fix(api): optimize helper injection

This commit is contained in:
yassinedorbozgithub 2025-06-12 15:27:28 +01:00
parent 1468da3d54
commit b7253c99ec
2 changed files with 13 additions and 36 deletions

View File

@ -47,11 +47,9 @@ describe('NlpEntityRepository', () => {
let nlpValueRepository: NlpValueRepository; let nlpValueRepository: NlpValueRepository;
let firstNameNlpEntity: NlpEntity | null; let firstNameNlpEntity: NlpEntity | null;
let nlpService: NlpService; let nlpService: NlpService;
let helperService: HelperService;
let llmNluHelper: LlmNluHelper;
beforeAll(async () => { beforeAll(async () => {
const { getMocks } = await buildTestingMocks({ const { getMocks, module } = await buildTestingMocks({
imports: [ imports: [
rootMongooseTestModule(installNlpValueFixtures), rootMongooseTestModule(installNlpValueFixtures),
MongooseModule.forFeature([ MongooseModule.forFeature([
@ -86,9 +84,6 @@ describe('NlpEntityRepository', () => {
{ {
provide: SettingService, provide: SettingService,
useValue: { useValue: {
getConfig: jest.fn(() => ({
chatbot: { lang: { default: 'fr' } },
})),
getSettings: jest.fn(() => ({ getSettings: jest.fn(() => ({
chatbot_settings: { chatbot_settings: {
default_nlu_helper: 'llm-nlu-helper', default_nlu_helper: 'llm-nlu-helper',
@ -103,23 +98,16 @@ describe('NlpEntityRepository', () => {
], ],
}); });
[ [nlpEntityRepository, nlpValueRepository, nlpService] = await getMocks([
nlpEntityRepository,
nlpValueRepository,
nlpService,
helperService,
llmNluHelper,
] = await getMocks([
NlpEntityRepository, NlpEntityRepository,
NlpValueRepository, NlpValueRepository,
NlpService, NlpService,
HelperService,
LlmNluHelper,
]); ]);
firstNameNlpEntity = await nlpEntityRepository.findOne({ firstNameNlpEntity = await nlpEntityRepository.findOne({
name: 'firstname', name: 'firstname',
}); });
helperService.register(llmNluHelper); const llmNluHelper = module.get(LlmNluHelper);
module.get(HelperService).register(llmNluHelper);
}); });
afterAll(closeInMongodConnection); afterAll(closeInMongodConnection);

View File

@ -54,11 +54,9 @@ describe('NlpValueRepository', () => {
let nlpSampleEntityRepository: NlpSampleEntityRepository; let nlpSampleEntityRepository: NlpSampleEntityRepository;
let nlpValues: NlpValue[]; let nlpValues: NlpValue[];
let nlpService: NlpService; let nlpService: NlpService;
let helperService: HelperService;
let llmNluHelper: LlmNluHelper;
beforeAll(async () => { beforeAll(async () => {
const { getMocks } = await buildTestingMocks({ const { getMocks, module } = await buildTestingMocks({
imports: [ imports: [
rootMongooseTestModule(installNlpSampleEntityFixtures), rootMongooseTestModule(installNlpSampleEntityFixtures),
MongooseModule.forFeature([ MongooseModule.forFeature([
@ -95,9 +93,6 @@ describe('NlpValueRepository', () => {
{ {
provide: SettingService, provide: SettingService,
useValue: { useValue: {
getConfig: jest.fn(() => ({
chatbot: { lang: { default: 'fr' } },
})),
getSettings: jest.fn(() => ({ getSettings: jest.fn(() => ({
chatbot_settings: { chatbot_settings: {
default_nlu_helper: 'llm-nlu-helper', default_nlu_helper: 'llm-nlu-helper',
@ -111,21 +106,15 @@ describe('NlpValueRepository', () => {
], ],
}); });
[ [nlpValueRepository, nlpSampleEntityRepository, nlpService] =
nlpValueRepository, await getMocks([
nlpSampleEntityRepository, NlpValueRepository,
nlpService, NlpSampleEntityRepository,
helperService, NlpService,
llmNluHelper, ]);
] = await getMocks([
NlpValueRepository,
NlpSampleEntityRepository,
NlpService,
HelperService,
LlmNluHelper,
]);
nlpValues = await nlpValueRepository.findAll(); nlpValues = await nlpValueRepository.findAll();
helperService.register(llmNluHelper); const llmNluHelper = module.get(LlmNluHelper);
module.get(HelperService).register(llmNluHelper);
}); });
afterAll(closeInMongodConnection); afterAll(closeInMongodConnection);