Merge branch '1132-issue---api-make-sure-hookentityprepostcreate-is-used-across-the-board' into 1134-issue---api-make-sure-hookentityprepostupdate-is-used-across-the-board

This commit is contained in:
yassinedorbozgithub 2025-06-17 09:01:19 +01:00
commit 4b33b21859
2 changed files with 41 additions and 13 deletions

View File

@ -48,6 +48,8 @@ describe('NlpEntityRepository', () => {
let nlpValueRepository: NlpValueRepository;
let firstNameNlpEntity: NlpEntity | null;
let nlpService: NlpService;
let llmNluHelper: LlmNluHelper;
let nlpEntityService: NlpEntityService;
beforeAll(async () => {
const { getMocks, module } = await buildTestingMocks({
@ -99,15 +101,17 @@ describe('NlpEntityRepository', () => {
],
});
[nlpEntityRepository, nlpValueRepository, nlpService] = await getMocks([
[nlpEntityRepository, nlpValueRepository, nlpService, nlpEntityService] =
await getMocks([
NlpEntityRepository,
NlpValueRepository,
NlpService,
NlpEntityService,
]);
firstNameNlpEntity = await nlpEntityRepository.findOne({
name: 'firstname',
});
const llmNluHelper = module.get(LlmNluHelper);
llmNluHelper = module.get(LlmNluHelper);
module.get(HelperService).register(llmNluHelper);
});
@ -179,8 +183,18 @@ describe('NlpEntityRepository', () => {
it('should not create and attached a foreign_id to the create nlp entity', async () => {
nlpEntityRepository.eventEmitter.once(
'hook:nlpEntity:postCreate',
async (...args) => {
await nlpService.handleEntityPostCreate(args[0]);
async (...[created]) => {
const spy1 = jest.spyOn(llmNluHelper, 'addEntity');
const spy2 = jest.spyOn(nlpEntityService, 'updateOne');
await nlpService.handleEntityPostCreate(created);
expect(spy1).toHaveBeenCalledWith(created);
expect(spy2).toHaveBeenCalledWith(
{
_id: created._id,
},
{ foreign_id: await spy1.mock.results[0].value },
);
},
);
@ -199,8 +213,8 @@ describe('NlpEntityRepository', () => {
it('should not create and attached a foreign_id to the create nlp entity with builtin true', async () => {
nlpEntityRepository.eventEmitter.once(
'hook:nlpEntity:postCreate',
async (...args) => {
await nlpService.handleEntityPostCreate(args[0]);
async (...[created]) => {
await nlpService.handleEntityPostCreate(created);
},
);

View File

@ -55,6 +55,8 @@ describe('NlpValueRepository', () => {
let nlpValues: NlpValue[];
let nlpService: NlpService;
let nlpEntityRepository: NlpEntityRepository;
let llmNluHelper: LlmNluHelper;
let nlpValueService: NlpValueService;
beforeAll(async () => {
const { getMocks, module } = await buildTestingMocks({
@ -109,14 +111,16 @@ describe('NlpValueRepository', () => {
nlpSampleEntityRepository,
nlpService,
nlpEntityRepository,
nlpValueService,
] = await getMocks([
NlpValueRepository,
NlpSampleEntityRepository,
NlpService,
NlpEntityRepository,
NlpValueService,
]);
nlpValues = await nlpValueRepository.findAll();
const llmNluHelper = module.get(LlmNluHelper);
llmNluHelper = module.get(LlmNluHelper);
module.get(HelperService).register(llmNluHelper);
});
@ -192,8 +196,18 @@ describe('NlpValueRepository', () => {
it('should create and attached a foreign_id to the create nlp value', async () => {
nlpValueRepository.eventEmitter.once(
'hook:nlpValue:postCreate',
async (...args) => {
await nlpService.handleValuePostCreate(args[0]);
async (...[created]) => {
const spy1 = jest.spyOn(llmNluHelper, 'addValue');
const spy2 = jest.spyOn(nlpValueService, 'updateOne');
await nlpService.handleValuePostCreate(created);
expect(spy1).toHaveBeenCalledWith(created);
expect(spy2).toHaveBeenCalledWith(
{
_id: created._id,
},
{ foreign_id: await spy1.mock.results[0].value },
);
},
);