From 27cad61f42fbe3748d1926f4d5f734614b6d3c50 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 3 Jun 2024 15:24:19 +0700 Subject: [PATCH] fix: correct tests setup --- cortex-js/package.json | 5 +- .../controllers/assistants.controller.spec.ts | 5 ++ .../controllers/assistants.controller.ts | 20 +++++-- .../controllers/chat.controller.spec.ts | 5 ++ .../controllers/messages.controller.spec.ts | 3 ++ .../controllers/messages.controller.ts | 52 +++++++++++++------ .../controllers/models.controller.spec.ts | 9 +++- .../controllers/threads.controller.spec.ts | 2 + .../database/sqlite-database.providers.ts | 2 +- .../dtos/chat/create-chat-completion.dto.ts | 33 +++++++++--- .../providers/cortex/cortex.provider.ts | 2 +- cortex-js/src/main.ts | 29 ++++++++--- .../assistants/assistants.usecases.spec.ts | 3 ++ .../src/usecases/chat/chat.usecases.spec.ts | 4 ++ .../usecases/cortex/cortex.usecases.spec.ts | 5 ++ .../src/usecases/cortex/cortex.usecases.ts | 2 +- .../messages/messages.usecases.spec.ts | 3 ++ .../usecases/models/models.usecases.spec.ts | 13 +++++ .../usecases/threads/threads.usecases.spec.ts | 2 + cortex-js/test/jest-e2e.json | 3 ++ .../{app.e2e-spec.ts => models.e2e-spec.ts} | 10 ++-- 21 files changed, 168 insertions(+), 44 deletions(-) rename cortex-js/test/{app.e2e-spec.ts => models.e2e-spec.ts} (71%) diff --git a/cortex-js/package.json b/cortex-js/package.json index 53561b4fa..e795f942a 100644 --- a/cortex-js/package.json +++ b/cortex-js/package.json @@ -107,6 +107,9 @@ "**/*.(t|j)s" ], "coverageDirectory": "../coverage", - "testEnvironment": "node" + "testEnvironment": "node", + "moduleNameMapper": { + "@/(.*)$": "/$1" + } } } diff --git a/cortex-js/src/infrastructure/controllers/assistants.controller.spec.ts b/cortex-js/src/infrastructure/controllers/assistants.controller.spec.ts index 872c4fe4c..7f9b5d351 100644 --- a/cortex-js/src/infrastructure/controllers/assistants.controller.spec.ts +++ b/cortex-js/src/infrastructure/controllers/assistants.controller.spec.ts @@ -1,12 +1,17 @@ import { Test, TestingModule } from '@nestjs/testing'; import { AssistantsController } from './assistants.controller'; +import { AssistantsUsecases } from '@/usecases/assistants/assistants.usecases'; +import { DatabaseModule } from '../database/database.module'; describe('AssistantsController', () => { let controller: AssistantsController; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [DatabaseModule], controllers: [AssistantsController], + providers: [AssistantsUsecases], + exports: [AssistantsUsecases], }).compile(); controller = module.get(AssistantsController); diff --git a/cortex-js/src/infrastructure/controllers/assistants.controller.ts b/cortex-js/src/infrastructure/controllers/assistants.controller.ts index dcb66a613..5b8d22bef 100644 --- a/cortex-js/src/infrastructure/controllers/assistants.controller.ts +++ b/cortex-js/src/infrastructure/controllers/assistants.controller.ts @@ -16,7 +16,7 @@ import { ApiOperation, ApiParam, ApiTags, - ApiResponse + ApiResponse, } from '@nestjs/swagger'; import { AssistantEntity } from '../entities/assistant.entity'; import { TransformInterceptor } from '../interceptors/transform.interceptor'; @@ -41,7 +41,8 @@ export class AssistantsController { @ApiOperation({ summary: 'List assistants', - description: 'Retrieves all the available assistants along with their settings.', + description: + 'Retrieves all the available assistants along with their settings.', }) @ApiOkResponse({ description: 'Ok', @@ -54,13 +55,18 @@ export class AssistantsController { @ApiOperation({ summary: 'Get assistant', - description: "Retrieves a specific assistant defined by an assistant's `id`.", + description: + "Retrieves a specific assistant defined by an assistant's `id`.", }) @ApiOkResponse({ description: 'Ok', type: AssistantEntity, }) - @ApiParam({ name: 'id', required: true, description: "The unique identifier of the assistant." }) + @ApiParam({ + name: 'id', + required: true, + description: 'The unique identifier of the assistant.', + }) @Get(':id') findOne(@Param('id') id: string) { return this.assistantsService.findOne(id); @@ -75,7 +81,11 @@ export class AssistantsController { description: 'The assistant has been successfully deleted.', type: DeleteAssistantResponseDto, }) - @ApiParam({ name: 'id', required: true, description: "The unique identifier of the assistant." }) + @ApiParam({ + name: 'id', + required: true, + description: 'The unique identifier of the assistant.', + }) @Delete(':id') remove(@Param('id') id: string) { return this.assistantsService.remove(id); diff --git a/cortex-js/src/infrastructure/controllers/chat.controller.spec.ts b/cortex-js/src/infrastructure/controllers/chat.controller.spec.ts index 571463df3..07c3d088e 100644 --- a/cortex-js/src/infrastructure/controllers/chat.controller.spec.ts +++ b/cortex-js/src/infrastructure/controllers/chat.controller.spec.ts @@ -1,12 +1,17 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ChatController } from './chat.controller'; +import { ChatUsecases } from '@/usecases/chat/chat.usecases'; +import { DatabaseModule } from '../database/database.module'; +import { ExtensionModule } from '../repositories/extensions/extension.module'; describe('ChatController', () => { let controller: ChatController; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [DatabaseModule, ExtensionModule], controllers: [ChatController], + providers: [ChatUsecases], }).compile(); controller = module.get(ChatController); diff --git a/cortex-js/src/infrastructure/controllers/messages.controller.spec.ts b/cortex-js/src/infrastructure/controllers/messages.controller.spec.ts index a81d18818..351155b6e 100644 --- a/cortex-js/src/infrastructure/controllers/messages.controller.spec.ts +++ b/cortex-js/src/infrastructure/controllers/messages.controller.spec.ts @@ -1,14 +1,17 @@ import { Test, TestingModule } from '@nestjs/testing'; import { MessagesController } from './messages.controller'; import { MessagesUsecases } from '@/usecases/messages/messages.usecases'; +import { DatabaseModule } from '../database/database.module'; describe('MessagesController', () => { let controller: MessagesController; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [DatabaseModule], controllers: [MessagesController], providers: [MessagesUsecases], + exports: [MessagesUsecases], }).compile(); controller = module.get(MessagesController); diff --git a/cortex-js/src/infrastructure/controllers/messages.controller.ts b/cortex-js/src/infrastructure/controllers/messages.controller.ts index e0084d83e..d668ffec6 100644 --- a/cortex-js/src/infrastructure/controllers/messages.controller.ts +++ b/cortex-js/src/infrastructure/controllers/messages.controller.ts @@ -15,14 +15,7 @@ import { UpdateMessageDto } from '@/infrastructure/dtos/messages/update-message. import { ListMessagesResponseDto } from '@/infrastructure/dtos/messages/list-message.dto'; import { GetMessageResponseDto } from '@/infrastructure/dtos/messages/get-message.dto'; import { DeleteMessageResponseDto } from '@/infrastructure/dtos/messages/delete-message.dto'; -import { - ApiCreatedResponse, - ApiOkResponse, - ApiOperation, - ApiParam, - ApiTags, - ApiResponse -} from '@nestjs/swagger'; +import { ApiOperation, ApiParam, ApiTags, ApiResponse } from '@nestjs/swagger'; import { TransformInterceptor } from '../interceptors/transform.interceptor'; @ApiTags('Messages') @@ -37,7 +30,10 @@ export class MessagesController { description: 'The message has been successfully created.', type: CreateMessageDto, }) - @ApiOperation({ summary: 'Create message', description: "Creates a message in a thread." }) + @ApiOperation({ + summary: 'Create message', + description: 'Creates a message in a thread.', + }) @Post() create(@Body() createMessageDto: CreateMessageDto) { return this.messagesUsecases.create(createMessageDto); @@ -49,7 +45,10 @@ export class MessagesController { description: 'Ok', type: ListMessagesResponseDto, }) - @ApiOperation({ summary: 'List messages', description: "Retrieves all the messages in a thread." }) + @ApiOperation({ + summary: 'List messages', + description: 'Retrieves all the messages in a thread.', + }) @Get() findAll() { return this.messagesUsecases.findAll(); @@ -61,8 +60,15 @@ export class MessagesController { description: 'Ok', type: GetMessageResponseDto, }) - @ApiOperation({ summary: 'Retrieve message', description: "Retrieves a specific message defined by a message's `id`." }) - @ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." }) + @ApiOperation({ + summary: 'Retrieve message', + description: "Retrieves a specific message defined by a message's `id`.", + }) + @ApiParam({ + name: 'id', + required: true, + description: 'The unique identifier of the message.', + }) @Get(':id') findOne(@Param('id') id: string) { return this.messagesUsecases.findOne(id); @@ -74,8 +80,15 @@ export class MessagesController { description: 'The message has been successfully updated.', type: UpdateMessageDto, }) - @ApiOperation({ summary: 'Update message', description: "Updates a specific message defined by a message's `id`." }) - @ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." }) + @ApiOperation({ + summary: 'Update message', + description: "Updates a specific message defined by a message's `id`.", + }) + @ApiParam({ + name: 'id', + required: true, + description: 'The unique identifier of the message.', + }) @Patch(':id') update(@Param('id') id: string, @Body() updateMessageDto: UpdateMessageDto) { return this.messagesUsecases.update(id, updateMessageDto); @@ -87,8 +100,15 @@ export class MessagesController { description: 'Successfully deleted the message.', type: DeleteMessageResponseDto, }) - @ApiOperation({ summary: 'Delete message', description: "Deletes a specific message defined by a message's `id`." }) - @ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." }) + @ApiOperation({ + summary: 'Delete message', + description: "Deletes a specific message defined by a message's `id`.", + }) + @ApiParam({ + name: 'id', + required: true, + description: 'The unique identifier of the message.', + }) @Delete(':id') remove(@Param('id') id: string) { return this.messagesUsecases.remove(id); diff --git a/cortex-js/src/infrastructure/controllers/models.controller.spec.ts b/cortex-js/src/infrastructure/controllers/models.controller.spec.ts index cd6fb8db5..6b4cc07cf 100644 --- a/cortex-js/src/infrastructure/controllers/models.controller.spec.ts +++ b/cortex-js/src/infrastructure/controllers/models.controller.spec.ts @@ -1,14 +1,21 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ModelsController } from './models.controller'; import { ModelsUsecases } from '@/usecases/models/models.usecases'; +import { DatabaseModule } from '../database/database.module'; +import { ExtensionModule } from '../repositories/extensions/extension.module'; +import { FileManagerModule } from '@/file-manager/file-manager.module'; +import { HttpModule } from '@nestjs/axios'; +import { CortexUsecases } from '@/usecases/cortex/cortex.usecases'; describe('ModelsController', () => { let controller: ModelsController; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [DatabaseModule, ExtensionModule, FileManagerModule, HttpModule], controllers: [ModelsController], - providers: [ModelsUsecases], + providers: [ModelsUsecases, CortexUsecases], + exports: [ModelsUsecases], }).compile(); controller = module.get(ModelsController); diff --git a/cortex-js/src/infrastructure/controllers/threads.controller.spec.ts b/cortex-js/src/infrastructure/controllers/threads.controller.spec.ts index e2dbd7968..1cf065219 100644 --- a/cortex-js/src/infrastructure/controllers/threads.controller.spec.ts +++ b/cortex-js/src/infrastructure/controllers/threads.controller.spec.ts @@ -1,12 +1,14 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ThreadsController } from './threads.controller'; import { ThreadsUsecases } from '@/usecases/threads/threads.usecases'; +import { DatabaseModule } from '../database/database.module'; describe('ThreadsController', () => { let controller: ThreadsController; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [DatabaseModule], controllers: [ThreadsController], providers: [ThreadsUsecases], }).compile(); diff --git a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts index 778f47675..bcedf7b0c 100644 --- a/cortex-js/src/infrastructure/database/sqlite-database.providers.ts +++ b/cortex-js/src/infrastructure/database/sqlite-database.providers.ts @@ -1,5 +1,5 @@ import { FileManagerService } from '@/file-manager/file-manager.service'; -import { databaseFile } from 'constant'; +import { databaseFile } from '@/../constant'; import { join } from 'path'; import { DataSource } from 'typeorm'; diff --git a/cortex-js/src/infrastructure/dtos/chat/create-chat-completion.dto.ts b/cortex-js/src/infrastructure/dtos/chat/create-chat-completion.dto.ts index 37ac4b914..5e48edc92 100644 --- a/cortex-js/src/infrastructure/dtos/chat/create-chat-completion.dto.ts +++ b/cortex-js/src/infrastructure/dtos/chat/create-chat-completion.dto.ts @@ -25,31 +25,50 @@ export class CreateChatCompletionDto { @IsString() model: string; - @ApiProperty({description: "Determines the format for output generation. If set to `true`, the output is generated continuously, allowing for real-time streaming of responses. If set to `false`, the output is delivered in a single JSON file."}) + @ApiProperty({ + description: + 'Determines the format for output generation. If set to `true`, the output is generated continuously, allowing for real-time streaming of responses. If set to `false`, the output is delivered in a single JSON file.', + }) @IsBoolean() stream: boolean; - @ApiProperty({description: "Sets the upper limit on the number of tokens the model can generate in a single output."}) + @ApiProperty({ + description: + 'Sets the upper limit on the number of tokens the model can generate in a single output.', + }) @IsNumber() max_tokens: number; - @ApiProperty({description: "Defines specific tokens or phrases that signal the model to stop producing further output."}) + @ApiProperty({ + description: + 'Defines specific tokens or phrases that signal the model to stop producing further output.', + }) @IsArray() stop: string[]; - @ApiProperty({description: "Modifies the likelihood of the model repeating the same words or phrases within a single output."}) + @ApiProperty({ + description: + 'Modifies the likelihood of the model repeating the same words or phrases within a single output.', + }) @IsNumber() frequency_penalty: number; - @ApiProperty({description: "Reduces the likelihood of repeating tokens, promoting novelty in the output."}) + @ApiProperty({ + description: + 'Reduces the likelihood of repeating tokens, promoting novelty in the output.', + }) @IsNumber() presence_penalty: number; - @ApiProperty({description: "Influences the randomness of the model's output."}) + @ApiProperty({ + description: "Influences the randomness of the model's output.", + }) @IsNumber() temperature: number; - @ApiProperty({description: "Sets probability threshold for more relevant outputs."}) + @ApiProperty({ + description: 'Sets probability threshold for more relevant outputs.', + }) @IsNumber() top_p: number; } diff --git a/cortex-js/src/infrastructure/providers/cortex/cortex.provider.ts b/cortex-js/src/infrastructure/providers/cortex/cortex.provider.ts index 2c367ee47..d13eca9fd 100644 --- a/cortex-js/src/infrastructure/providers/cortex/cortex.provider.ts +++ b/cortex-js/src/infrastructure/providers/cortex/cortex.provider.ts @@ -4,7 +4,7 @@ import { PromptTemplate } from '@/domain/models/prompt-template.interface'; import { join } from 'path'; import { Model, ModelSettingParams } from '@/domain/models/model.interface'; import { HttpService } from '@nestjs/axios'; -import { defaultCortexCppHost, defaultCortexCppPort } from 'constant'; +import { defaultCortexCppHost, defaultCortexCppPort } from '@/../constant'; import { readdirSync } from 'node:fs'; import { normalizeModelId } from '@/infrastructure/commanders/utils/normalize-model-id'; import { firstValueFrom } from 'rxjs'; diff --git a/cortex-js/src/main.ts b/cortex-js/src/main.ts index 695017d3e..3bcab01b7 100644 --- a/cortex-js/src/main.ts +++ b/cortex-js/src/main.ts @@ -25,13 +25,30 @@ async function bootstrap() { const config = new DocumentBuilder() .setTitle('Cortex API') - .setDescription('Cortex API provides a command-line interface (CLI) for seamless interaction with large language models (LLMs). Fully compatible with the [OpenAI API](https://platform.openai.com/docs/api-reference), it enables straightforward command execution and management of LLM interactions.') + .setDescription( + 'Cortex API provides a command-line interface (CLI) for seamless interaction with large language models (LLMs). Fully compatible with the [OpenAI API](https://platform.openai.com/docs/api-reference), it enables straightforward command execution and management of LLM interactions.', + ) .setVersion('1.0') - .addTag('Inference', 'This endpoint initiates interaction with a Language Learning Model (LLM).') - .addTag('Assistants', 'These endpoints manage the lifecycle of an Assistant within a conversation thread.') - .addTag('Models', 'These endpoints provide a list and descriptions of all available models within the Cortex framework.') - .addTag('Messages', "These endpoints manage the retrieval and storage of conversation content, including responses from LLMs and other metadata related to chat interactions.") - .addTag('Threads', 'These endpoints handle the creation, retrieval, updating, and deletion of conversation threads.') + .addTag( + 'Inference', + 'This endpoint initiates interaction with a Language Learning Model (LLM).', + ) + .addTag( + 'Assistants', + 'These endpoints manage the lifecycle of an Assistant within a conversation thread.', + ) + .addTag( + 'Models', + 'These endpoints provide a list and descriptions of all available models within the Cortex framework.', + ) + .addTag( + 'Messages', + 'These endpoints manage the retrieval and storage of conversation content, including responses from LLMs and other metadata related to chat interactions.', + ) + .addTag( + 'Threads', + 'These endpoints handle the creation, retrieval, updating, and deletion of conversation threads.', + ) .addServer('http://localhost:1337') .addServer('http://localhost:1337/v1') .build(); diff --git a/cortex-js/src/usecases/assistants/assistants.usecases.spec.ts b/cortex-js/src/usecases/assistants/assistants.usecases.spec.ts index 9cf3f0ea9..8af94e723 100644 --- a/cortex-js/src/usecases/assistants/assistants.usecases.spec.ts +++ b/cortex-js/src/usecases/assistants/assistants.usecases.spec.ts @@ -1,11 +1,14 @@ import { Test, TestingModule } from '@nestjs/testing'; import { AssistantsUsecases } from './assistants.usecases'; +import { DatabaseModule } from '@/infrastructure/database/database.module'; describe('AssistantsService', () => { let service: AssistantsUsecases; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [DatabaseModule], + exports: [AssistantsUsecases], providers: [AssistantsUsecases], }).compile(); diff --git a/cortex-js/src/usecases/chat/chat.usecases.spec.ts b/cortex-js/src/usecases/chat/chat.usecases.spec.ts index 6ee013ab0..dbf5e8efc 100644 --- a/cortex-js/src/usecases/chat/chat.usecases.spec.ts +++ b/cortex-js/src/usecases/chat/chat.usecases.spec.ts @@ -1,12 +1,16 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ChatUsecases } from './chat.usecases'; +import { DatabaseModule } from '@/infrastructure/database/database.module'; +import { ExtensionModule } from '@/infrastructure/repositories/extensions/extension.module'; describe('ChatService', () => { let service: ChatUsecases; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [DatabaseModule, ExtensionModule], providers: [ChatUsecases], + exports: [ChatUsecases], }).compile(); service = module.get(ChatUsecases); diff --git a/cortex-js/src/usecases/cortex/cortex.usecases.spec.ts b/cortex-js/src/usecases/cortex/cortex.usecases.spec.ts index d369e8cfa..53642376f 100644 --- a/cortex-js/src/usecases/cortex/cortex.usecases.spec.ts +++ b/cortex-js/src/usecases/cortex/cortex.usecases.spec.ts @@ -1,12 +1,17 @@ import { Test, TestingModule } from '@nestjs/testing'; import { CortexUsecases } from './cortex.usecases'; +import { DatabaseModule } from '@/infrastructure/database/database.module'; +import { HttpModule } from '@nestjs/axios'; +import { FileManagerModule } from '@/file-manager/file-manager.module'; describe('CortexUsecases', () => { let cortexUsecases: CortexUsecases; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [DatabaseModule, HttpModule, FileManagerModule], providers: [CortexUsecases], + exports: [], }).compile(); cortexUsecases = module.get(CortexUsecases); diff --git a/cortex-js/src/usecases/cortex/cortex.usecases.ts b/cortex-js/src/usecases/cortex/cortex.usecases.ts index 5f14645c3..7d19a2f45 100644 --- a/cortex-js/src/usecases/cortex/cortex.usecases.ts +++ b/cortex-js/src/usecases/cortex/cortex.usecases.ts @@ -3,7 +3,7 @@ import { ChildProcess, spawn } from 'child_process'; import { join } from 'path'; import { CortexOperationSuccessfullyDto } from '@/infrastructure/dtos/cortex/cortex-operation-successfully.dto'; import { HttpService } from '@nestjs/axios'; -import { defaultCortexCppHost, defaultCortexCppPort } from 'constant'; +import { defaultCortexCppHost, defaultCortexCppPort } from '@/../constant'; import { existsSync } from 'node:fs'; import { firstValueFrom } from 'rxjs'; import { FileManagerService } from '@/file-manager/file-manager.service'; diff --git a/cortex-js/src/usecases/messages/messages.usecases.spec.ts b/cortex-js/src/usecases/messages/messages.usecases.spec.ts index d32f737b5..ad671d3f3 100644 --- a/cortex-js/src/usecases/messages/messages.usecases.spec.ts +++ b/cortex-js/src/usecases/messages/messages.usecases.spec.ts @@ -1,12 +1,15 @@ import { Test, TestingModule } from '@nestjs/testing'; import { MessagesUsecases } from './messages.usecases'; +import { DatabaseModule } from '@/infrastructure/database/database.module'; describe('MessagesService', () => { let service: MessagesUsecases; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [DatabaseModule], providers: [MessagesUsecases], + exports: [MessagesUsecases], }).compile(); service = module.get(MessagesUsecases); diff --git a/cortex-js/src/usecases/models/models.usecases.spec.ts b/cortex-js/src/usecases/models/models.usecases.spec.ts index dd00a5c79..39ed92150 100644 --- a/cortex-js/src/usecases/models/models.usecases.spec.ts +++ b/cortex-js/src/usecases/models/models.usecases.spec.ts @@ -1,12 +1,25 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ModelsUsecases } from './models.usecases'; +import { DatabaseModule } from '@/infrastructure/database/database.module'; +import { ModelsModule } from './models.module'; +import { ExtensionModule } from '@/infrastructure/repositories/extensions/extension.module'; +import { FileManagerModule } from '@/file-manager/file-manager.module'; +import { HttpModule } from '@nestjs/axios'; describe('ModelsService', () => { let service: ModelsUsecases; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [ + DatabaseModule, + ModelsModule, + ExtensionModule, + FileManagerModule, + HttpModule, + ], providers: [ModelsUsecases], + exports: [ModelsUsecases], }).compile(); service = module.get(ModelsUsecases); diff --git a/cortex-js/src/usecases/threads/threads.usecases.spec.ts b/cortex-js/src/usecases/threads/threads.usecases.spec.ts index 881b54afa..39a9d11dd 100644 --- a/cortex-js/src/usecases/threads/threads.usecases.spec.ts +++ b/cortex-js/src/usecases/threads/threads.usecases.spec.ts @@ -1,11 +1,13 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ThreadsUsecases } from './threads.usecases'; +import { DatabaseModule } from '@/infrastructure/database/database.module'; describe('ThreadsService', () => { let service: ThreadsUsecases; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [DatabaseModule], providers: [ThreadsUsecases], }).compile(); diff --git a/cortex-js/test/jest-e2e.json b/cortex-js/test/jest-e2e.json index e9d912f3e..7b028de70 100644 --- a/cortex-js/test/jest-e2e.json +++ b/cortex-js/test/jest-e2e.json @@ -5,5 +5,8 @@ "testRegex": ".e2e-spec.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" + }, + "moduleNameMapper": { + "@/(.*)$": "/../src/$1" } } diff --git a/cortex-js/test/app.e2e-spec.ts b/cortex-js/test/models.e2e-spec.ts similarity index 71% rename from cortex-js/test/app.e2e-spec.ts rename to cortex-js/test/models.e2e-spec.ts index 9832ffcae..f6bf5a2e5 100644 --- a/cortex-js/test/app.e2e-spec.ts +++ b/cortex-js/test/models.e2e-spec.ts @@ -1,9 +1,9 @@ import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; -import * as request from 'supertest'; -import { AppModule } from './../@/app.module'; +import request from 'supertest'; +import { AppModule } from '@/app.module'; -describe('AppController (e2e)', () => { +describe('ModelsController (e2e)', () => { let app: INestApplication; beforeEach(async () => { @@ -17,8 +17,8 @@ describe('AppController (e2e)', () => { it('/ (GET)', () => { return request(app.getHttpServer()) - .get('/') + .get('/models') .expect(200) - .expect('Hello World!'); + .expect((e) => Array.isArray(e)); }); });