mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(api): enhance postCreate unit tests
This commit is contained in:
parent
bf37cd556a
commit
66c2a18e1c
@ -48,6 +48,8 @@ describe('NlpEntityRepository', () => {
|
|||||||
let nlpValueRepository: NlpValueRepository;
|
let nlpValueRepository: NlpValueRepository;
|
||||||
let firstNameNlpEntity: NlpEntity | null;
|
let firstNameNlpEntity: NlpEntity | null;
|
||||||
let nlpService: NlpService;
|
let nlpService: NlpService;
|
||||||
|
let llmNluHelper: LlmNluHelper;
|
||||||
|
let nlpEntityService: NlpEntityService;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const { getMocks, module } = await buildTestingMocks({
|
const { getMocks, module } = await buildTestingMocks({
|
||||||
@ -99,15 +101,17 @@ describe('NlpEntityRepository', () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
[nlpEntityRepository, nlpValueRepository, nlpService] = await getMocks([
|
[nlpEntityRepository, nlpValueRepository, nlpService, nlpEntityService] =
|
||||||
|
await getMocks([
|
||||||
NlpEntityRepository,
|
NlpEntityRepository,
|
||||||
NlpValueRepository,
|
NlpValueRepository,
|
||||||
NlpService,
|
NlpService,
|
||||||
|
NlpEntityService,
|
||||||
]);
|
]);
|
||||||
firstNameNlpEntity = await nlpEntityRepository.findOne({
|
firstNameNlpEntity = await nlpEntityRepository.findOne({
|
||||||
name: 'firstname',
|
name: 'firstname',
|
||||||
});
|
});
|
||||||
const llmNluHelper = module.get(LlmNluHelper);
|
llmNluHelper = module.get(LlmNluHelper);
|
||||||
module.get(HelperService).register(llmNluHelper);
|
module.get(HelperService).register(llmNluHelper);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -179,8 +183,18 @@ describe('NlpEntityRepository', () => {
|
|||||||
it('should not create and attached a foreign_id to the create nlp entity', async () => {
|
it('should not create and attached a foreign_id to the create nlp entity', async () => {
|
||||||
nlpEntityRepository.eventEmitter.once(
|
nlpEntityRepository.eventEmitter.once(
|
||||||
'hook:nlpEntity:postCreate',
|
'hook:nlpEntity:postCreate',
|
||||||
async (...args) => {
|
async (...[created]) => {
|
||||||
await nlpService.handleEntityPostCreate(args[0]);
|
const spy1 = jest.spyOn(llmNluHelper, 'addEntity');
|
||||||
|
const spy2 = jest.spyOn(nlpEntityService, 'updateOne');
|
||||||
|
await nlpService.handleEntityPostCreate(created);
|
||||||
|
|
||||||
|
expect(spy1).toHaveBeenCalledWith(created);
|
||||||
|
expect(spy2).toHaveBeenCalledWith(
|
||||||
|
{
|
||||||
|
_id: created._id,
|
||||||
|
},
|
||||||
|
{ foreign_id: await spy1.mock.results[0].value },
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -199,8 +213,8 @@ 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 attached a foreign_id to the create nlp entity with builtin true', async () => {
|
||||||
nlpEntityRepository.eventEmitter.once(
|
nlpEntityRepository.eventEmitter.once(
|
||||||
'hook:nlpEntity:postCreate',
|
'hook:nlpEntity:postCreate',
|
||||||
async (...args) => {
|
async (...[created]) => {
|
||||||
await nlpService.handleEntityPostCreate(args[0]);
|
await nlpService.handleEntityPostCreate(created);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user