mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(api): enhance NlpValue postCreate unit tests
This commit is contained in:
parent
66c2a18e1c
commit
9bb985c37f
@ -55,6 +55,8 @@ describe('NlpValueRepository', () => {
|
|||||||
let nlpValues: NlpValue[];
|
let nlpValues: NlpValue[];
|
||||||
let nlpService: NlpService;
|
let nlpService: NlpService;
|
||||||
let nlpEntityRepository: NlpEntityRepository;
|
let nlpEntityRepository: NlpEntityRepository;
|
||||||
|
let llmNluHelper: LlmNluHelper;
|
||||||
|
let nlpValueService: NlpValueService;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const { getMocks, module } = await buildTestingMocks({
|
const { getMocks, module } = await buildTestingMocks({
|
||||||
@ -109,14 +111,16 @@ describe('NlpValueRepository', () => {
|
|||||||
nlpSampleEntityRepository,
|
nlpSampleEntityRepository,
|
||||||
nlpService,
|
nlpService,
|
||||||
nlpEntityRepository,
|
nlpEntityRepository,
|
||||||
|
nlpValueService,
|
||||||
] = await getMocks([
|
] = await getMocks([
|
||||||
NlpValueRepository,
|
NlpValueRepository,
|
||||||
NlpSampleEntityRepository,
|
NlpSampleEntityRepository,
|
||||||
NlpService,
|
NlpService,
|
||||||
NlpEntityRepository,
|
NlpEntityRepository,
|
||||||
|
NlpValueService,
|
||||||
]);
|
]);
|
||||||
nlpValues = await nlpValueRepository.findAll();
|
nlpValues = await nlpValueRepository.findAll();
|
||||||
const llmNluHelper = module.get(LlmNluHelper);
|
llmNluHelper = module.get(LlmNluHelper);
|
||||||
module.get(HelperService).register(llmNluHelper);
|
module.get(HelperService).register(llmNluHelper);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -192,8 +196,18 @@ describe('NlpValueRepository', () => {
|
|||||||
it('should create and attached a foreign_id to the create nlp value', async () => {
|
it('should create and attached a foreign_id to the create nlp value', async () => {
|
||||||
nlpValueRepository.eventEmitter.once(
|
nlpValueRepository.eventEmitter.once(
|
||||||
'hook:nlpValue:postCreate',
|
'hook:nlpValue:postCreate',
|
||||||
async (...args) => {
|
async (...[created]) => {
|
||||||
await nlpService.handleValuePostCreate(args[0]);
|
const spy1 = jest.spyOn(llmNluHelper, 'addValue');
|
||||||
|
const spy2 = jest.spyOn(nlpValueService, 'updateOne');
|
||||||
|
await nlpService.handleValuePostCreate(created);
|
||||||
|
|
||||||
|
expect(spy1).toHaveBeenCalledWith(created);
|
||||||
|
expect(spy2).toHaveBeenCalledWith(
|
||||||
|
{
|
||||||
|
_id: created._id,
|
||||||
|
},
|
||||||
|
{ foreign_id: await spy1.mock.results[0].value },
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user