Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit b879f66

Browse files
authored
fix: correct tests setup (#654)
1 parent 51a58cb commit b879f66

21 files changed

+168
-44
lines changed

cortex-js/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@
107107
"**/*.(t|j)s"
108108
],
109109
"coverageDirectory": "../coverage",
110-
"testEnvironment": "node"
110+
"testEnvironment": "node",
111+
"moduleNameMapper": {
112+
"@/(.*)$": "<rootDir>/$1"
113+
}
111114
}
112115
}

cortex-js/src/infrastructure/controllers/assistants.controller.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { AssistantsController } from './assistants.controller';
3+
import { AssistantsUsecases } from '@/usecases/assistants/assistants.usecases';
4+
import { DatabaseModule } from '../database/database.module';
35

46
describe('AssistantsController', () => {
57
let controller: AssistantsController;
68

79
beforeEach(async () => {
810
const module: TestingModule = await Test.createTestingModule({
11+
imports: [DatabaseModule],
912
controllers: [AssistantsController],
13+
providers: [AssistantsUsecases],
14+
exports: [AssistantsUsecases],
1015
}).compile();
1116

1217
controller = module.get<AssistantsController>(AssistantsController);

cortex-js/src/infrastructure/controllers/assistants.controller.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
ApiOperation,
1717
ApiParam,
1818
ApiTags,
19-
ApiResponse
19+
ApiResponse,
2020
} from '@nestjs/swagger';
2121
import { AssistantEntity } from '../entities/assistant.entity';
2222
import { TransformInterceptor } from '../interceptors/transform.interceptor';
@@ -41,7 +41,8 @@ export class AssistantsController {
4141

4242
@ApiOperation({
4343
summary: 'List assistants',
44-
description: 'Retrieves all the available assistants along with their settings.',
44+
description:
45+
'Retrieves all the available assistants along with their settings.',
4546
})
4647
@ApiOkResponse({
4748
description: 'Ok',
@@ -54,13 +55,18 @@ export class AssistantsController {
5455

5556
@ApiOperation({
5657
summary: 'Get assistant',
57-
description: "Retrieves a specific assistant defined by an assistant's `id`.",
58+
description:
59+
"Retrieves a specific assistant defined by an assistant's `id`.",
5860
})
5961
@ApiOkResponse({
6062
description: 'Ok',
6163
type: AssistantEntity,
6264
})
63-
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the assistant." })
65+
@ApiParam({
66+
name: 'id',
67+
required: true,
68+
description: 'The unique identifier of the assistant.',
69+
})
6470
@Get(':id')
6571
findOne(@Param('id') id: string) {
6672
return this.assistantsService.findOne(id);
@@ -75,7 +81,11 @@ export class AssistantsController {
7581
description: 'The assistant has been successfully deleted.',
7682
type: DeleteAssistantResponseDto,
7783
})
78-
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the assistant." })
84+
@ApiParam({
85+
name: 'id',
86+
required: true,
87+
description: 'The unique identifier of the assistant.',
88+
})
7989
@Delete(':id')
8090
remove(@Param('id') id: string) {
8191
return this.assistantsService.remove(id);

cortex-js/src/infrastructure/controllers/chat.controller.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { ChatController } from './chat.controller';
3+
import { ChatUsecases } from '@/usecases/chat/chat.usecases';
4+
import { DatabaseModule } from '../database/database.module';
5+
import { ExtensionModule } from '../repositories/extensions/extension.module';
36

47
describe('ChatController', () => {
58
let controller: ChatController;
69

710
beforeEach(async () => {
811
const module: TestingModule = await Test.createTestingModule({
12+
imports: [DatabaseModule, ExtensionModule],
913
controllers: [ChatController],
14+
providers: [ChatUsecases],
1015
}).compile();
1116

1217
controller = module.get<ChatController>(ChatController);

cortex-js/src/infrastructure/controllers/messages.controller.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { MessagesController } from './messages.controller';
33
import { MessagesUsecases } from '@/usecases/messages/messages.usecases';
4+
import { DatabaseModule } from '../database/database.module';
45

56
describe('MessagesController', () => {
67
let controller: MessagesController;
78

89
beforeEach(async () => {
910
const module: TestingModule = await Test.createTestingModule({
11+
imports: [DatabaseModule],
1012
controllers: [MessagesController],
1113
providers: [MessagesUsecases],
14+
exports: [MessagesUsecases],
1215
}).compile();
1316

1417
controller = module.get<MessagesController>(MessagesController);

cortex-js/src/infrastructure/controllers/messages.controller.ts

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ import { UpdateMessageDto } from '@/infrastructure/dtos/messages/update-message.
1515
import { ListMessagesResponseDto } from '@/infrastructure/dtos/messages/list-message.dto';
1616
import { GetMessageResponseDto } from '@/infrastructure/dtos/messages/get-message.dto';
1717
import { DeleteMessageResponseDto } from '@/infrastructure/dtos/messages/delete-message.dto';
18-
import {
19-
ApiCreatedResponse,
20-
ApiOkResponse,
21-
ApiOperation,
22-
ApiParam,
23-
ApiTags,
24-
ApiResponse
25-
} from '@nestjs/swagger';
18+
import { ApiOperation, ApiParam, ApiTags, ApiResponse } from '@nestjs/swagger';
2619
import { TransformInterceptor } from '../interceptors/transform.interceptor';
2720

2821
@ApiTags('Messages')
@@ -37,7 +30,10 @@ export class MessagesController {
3730
description: 'The message has been successfully created.',
3831
type: CreateMessageDto,
3932
})
40-
@ApiOperation({ summary: 'Create message', description: "Creates a message in a thread." })
33+
@ApiOperation({
34+
summary: 'Create message',
35+
description: 'Creates a message in a thread.',
36+
})
4137
@Post()
4238
create(@Body() createMessageDto: CreateMessageDto) {
4339
return this.messagesUsecases.create(createMessageDto);
@@ -49,7 +45,10 @@ export class MessagesController {
4945
description: 'Ok',
5046
type: ListMessagesResponseDto,
5147
})
52-
@ApiOperation({ summary: 'List messages', description: "Retrieves all the messages in a thread." })
48+
@ApiOperation({
49+
summary: 'List messages',
50+
description: 'Retrieves all the messages in a thread.',
51+
})
5352
@Get()
5453
findAll() {
5554
return this.messagesUsecases.findAll();
@@ -61,8 +60,15 @@ export class MessagesController {
6160
description: 'Ok',
6261
type: GetMessageResponseDto,
6362
})
64-
@ApiOperation({ summary: 'Retrieve message', description: "Retrieves a specific message defined by a message's `id`." })
65-
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." })
63+
@ApiOperation({
64+
summary: 'Retrieve message',
65+
description: "Retrieves a specific message defined by a message's `id`.",
66+
})
67+
@ApiParam({
68+
name: 'id',
69+
required: true,
70+
description: 'The unique identifier of the message.',
71+
})
6672
@Get(':id')
6773
findOne(@Param('id') id: string) {
6874
return this.messagesUsecases.findOne(id);
@@ -74,8 +80,15 @@ export class MessagesController {
7480
description: 'The message has been successfully updated.',
7581
type: UpdateMessageDto,
7682
})
77-
@ApiOperation({ summary: 'Update message', description: "Updates a specific message defined by a message's `id`." })
78-
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." })
83+
@ApiOperation({
84+
summary: 'Update message',
85+
description: "Updates a specific message defined by a message's `id`.",
86+
})
87+
@ApiParam({
88+
name: 'id',
89+
required: true,
90+
description: 'The unique identifier of the message.',
91+
})
7992
@Patch(':id')
8093
update(@Param('id') id: string, @Body() updateMessageDto: UpdateMessageDto) {
8194
return this.messagesUsecases.update(id, updateMessageDto);
@@ -87,8 +100,15 @@ export class MessagesController {
87100
description: 'Successfully deleted the message.',
88101
type: DeleteMessageResponseDto,
89102
})
90-
@ApiOperation({ summary: 'Delete message', description: "Deletes a specific message defined by a message's `id`." })
91-
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." })
103+
@ApiOperation({
104+
summary: 'Delete message',
105+
description: "Deletes a specific message defined by a message's `id`.",
106+
})
107+
@ApiParam({
108+
name: 'id',
109+
required: true,
110+
description: 'The unique identifier of the message.',
111+
})
92112
@Delete(':id')
93113
remove(@Param('id') id: string) {
94114
return this.messagesUsecases.remove(id);

cortex-js/src/infrastructure/controllers/models.controller.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { ModelsController } from './models.controller';
33
import { ModelsUsecases } from '@/usecases/models/models.usecases';
4+
import { DatabaseModule } from '../database/database.module';
5+
import { ExtensionModule } from '../repositories/extensions/extension.module';
6+
import { FileManagerModule } from '@/file-manager/file-manager.module';
7+
import { HttpModule } from '@nestjs/axios';
8+
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
49

510
describe('ModelsController', () => {
611
let controller: ModelsController;
712

813
beforeEach(async () => {
914
const module: TestingModule = await Test.createTestingModule({
15+
imports: [DatabaseModule, ExtensionModule, FileManagerModule, HttpModule],
1016
controllers: [ModelsController],
11-
providers: [ModelsUsecases],
17+
providers: [ModelsUsecases, CortexUsecases],
18+
exports: [ModelsUsecases],
1219
}).compile();
1320

1421
controller = module.get<ModelsController>(ModelsController);

cortex-js/src/infrastructure/controllers/threads.controller.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { ThreadsController } from './threads.controller';
33
import { ThreadsUsecases } from '@/usecases/threads/threads.usecases';
4+
import { DatabaseModule } from '../database/database.module';
45

56
describe('ThreadsController', () => {
67
let controller: ThreadsController;
78

89
beforeEach(async () => {
910
const module: TestingModule = await Test.createTestingModule({
11+
imports: [DatabaseModule],
1012
controllers: [ThreadsController],
1113
providers: [ThreadsUsecases],
1214
}).compile();

cortex-js/src/infrastructure/database/sqlite-database.providers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FileManagerService } from '@/file-manager/file-manager.service';
2-
import { databaseFile } from 'constant';
2+
import { databaseFile } from '@/../constant';
33
import { join } from 'path';
44
import { DataSource } from 'typeorm';
55

cortex-js/src/infrastructure/dtos/chat/create-chat-completion.dto.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,50 @@ export class CreateChatCompletionDto {
2525
@IsString()
2626
model: string;
2727

28-
@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."})
28+
@ApiProperty({
29+
description:
30+
'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.',
31+
})
2932
@IsBoolean()
3033
stream: boolean;
3134

32-
@ApiProperty({description: "Sets the upper limit on the number of tokens the model can generate in a single output."})
35+
@ApiProperty({
36+
description:
37+
'Sets the upper limit on the number of tokens the model can generate in a single output.',
38+
})
3339
@IsNumber()
3440
max_tokens: number;
3541

36-
@ApiProperty({description: "Defines specific tokens or phrases that signal the model to stop producing further output."})
42+
@ApiProperty({
43+
description:
44+
'Defines specific tokens or phrases that signal the model to stop producing further output.',
45+
})
3746
@IsArray()
3847
stop: string[];
3948

40-
@ApiProperty({description: "Modifies the likelihood of the model repeating the same words or phrases within a single output."})
49+
@ApiProperty({
50+
description:
51+
'Modifies the likelihood of the model repeating the same words or phrases within a single output.',
52+
})
4153
@IsNumber()
4254
frequency_penalty: number;
4355

44-
@ApiProperty({description: "Reduces the likelihood of repeating tokens, promoting novelty in the output."})
56+
@ApiProperty({
57+
description:
58+
'Reduces the likelihood of repeating tokens, promoting novelty in the output.',
59+
})
4560
@IsNumber()
4661
presence_penalty: number;
4762

48-
@ApiProperty({description: "Influences the randomness of the model's output."})
63+
@ApiProperty({
64+
description: "Influences the randomness of the model's output.",
65+
})
4966
@IsNumber()
5067
temperature: number;
5168

52-
@ApiProperty({description: "Sets probability threshold for more relevant outputs."})
69+
@ApiProperty({
70+
description: 'Sets probability threshold for more relevant outputs.',
71+
})
5372
@IsNumber()
5473
top_p: number;
5574
}

0 commit comments

Comments
 (0)