From 0e1d57dba1109f7bb1af153ad251717141769045 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Fri, 13 Jun 2025 15:55:10 +0100 Subject: [PATCH] fix(api): enhance unit tests --- .../nlp/repositories/nlp-entity.repository.spec.ts | 11 ++++++----- .../nlp/repositories/nlp-value.repository.spec.ts | 13 ++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/api/src/nlp/repositories/nlp-entity.repository.spec.ts b/api/src/nlp/repositories/nlp-entity.repository.spec.ts index c0985826..6463a532 100644 --- a/api/src/nlp/repositories/nlp-entity.repository.spec.ts +++ b/api/src/nlp/repositories/nlp-entity.repository.spec.ts @@ -116,16 +116,17 @@ describe('NlpEntityRepository', () => { describe('The deleteCascadeOne function', () => { it('should delete a nlp entity', async () => { + nlpValueRepository.eventEmitter.on( + 'hook:nlpEntity:preDelete', + async (...args) => { + await nlpService.handleEntityDelete(args[0], args[1]); + }, + ); const intentNlpEntity = await nlpEntityRepository.findOne({ name: 'intent', }); const result = await nlpEntityRepository.deleteOne(intentNlpEntity!.id); - await nlpService.handleEntityDelete( - {}, - { _id: intentNlpEntity!.id, builtin: { $ne: true } }, - ); - expect(result.deletedCount).toEqual(1); const intentNlpValues = await nlpValueRepository.find({ diff --git a/api/src/nlp/repositories/nlp-value.repository.spec.ts b/api/src/nlp/repositories/nlp-value.repository.spec.ts index 06bf9547..46b12d14 100644 --- a/api/src/nlp/repositories/nlp-value.repository.spec.ts +++ b/api/src/nlp/repositories/nlp-value.repository.spec.ts @@ -75,8 +75,6 @@ describe('NlpValueRepository', () => { { provide: CACHE_MANAGER, useValue: { - del: jest.fn(), - get: jest.fn(), set: jest.fn(), }, }, @@ -169,12 +167,13 @@ describe('NlpValueRepository', () => { describe('The deleteCascadeOne function', () => { it('should delete a nlp Value', async () => { - const result = await nlpValueRepository.deleteOne(nlpValues[1].id); - - await nlpService.handleValueDelete( - {}, - { _id: nlpValues[1].id, builtin: { $ne: true } }, + nlpValueRepository.eventEmitter.on( + 'hook:nlpValue:preDelete', + async (...args) => { + await nlpService.handleValueDelete(args[0], args[1]); + }, ); + const result = await nlpValueRepository.deleteOne(nlpValues[1].id); expect(result.deletedCount).toEqual(1); const sampleEntities = await nlpSampleEntityRepository.find({