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 15:31:20 +01:00
commit de8615bf3a
2 changed files with 14 additions and 14 deletions

View File

@ -180,20 +180,20 @@ describe('NlpEntityRepository', () => {
}); });
describe('postCreate', () => { describe('postCreate', () => {
it('should not create and attached a foreign_id to the create nlp entity', async () => { it('should create and attach a foreign_id to the newly created nlp entity', async () => {
nlpEntityRepository.eventEmitter.once( nlpEntityRepository.eventEmitter.once(
'hook:nlpEntity:postCreate', 'hook:nlpEntity:postCreate',
async (...[created]) => { async (...[created]) => {
const spy1 = jest.spyOn(llmNluHelper, 'addEntity'); const helperSpy = jest.spyOn(llmNluHelper, 'addEntity');
const spy2 = jest.spyOn(nlpEntityService, 'updateOne'); jest.spyOn(nlpEntityService, 'updateOne');
await nlpService.handleEntityPostCreate(created); await nlpService.handleEntityPostCreate(created);
expect(spy1).toHaveBeenCalledWith(created); expect(helperSpy).toHaveBeenCalledWith(created);
expect(spy2).toHaveBeenCalledWith( expect(nlpEntityService.updateOne).toHaveBeenCalledWith(
{ {
_id: created._id, _id: created._id,
}, },
{ foreign_id: await spy1.mock.results[0].value }, { foreign_id: await helperSpy.mock.results[0].value },
); );
}, },
); );
@ -210,7 +210,7 @@ describe('NlpEntityRepository', () => {
]); ]);
}); });
it('should not create and attached a foreign_id to the create nlp entity with builtin true', async () => { it('should not create and attach a foreign_id to the newly created nlp entity with builtin set to true', async () => {
nlpEntityRepository.eventEmitter.once( nlpEntityRepository.eventEmitter.once(
'hook:nlpEntity:postCreate', 'hook:nlpEntity:postCreate',
async (...[created]) => { async (...[created]) => {

View File

@ -193,20 +193,20 @@ describe('NlpValueRepository', () => {
}); });
describe('postCreate', () => { describe('postCreate', () => {
it('should create and attached a foreign_id to the create nlp value', async () => { it('should create and attach a foreign_id to the newly created nlp value', async () => {
nlpValueRepository.eventEmitter.once( nlpValueRepository.eventEmitter.once(
'hook:nlpValue:postCreate', 'hook:nlpValue:postCreate',
async (...[created]) => { async (...[created]) => {
const spy1 = jest.spyOn(llmNluHelper, 'addValue'); const helperSpy = jest.spyOn(llmNluHelper, 'addValue');
const spy2 = jest.spyOn(nlpValueService, 'updateOne'); jest.spyOn(nlpValueService, 'updateOne');
await nlpService.handleValuePostCreate(created); await nlpService.handleValuePostCreate(created);
expect(spy1).toHaveBeenCalledWith(created); expect(helperSpy).toHaveBeenCalledWith(created);
expect(spy2).toHaveBeenCalledWith( expect(nlpValueService.updateOne).toHaveBeenCalledWith(
{ {
_id: created._id, _id: created._id,
}, },
{ foreign_id: await spy1.mock.results[0].value }, { foreign_id: await helperSpy.mock.results[0].value },
); );
}, },
); );
@ -228,7 +228,7 @@ describe('NlpValueRepository', () => {
]); ]);
}); });
it('should create and attached a foreign_id to the create nlp value with builtin true', async () => { it('should not create and attach a foreign_id to the newly created nlp value with builtin set to true', async () => {
nlpValueRepository.eventEmitter.once( nlpValueRepository.eventEmitter.once(
'hook:nlpValue:postCreate', 'hook:nlpValue:postCreate',
async (...[created]) => { async (...[created]) => {