Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All 2.0 test cases #74

Open
wants to merge 5 commits into
base: release-2.0-dev-testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest-coverage/coverage-report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><meta name="keywords" contect="jest, reporters"><meta name="author" contect="hazyzh"><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1,maximum-scale=1"><link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAHX0lEQVR4Xu2bfWwUVRDAZ/buSsG0Vxq1EAhtL/e2kKISAVEoKJVE4gfiR6wmJsoflpBANLZKqyRIgVg+/CLBNqKoMX5RKWhFsUbRBuJHRCoECLt7x0Jb5IBmr62tx+3dPrNH93Itd7e7xx0ccu+/dmfmzfz2vXmzu3MI1/jAazx+yADIrIBrnMDl2gK4atWqF8+ePXufx+OZFAgEbLG422w2/8SJE7fW1dXVAgBN9f1JOYD6+vqb2trafhUEYZSZYAghA3Pnzp1eXV19xIyeWdmUAli2bNmIY8eOeUVRzDbrmCo/duzYwPz580tqa2vdiegb0UkpgKVLl/7c2to6R3OEYRgoLS2F7OzoPHw+Hxw+fBgURQn7Xl5efqCxsfFWI8EkIpMQAIfDMc1iscxHxFmU0pGxJs7Pz79TkqTQZYfDAVu2bIHx48fH9bOvrw8WL14M+/fvD8nl5uZCT0/Pz1GU/ADQBQBuRPzF7/fvFUXRZxaCKQDFxcUlVqv1NUS8T28iu92uOh4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EpmYjNjK5ME0ykJquVwb6DXzA0cIuvILjRdLqfNCqjpWAdfSEPeopkGUWC7HlrIu5BvNf7mLS0AdAckmHHkIdMBR1PYXFgH99jDbQa6NtMCgAIKzDlaAafls7oOxxNQy+RdJVtNPS+kBQA1qE7/39As7b4kAJNHlkB57kxTNtIGgCmvkyicAZBOx2ASb6xhU5kVkFkBSXgaLCkpKVZ7bbR1N/zboJTOX4ZWrz/Z/PmOCZrviqI4BUFwRdtDMb8NFhQUXGe329XWs9BQFOVJQRA+1v5OZwA1z7/094+te8Zqvvp8vvyTJ09eaFgcNuJ2iBBCehAxV9WhlK7leX7F1QCgYsETfcfdovaqOcBxXMzmbL0WmR0AoHU3HuI47uYwAL80BUE5YDg1XyZBz+kz8MA8rTciNOlejuNmx5o+LgCn0/kkwzCRr3UXcxz3jmbM6+9OeTu7WW51K9bA1zt3hdUURXleEIQ3EgJQWlqaJcvyCQAYM7gNfMFg8Ba32x1qnJD83R8gwFNmnUyV/Jfbv4K1K1+NNN/n8/kKY+1/VVC3T9DpdC5hGOZtzSqlVH26WcTz/C61Rwhk5ScEuCVVQRm1+8mHn8KbGzYNEaeUPsvz/NB/mkmCmizLsp8BQEWkLqV0OwBsav299WDeqNznAOBpxCFNikZ9T0iuv78fXLwbXLwLvm3ZDe1//jXcThPHcY/pGdddAYMGbISQTxHxET2D6XCdUvoFz/NPAEBAzx+jAFQ7DMuyjQDwjJ7RK3mdUtrA8/xStXQx4ocZACF76o8lrFbrKkrp3Yg4wsgkqZahlJ5Xu9kDgcBKt9utNnYbHqYBRFi2OZ3OaYhYRCktZBgmod8FGfZ0mCCldEB950IpPS4Ighq0sUbkRJJgok5eDXqXsgKuhvh0fcwA0EX0Pxf4Dws8WYyVxouxAAAAAElFTkSuQmCC"></head><title>Report</title><body><div id="app"></div><script defer="defer" src="./jest-html-reporters-attach/coverage-report/index.js"></script></body></html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2,855 changes: 1,552 additions & 1,303 deletions package-lock.json

Large diffs are not rendered by default.

33 changes: 29 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test": "jest --coverage",
"test:controller": "jest --testPathPattern=scores.controller.spec.ts",
"test:service": "jest --testPathPattern=scores.service.spec.ts",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
Expand All @@ -31,7 +33,7 @@
"@nestjs/mapped-types": "*",
"@nestjs/mongoose": "^10.0.1",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-fastify": "^10.1.3",
"@nestjs/platform-fastify": "^10.3.9",
"@nestjs/swagger": "^7.1.12",
"@nestjs/typeorm": "^10.0.0",
"axios": "^1.6.2",
Expand Down Expand Up @@ -60,7 +62,8 @@
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.5.0",
"jest": "^29.7.0",
"jest-html-reporters": "^3.1.7",
"prettier": "^2.8.8",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
Expand All @@ -71,6 +74,17 @@
"typescript": "^5.1.3"
},
"jest": {
"reporters": [
"default",
[
"jest-html-reporters",
{
"publicPath": "./jest-coverage",
"filename": "coverage-report.html",
"expand": true
}
]
],
"moduleFileExtensions": [
"js",
"json",
Expand All @@ -85,6 +99,17 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"coveragePathIgnorePatterns": [
"/node_modules/",
"/dist/",
"/src/config/",
"/src/app-cluster.service.ts",
"/src/app.module.ts",
"/src/main.ts",
"/src/mysql/mysql.module.ts",
"/src/mysql/scores.controller.ts",
"/src/mysql/scores.service.ts"
]
}
}
2 changes: 1 addition & 1 deletion src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'ALL Learner AI Services';
return 'Hello World!';
}
}
22 changes: 22 additions & 0 deletions src/config/mongodb.config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe('Mongo Config', () => {
const originalEnv = process.env;

beforeEach(() => {
jest.resetModules();
process.env = { ...originalEnv };
});

afterEach(() => {
process.env = originalEnv;
});

it('should export the correct MongoDB URI from the environment variable', () => {
const testUri = 'mongodb://localhost:27017/lais_db';
process.env.MONGO_URL = testUri;

// Re-import the config to ensure it picks up the new environment variable
const config = require('./mongodb.config').default;

expect(config.uri).toBe(testUri);
});
});
4 changes: 3 additions & 1 deletion src/config/mongodb.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default {
const mongo_config = {
uri: process.env.MONGO_URL,
};

export default mongo_config;
37 changes: 37 additions & 0 deletions src/config/mysql.config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

import { Score } from '../mysql/entities/score.entity';
import mySql_config from './mysql.config';

describe('Database Configuration', () => {
it('should have the correct type', () => {
expect(mySql_config.type).toBe('mysql');
});

it('should have the correct host', () => {
expect(mySql_config.host).toBe('localhost');
});

it('should have the correct port', () => {
expect(mySql_config.port).toBe(3310);
});

it('should have the correct username', () => {
expect(mySql_config.username).toBe('root');
});

it('should have the correct password', () => {
expect(mySql_config.password).toBe('');
});

it('should have the correct database name', () => {
expect(mySql_config.database).toBe('lais_db');
});

it('should have synchronize set to true', () => {
expect(mySql_config.synchronize).toBe(true);
});

it('should have the correct entities', () => {
expect(mySql_config.entities).toEqual([Score]);
});
});
5 changes: 4 additions & 1 deletion src/config/mysql.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import exp from 'constants';
import { Score } from '../mysql/entities/score.entity';

export default {
const mySql_config = {
type: 'mysql',
host: 'localhost',
port: 3310,
Expand All @@ -10,3 +11,5 @@ export default {
synchronize: true,
entities: [Score],
};

export default mySql_config;
69 changes: 69 additions & 0 deletions src/mongodb/cache/cache.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CacheService } from './cache.service';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Cache } from 'cache-manager';

describe('CacheService', () => {
let service: CacheService;
let cacheManager: Cache;

beforeEach(async () => {
const cacheManagerMock = {
get: jest.fn(),
set: jest.fn(),
del: jest.fn(),
};

const module: TestingModule = await Test.createTestingModule({
providers: [
CacheService,
{
provide: CACHE_MANAGER,
useValue: cacheManagerMock,
},
],
}).compile();

service = module.get<CacheService>(CacheService);
cacheManager = module.get<Cache>(CACHE_MANAGER);
});

it('should be defined', () => {
expect(service).toBeDefined();
});

describe('get', () => {
it('should return the value for a given key', async () => {
const key = 'test-key';
const value = 'test-value';
jest.spyOn(cacheManager, 'get').mockResolvedValue(value);

const result = await service.get(key);

expect(cacheManager.get).toHaveBeenCalledWith(key);
expect(result).toBe(value);
});
});

describe('set', () => {
it('should set the value with a given key and ttl', async () => {
const key = 'test-key';
const value = 'test-value';
const ttl = 1000;

await service.set(key, value, ttl);

expect(cacheManager.set).toHaveBeenCalledWith(key, value, ttl);
});
});

describe('del', () => {
it('should delete the value for a given key', async () => {
const key = 'test-key';

await service.del(key);

expect(cacheManager.del).toHaveBeenCalledWith(key);
});
});
});
42 changes: 42 additions & 0 deletions src/mongodb/mongodb.module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Test, TestingModule } from '@nestjs/testing';
import { getConnectionToken } from '@nestjs/mongoose';
import { ConfigModule } from '@nestjs/config';
import { MongodbModule } from './mongodb.module';
import * as mongoose from 'mongoose';

describe('MongodbModule', () => {
let module: TestingModule;
let connection: mongoose.Connection;

beforeAll(async () => {
// Set mock MONGO_URL
process.env.MONGO_URL = 'mongodb://localhost:27017/testdb';

module = await Test.createTestingModule({
imports: [
MongodbModule,
ConfigModule.forRoot({
isGlobal: true,
}),
],
}).compile();

connection = module.get(getConnectionToken());
});

// Close the connection after tests
afterAll(async () => {
await connection.close();
});

it('should be defined', () => {
expect(module).toBeDefined();
});

it('should connect to MongoDB with the correct URI', () => {
expect(connection.readyState).toBe(1); // 1 indicates connected
expect(connection.host).toBe('localhost');
expect(connection.port).toBe(27017);
expect(connection.name).toBe('testdb');
});
});
7 changes: 2 additions & 5 deletions src/mongodb/mongodb.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import mongodbConfig from '../config/mongodb.config';
import { ScoreSchema } from './schemas/scores.schema';
import { hexcodeMappingSchema } from './schemas/hexcodeMapping.schema';
import { assessmentInputSchema } from './schemas/assessmentInput.schema';
import { denoiserOutputLogsSchema } from './schemas/denoiserOutputLogs.schema'
import { denoiserOutputLogsSchema } from './schemas/denoiserOutputLogs.schema';
import { ScoresController } from './scores.controller';
import { ScoresService } from './scores.service';
import { CacheService } from './cache/cache.service';
import { HttpModule } from '@nestjs/axios';
import { CacheModule } from '@nestjs/cache-manager';


@Module({
imports: [
HttpModule.register({
Expand All @@ -21,7 +20,6 @@ import { CacheModule } from '@nestjs/cache-manager';
ConfigModule.forRoot({
isGlobal: true,
}),

MongooseModule.forRootAsync({
useFactory: async () => ({
uri: process.env.MONGO_URL,
Expand All @@ -33,7 +31,6 @@ import { CacheModule } from '@nestjs/cache-manager';
},
}),
}),

MongooseModule.forFeature([
{ name: 'Score', schema: ScoreSchema },
{ name: 'hexcodeMapping', schema: hexcodeMappingSchema },
Expand All @@ -44,6 +41,6 @@ import { CacheModule } from '@nestjs/cache-manager';
],
controllers: [ScoresController],
providers: [ScoresService, CacheService],

exports: [ScoresService]
})
export class MongodbModule { }
Loading