Skip to content

Commit

Permalink
Adds indexers unit test back and fixes them (#8360)
Browse files Browse the repository at this point in the history
Co-authored-by: Soroush <hatpick@fmail.com>
  • Loading branch information
hatpick and Soroush committed Jul 13, 2021
1 parent 267d9ca commit 6227ded
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 19 deletions.
1 change: 1 addition & 0 deletions Composer/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = {
'<rootDir>/packages/intellisense',
'<rootDir>/packages/lib/code-editor',
'<rootDir>/packages/lib/shared',
'<rootDir>/packages/lib/indexers',
'<rootDir>/packages/lib/ui-shared',
'<rootDir>/packages/server',
'<rootDir>/packages/electron-server',
Expand Down
78 changes: 69 additions & 9 deletions Composer/packages/lib/indexers/__tests__/botIndexer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const botAssets: BotAssets = {
setting: {
languages: ['en-us', 'zh-cn', 'af'],
defaultLanguage: 'en-us',
customFunctions: [],
importedLibraries: [],
botId: '',
skillHostEndpoint: '',
skill: {
Expand All @@ -98,15 +100,19 @@ describe('check manifest', () => {
});

describe('check LUIS & QnA key', () => {
it('LUIS authoringKey should exist in setting', () => {
it('LUIS authoringKey and region should exist in setting', () => {
const diagnostics = checkSetting(botAssets);
expect(diagnostics.length).toEqual(1);
expect(diagnostics.length).toEqual(2);
});

it('LUIS authoringKey should exist in setting', () => {
it('No diagnostics when LUIS authoringKey should exist in setting', () => {
const mergedSettings = {
...botAssets.setting,
luis: { authoringKey: '4d210acc6d794d71a2a3450*****2fb7', endpointKey: '' } as ILuisConfig,
luis: {
authoringKey: '4d210acc6d794d71a2a3450*****2fb7',
endpointKey: '',
authoringRegion: 'westus',
} as ILuisConfig,
};
const diagnostics = checkSetting({ ...botAssets, setting: mergedSettings });
expect(diagnostics.length).toEqual(0);
Expand All @@ -115,6 +121,14 @@ describe('check LUIS & QnA key', () => {
it('QnA subscriptionKey should exist in setting, when qna file is not empty', () => {
const botAssets2 = {
...botAssets,
setting: {
...botAssets.setting,
luis: {
authoringKey: '4d210acc6d794d71a2a3450*****2fb7',
endpointKey: '',
authoringRegion: 'westus',
} as ILuisConfig,
},
dialogs: [
{
luFile: 'a.lu',
Expand All @@ -129,12 +143,20 @@ describe('check LUIS & QnA key', () => {
],
};
const diagnostics = checkSetting(botAssets2);
expect(diagnostics.length).toEqual(2);
expect(diagnostics.length).toEqual(1);
});

it('QnA subscriptionKey should exist in setting, when qna file is empty', () => {
it('QnA subscriptionKey should not be required in setting, when qna file is empty', () => {
const botAssets2 = {
...botAssets,
setting: {
...botAssets.setting,
luis: {
authoringKey: '4d210acc6d794d71a2a3450*****2fb7',
endpointKey: '',
authoringRegion: 'westus',
} as ILuisConfig,
},
dialogs: [
{
luFile: 'a.lu',
Expand All @@ -143,7 +165,7 @@ describe('check LUIS & QnA key', () => {
],
};
const diagnostics = checkSetting(botAssets2);
expect(diagnostics.length).toEqual(1);
expect(diagnostics.length).toEqual(0);
});
});

Expand All @@ -159,7 +181,22 @@ describe('checkLUISLocales', () => {

describe('checkQnALocales', () => {
it('should check qna not supported locales', () => {
const diagnostics = checkQnALocales(botAssets);
const botAssets2 = {
...botAssets,
dialogs: [
{
luFile: 'a.lu',
qnaFile: 'a.lu.qna',
} as DialogInfo,
],
qnaFiles: [
{
id: 'a.en-us',
empty: false,
} as QnAFile,
],
};
const diagnostics = checkQnALocales(botAssets2);
const errors = diagnostics.filter((item) => item.severity === DiagnosticSeverity.Error);
const warnings = diagnostics.filter((item) => item.severity === DiagnosticSeverity.Warning);
expect(errors.length).toEqual(0);
Expand Down Expand Up @@ -224,7 +261,30 @@ describe('filterLUISFilesToPublish', () => {
});
describe('filterQnAFilesToPublish', () => {
it('should filter qnaFiles left QnA supported locale file', () => {
const qnaFilesToPublish = filterQnAFilesToPublish(botAssets.qnaFiles, botAssets.dialogs);
const botAssets2 = {
...botAssets,
dialogs: [
{
luFile: 'a.lu',
qnaFile: 'a.lu.qna',
} as DialogInfo,
],
qnaFiles: [
{
id: 'a.en-us',
empty: false,
} as QnAFile,
{
id: 'a.zh-cn',
empty: false,
} as QnAFile,
{
id: 'a.af',
empty: false,
} as QnAFile,
],
};
const qnaFilesToPublish = filterQnAFilesToPublish(botAssets2.qnaFiles);
expect(qnaFilesToPublish.length).toEqual(2);
expect(qnaFilesToPublish).not.toContain({
id: 'a.af',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { formDialogSchemaIndexer } from '../src/formDialogSchemaIndexer';
const files: FileInfo[] = [
{ name: 'file1.json', content: '', lastModified: '', relativePath: '', path: '' },
{ name: 'file2.dialog', content: '', lastModified: '', relativePath: '', path: '' },
{ name: 'file3.form-dialog', content: '', lastModified: '', relativePath: '', path: '' },
{ name: 'file3.form', content: '', lastModified: '', relativePath: '', path: '' },
{ name: 'file4.lu', content: '', lastModified: '', relativePath: '', path: '' },
{ name: 'file5.lg', content: '', lastModified: '', relativePath: '', path: '' },
{ name: 'file6.botproj', content: '', lastModified: '', relativePath: '', path: '' },
{ name: 'file7.qna', content: '', lastModified: '', relativePath: '', path: '' },
{ name: 'file8.form-dialog', content: '', lastModified: '', relativePath: '', path: '' },
{ name: 'file8.form', content: '', lastModified: '', relativePath: '', path: '' },
];

const expected = [
Expand Down
4 changes: 2 additions & 2 deletions Composer/packages/lib/indexers/__tests__/luIndexer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('parse', () => {
expect(intents[0].Children.length).toEqual(2);
expect(intents[0].Children[0].Name).toEqual('CheckUnreadTodo');
expect(intents[0].Children[0].Entities.length).toEqual(1);
expect(intents[0].Children[0].Entities[0]).toEqual('todoTitle');
expect(intents[0].Children[0].Entities[0].Name).toEqual('todoTitle');
});

it('should parse LU file with import', () => {
Expand Down Expand Up @@ -111,6 +111,6 @@ describe('index', () => {
expect(intents.length).toEqual(1);
expect(intents[0].Name).toEqual('Greeting');
expect(intents[0].Entities.length).toEqual(1);
expect(intents[0].Entities[0]).toEqual('friendsName');
expect(intents[0].Entities[0].Name).toEqual('friendsName');
});
});
6 changes: 3 additions & 3 deletions Composer/packages/lib/indexers/__tests__/luUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ describe('LU parse and validation', () => {
expect(result1.diagnostics.length).toEqual(1);
});

it('Throws when ML entity is disable (validateResource)', () => {
it('Throws when ML entity is disable (validateResource, not orchestrator)', () => {
const fileContent = `# AskForName
- {@userName=Jack}
`;
const result1 = parse('a.lu', fileContent, { enableMLEntities: false }, []);
const result1 = parse('a.lu', fileContent, { isOrchestartor: false, enableMLEntities: false }, []);
expect(result1.diagnostics.length).toEqual(1);

const result2 = parse('a.lu', fileContent, { enableMLEntities: true }, []);
const result2 = parse('a.lu', fileContent, { isOrchestartor: false, enableMLEntities: true }, []);
expect(result2.diagnostics.length).toEqual(0);
});

Expand Down
6 changes: 3 additions & 3 deletions Composer/packages/lib/indexers/src/botIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const checkLUISLocales = (assets: { dialogs: DialogInfo[]; setting: DialogSettin
setting: { languages },
} = assets;

// if use LUIS, continue
// if not using LUIS, continue
const useLUIS = dialogs.some((item) => !!item.luFile && item?.luProvider === SDKKinds.LuisRecognizer);
if (!useLUIS) return [];

Expand All @@ -147,15 +147,15 @@ const checkLUISLocales = (assets: { dialogs: DialogInfo[]; setting: DialogSettin

/**
* Check bot settings & dialog
* files meet QnA requirments.
* files meet QnA requirements.
*/
const checkQnALocales = (assets: { dialogs: DialogInfo[]; setting: DialogSetting }): Diagnostic[] => {
const {
dialogs,
setting: { languages },
} = assets;

// if use LUIS, continue
// if not using QnA, continue
const useQnA = dialogs.some((item) => !!item.qnaFile);
if (!useQnA) return [];

Expand Down

0 comments on commit 6227ded

Please sign in to comment.