diff --git a/api/src/nlp/repositories/nlp-entity.repository.spec.ts b/api/src/nlp/repositories/nlp-entity.repository.spec.ts index 96920e70..ed4141be 100644 --- a/api/src/nlp/repositories/nlp-entity.repository.spec.ts +++ b/api/src/nlp/repositories/nlp-entity.repository.spec.ts @@ -228,4 +228,28 @@ describe('NlpEntityRepository', () => { 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); + }); + }); }); diff --git a/api/src/nlp/repositories/nlp-value.repository.spec.ts b/api/src/nlp/repositories/nlp-value.repository.spec.ts index 48689727..dec67457 100644 --- a/api/src/nlp/repositories/nlp-value.repository.spec.ts +++ b/api/src/nlp/repositories/nlp-value.repository.spec.ts @@ -250,4 +250,28 @@ describe('NlpValueRepository', () => { 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); + }); + }); });