mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
Merge branch '1132-issue---api-make-sure-hookentityprepostcreate-is-used-across-the-board' into 1134-issue---api-make-sure-hookentityprepostupdate-is-used-across-the-board
This commit is contained in:
commit
16cb46d403
@ -18,6 +18,7 @@ import { SettingRepository } from '@/setting/repositories/setting.repository';
|
|||||||
import { SettingModel } from '@/setting/schemas/setting.schema';
|
import { SettingModel } from '@/setting/schemas/setting.schema';
|
||||||
import { SettingSeeder } from '@/setting/seeds/setting.seed';
|
import { SettingSeeder } from '@/setting/seeds/setting.seed';
|
||||||
import { SettingService } from '@/setting/services/setting.service';
|
import { SettingService } from '@/setting/services/setting.service';
|
||||||
|
import { IGNORED_TEST_FIELDS } from '@/utils/test/constants';
|
||||||
import { nlpEntityFixtures } from '@/utils/test/fixtures/nlpentity';
|
import { nlpEntityFixtures } from '@/utils/test/fixtures/nlpentity';
|
||||||
import { installNlpValueFixtures } from '@/utils/test/fixtures/nlpvalue';
|
import { installNlpValueFixtures } from '@/utils/test/fixtures/nlpvalue';
|
||||||
import { getPageQuery } from '@/utils/test/pagination';
|
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 { SettingModel } from '@/setting/schemas/setting.schema';
|
||||||
import { SettingSeeder } from '@/setting/seeds/setting.seed';
|
import { SettingSeeder } from '@/setting/seeds/setting.seed';
|
||||||
import { SettingService } from '@/setting/services/setting.service';
|
import { SettingService } from '@/setting/services/setting.service';
|
||||||
|
import { IGNORED_TEST_FIELDS } from '@/utils/test/constants';
|
||||||
import { nlpEntityFixtures } from '@/utils/test/fixtures/nlpentity';
|
import { nlpEntityFixtures } from '@/utils/test/fixtures/nlpentity';
|
||||||
import { installNlpSampleEntityFixtures } from '@/utils/test/fixtures/nlpsampleentity';
|
import { installNlpSampleEntityFixtures } from '@/utils/test/fixtures/nlpsampleentity';
|
||||||
import { nlpValueFixtures } from '@/utils/test/fixtures/nlpvalue';
|
import { nlpValueFixtures } from '@/utils/test/fixtures/nlpvalue';
|
||||||
@ -53,6 +54,7 @@ describe('NlpValueRepository', () => {
|
|||||||
let nlpSampleEntityRepository: NlpSampleEntityRepository;
|
let nlpSampleEntityRepository: NlpSampleEntityRepository;
|
||||||
let nlpValues: NlpValue[];
|
let nlpValues: NlpValue[];
|
||||||
let nlpService: NlpService;
|
let nlpService: NlpService;
|
||||||
|
let nlpEntityRepository: NlpEntityRepository;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const { getMocks, module } = await buildTestingMocks({
|
const { getMocks, module } = await buildTestingMocks({
|
||||||
@ -102,12 +104,17 @@ describe('NlpValueRepository', () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
[nlpValueRepository, nlpSampleEntityRepository, nlpService] =
|
[
|
||||||
await getMocks([
|
nlpValueRepository,
|
||||||
NlpValueRepository,
|
nlpSampleEntityRepository,
|
||||||
NlpSampleEntityRepository,
|
nlpService,
|
||||||
NlpService,
|
nlpEntityRepository,
|
||||||
]);
|
] = await getMocks([
|
||||||
|
NlpValueRepository,
|
||||||
|
NlpSampleEntityRepository,
|
||||||
|
NlpService,
|
||||||
|
NlpEntityRepository,
|
||||||
|
]);
|
||||||
nlpValues = await nlpValueRepository.findAll();
|
nlpValues = await nlpValueRepository.findAll();
|
||||||
const llmNluHelper = module.get(LlmNluHelper);
|
const llmNluHelper = module.get(LlmNluHelper);
|
||||||
module.get(HelperService).register(llmNluHelper);
|
module.get(HelperService).register(llmNluHelper);
|
||||||
@ -180,4 +187,53 @@ describe('NlpValueRepository', () => {
|
|||||||
expect(sampleEntities.length).toEqual(0);
|
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