mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(api): add postCreate unit tests
This commit is contained in:
parent
a810702ff6
commit
bf37cd556a
@ -18,6 +18,7 @@ import { SettingRepository } from '@/setting/repositories/setting.repository';
|
||||
import { SettingModel } from '@/setting/schemas/setting.schema';
|
||||
import { SettingSeeder } from '@/setting/seeds/setting.seed';
|
||||
import { SettingService } from '@/setting/services/setting.service';
|
||||
import { IGNORED_TEST_FIELDS } from '@/utils/test/constants';
|
||||
import { nlpEntityFixtures } from '@/utils/test/fixtures/nlpentity';
|
||||
import { installNlpValueFixtures } from '@/utils/test/fixtures/nlpvalue';
|
||||
import { getPageQuery } from '@/utils/test/pagination';
|
||||
@ -173,4 +174,44 @@ describe('NlpEntityRepository', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('postCreate', () => {
|
||||
it('should not create and attached a foreign_id to the create nlp entity', async () => {
|
||||
nlpEntityRepository.eventEmitter.once(
|
||||
'hook:nlpEntity:postCreate',
|
||||
async (...args) => {
|
||||
await nlpService.handleEntityPostCreate(args[0]);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await nlpEntityRepository.create({
|
||||
name: 'test1',
|
||||
});
|
||||
const intentNlpEntity = await nlpEntityRepository.findOne(result.id);
|
||||
|
||||
expect(intentNlpEntity?.foreign_id).toBeDefined();
|
||||
expect(intentNlpEntity).toEqualPayload(result, [
|
||||
...IGNORED_TEST_FIELDS,
|
||||
'foreign_id',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not create and attached a foreign_id to the create nlp entity with builtin true', async () => {
|
||||
nlpEntityRepository.eventEmitter.once(
|
||||
'hook:nlpEntity:postCreate',
|
||||
async (...args) => {
|
||||
await nlpService.handleEntityPostCreate(args[0]);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await nlpEntityRepository.create({
|
||||
name: 'test2',
|
||||
builtin: true,
|
||||
});
|
||||
const intentNlpEntity = await nlpEntityRepository.findOne(result.id);
|
||||
|
||||
expect(intentNlpEntity?.foreign_id).toBeUndefined();
|
||||
expect(intentNlpEntity).toEqualPayload(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -18,6 +18,7 @@ import { SettingRepository } from '@/setting/repositories/setting.repository';
|
||||
import { SettingModel } from '@/setting/schemas/setting.schema';
|
||||
import { SettingSeeder } from '@/setting/seeds/setting.seed';
|
||||
import { SettingService } from '@/setting/services/setting.service';
|
||||
import { IGNORED_TEST_FIELDS } from '@/utils/test/constants';
|
||||
import { nlpEntityFixtures } from '@/utils/test/fixtures/nlpentity';
|
||||
import { installNlpSampleEntityFixtures } from '@/utils/test/fixtures/nlpsampleentity';
|
||||
import { nlpValueFixtures } from '@/utils/test/fixtures/nlpvalue';
|
||||
@ -53,6 +54,7 @@ describe('NlpValueRepository', () => {
|
||||
let nlpSampleEntityRepository: NlpSampleEntityRepository;
|
||||
let nlpValues: NlpValue[];
|
||||
let nlpService: NlpService;
|
||||
let nlpEntityRepository: NlpEntityRepository;
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks, module } = await buildTestingMocks({
|
||||
@ -102,11 +104,16 @@ describe('NlpValueRepository', () => {
|
||||
],
|
||||
});
|
||||
|
||||
[nlpValueRepository, nlpSampleEntityRepository, nlpService] =
|
||||
await getMocks([
|
||||
[
|
||||
nlpValueRepository,
|
||||
nlpSampleEntityRepository,
|
||||
nlpService,
|
||||
nlpEntityRepository,
|
||||
] = await getMocks([
|
||||
NlpValueRepository,
|
||||
NlpSampleEntityRepository,
|
||||
NlpService,
|
||||
NlpEntityRepository,
|
||||
]);
|
||||
nlpValues = await nlpValueRepository.findAll();
|
||||
const llmNluHelper = module.get(LlmNluHelper);
|
||||
@ -180,4 +187,53 @@ describe('NlpValueRepository', () => {
|
||||
expect(sampleEntities.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('postCreate', () => {
|
||||
it('should create and attached a foreign_id to the create nlp value', async () => {
|
||||
nlpValueRepository.eventEmitter.once(
|
||||
'hook:nlpValue:postCreate',
|
||||
async (...args) => {
|
||||
await nlpService.handleValuePostCreate(args[0]);
|
||||
},
|
||||
);
|
||||
|
||||
const createdNlpEntity = await nlpEntityRepository.create({
|
||||
name: 'test1',
|
||||
});
|
||||
|
||||
const result = await nlpValueRepository.create({
|
||||
entity: createdNlpEntity.id,
|
||||
value: 'test',
|
||||
});
|
||||
const intentNlpEntity = await nlpValueRepository.findOne(result.id);
|
||||
|
||||
expect(intentNlpEntity?.foreign_id).toBeDefined();
|
||||
expect(intentNlpEntity).toEqualPayload(result, [
|
||||
...IGNORED_TEST_FIELDS,
|
||||
'foreign_id',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should create and attached a foreign_id to the create nlp value with builtin true', async () => {
|
||||
nlpValueRepository.eventEmitter.once(
|
||||
'hook:nlpValue:postCreate',
|
||||
async (...args) => {
|
||||
await nlpService.handleValuePostCreate(args[0]);
|
||||
},
|
||||
);
|
||||
|
||||
const createdNlpEntity = await nlpEntityRepository.create({
|
||||
name: 'nlpEntityTest2',
|
||||
});
|
||||
const result = await nlpValueRepository.create({
|
||||
entity: createdNlpEntity.id,
|
||||
value: 'nlpValueTest2',
|
||||
builtin: true,
|
||||
});
|
||||
const intentNlpEntity = await nlpValueRepository.findOne(result.id);
|
||||
|
||||
expect(intentNlpEntity?.foreign_id).toBeUndefined();
|
||||
expect(intentNlpEntity).toEqualPayload(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user