fix(api): enhance NlpValue postUpdate unit tests

This commit is contained in:
yassinedorbozgithub 2025-06-17 11:38:37 +01:00
parent 3ce40840f6
commit 2d133450f1
2 changed files with 48 additions and 0 deletions

View File

@ -228,4 +228,28 @@ describe('NlpEntityRepository', () => {
expect(intentNlpEntity).toEqualPayload(result); expect(intentNlpEntity).toEqualPayload(result);
}); });
}); });
describe('postUpdate', () => {
it('should update an NlpValue and trigger a postUpdate event', async () => {
nlpEntityRepository.eventEmitter.once(
'hook:nlpEntity:postUpdate',
async (...[query, updated]) => {
const spy1 = jest.spyOn(llmNluHelper, 'updateEntity');
await nlpService.handleEntityPostUpdate(query, updated);
expect(spy1).toHaveBeenCalledWith(updated);
},
);
const updatedNlpEntity = await nlpEntityRepository.updateOne(
{
name: 'test2',
},
{ value: 'test3' },
);
const result = await nlpEntityRepository.findOne(updatedNlpEntity.id);
expect(result).toEqualPayload(updatedNlpEntity);
});
});
}); });

View File

@ -250,4 +250,28 @@ describe('NlpValueRepository', () => {
expect(intentNlpEntity).toEqualPayload(result); expect(intentNlpEntity).toEqualPayload(result);
}); });
}); });
describe('postUpdate', () => {
it('should update an NlpValue and trigger a postUpdate event', async () => {
nlpValueRepository.eventEmitter.once(
'hook:nlpValue:postUpdate',
async (...[query, updated]) => {
const spy1 = jest.spyOn(llmNluHelper, 'updateValue');
await nlpService.handleValuePostUpdate(query, updated);
expect(spy1).toHaveBeenCalledWith(updated);
},
);
const updatedNlpEntity = await nlpValueRepository.updateOne(
{
value: 'test',
},
{ value: 'test2' },
);
const result = await nlpValueRepository.findOne(updatedNlpEntity.id);
expect(result).toEqualPayload(updatedNlpEntity);
});
});
}); });