fix(api): enhance postUpdate unit tests

This commit is contained in:
yassinedorbozgithub 2025-06-18 09:06:32 +01:00
parent 6001fef761
commit 848a1b3767
2 changed files with 14 additions and 3 deletions

View File

@ -231,12 +231,13 @@ describe('NlpEntityRepository', () => {
describe('postUpdate', () => {
it('should update an NlpEntity and trigger a postUpdate event', async () => {
jest.spyOn(nlpService, 'handleEntityPostUpdate');
jest.spyOn(llmNluHelper, 'updateEntity');
nlpEntityRepository.eventEmitter.once(
'hook:nlpEntity:postUpdate',
async (...[query, updated]) => {
jest.spyOn(llmNluHelper, 'updateEntity');
await nlpService.handleEntityPostUpdate(query, updated);
expect(llmNluHelper.updateEntity).toHaveBeenCalledWith(updated);
},
);
@ -247,6 +248,10 @@ describe('NlpEntityRepository', () => {
},
{ value: 'test3' },
);
expect(nlpService.handleEntityPostUpdate).toHaveBeenCalledTimes(1);
expect(llmNluHelper.updateEntity).toHaveBeenCalledTimes(1);
const result = await nlpEntityRepository.findOne(updatedNlpEntity.id);
expect(result).toEqualPayload(updatedNlpEntity);

View File

@ -253,10 +253,12 @@ describe('NlpValueRepository', () => {
describe('postUpdate', () => {
it('should update an NlpValue and trigger a postUpdate event', async () => {
jest.spyOn(nlpService, 'handleValuePostUpdate');
jest.spyOn(llmNluHelper, 'updateValue');
nlpValueRepository.eventEmitter.once(
'hook:nlpValue:postUpdate',
async (...[query, updated]) => {
jest.spyOn(llmNluHelper, 'updateValue');
await nlpService.handleValuePostUpdate(query, updated);
expect(llmNluHelper.updateValue).toHaveBeenCalledWith(updated);
@ -269,6 +271,10 @@ describe('NlpValueRepository', () => {
},
{ value: 'test2' },
);
expect(nlpService.handleValuePostUpdate).toHaveBeenCalledTimes(1);
expect(llmNluHelper.updateValue).toHaveBeenCalledTimes(1);
const result = await nlpValueRepository.findOne(updatedNlpValue.id);
expect(result).toEqualPayload(updatedNlpValue);