From 6227ded3c05ffa1a668413a2366823f15df89be0 Mon Sep 17 00:00:00 2001 From: Soroush Date: Mon, 12 Jul 2021 21:11:24 -0700 Subject: [PATCH] Adds indexers unit test back and fixes them (#8360) Co-authored-by: Soroush --- Composer/jest.config.js | 1 + .../lib/indexers/__tests__/botIndexer.test.ts | 78 ++++++++++++++++--- .../__tests__/formDialogSchemaIndexer.test.ts | 4 +- .../lib/indexers/__tests__/luIndexer.test.ts | 4 +- .../lib/indexers/__tests__/luUtil.test.ts | 6 +- .../packages/lib/indexers/src/botIndexer.ts | 6 +- 6 files changed, 80 insertions(+), 19 deletions(-) diff --git a/Composer/jest.config.js b/Composer/jest.config.js index b9b038bf84..539cd8b8fa 100644 --- a/Composer/jest.config.js +++ b/Composer/jest.config.js @@ -45,6 +45,7 @@ module.exports = { '/packages/intellisense', '/packages/lib/code-editor', '/packages/lib/shared', + '/packages/lib/indexers', '/packages/lib/ui-shared', '/packages/server', '/packages/electron-server', diff --git a/Composer/packages/lib/indexers/__tests__/botIndexer.test.ts b/Composer/packages/lib/indexers/__tests__/botIndexer.test.ts index b46ae86a38..7f6732e18c 100644 --- a/Composer/packages/lib/indexers/__tests__/botIndexer.test.ts +++ b/Composer/packages/lib/indexers/__tests__/botIndexer.test.ts @@ -73,6 +73,8 @@ const botAssets: BotAssets = { setting: { languages: ['en-us', 'zh-cn', 'af'], defaultLanguage: 'en-us', + customFunctions: [], + importedLibraries: [], botId: '', skillHostEndpoint: '', skill: { @@ -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); @@ -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', @@ -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', @@ -143,7 +165,7 @@ describe('check LUIS & QnA key', () => { ], }; const diagnostics = checkSetting(botAssets2); - expect(diagnostics.length).toEqual(1); + expect(diagnostics.length).toEqual(0); }); }); @@ -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); @@ -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', diff --git a/Composer/packages/lib/indexers/__tests__/formDialogSchemaIndexer.test.ts b/Composer/packages/lib/indexers/__tests__/formDialogSchemaIndexer.test.ts index d5182a7e2b..6d003abbb9 100644 --- a/Composer/packages/lib/indexers/__tests__/formDialogSchemaIndexer.test.ts +++ b/Composer/packages/lib/indexers/__tests__/formDialogSchemaIndexer.test.ts @@ -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 = [ diff --git a/Composer/packages/lib/indexers/__tests__/luIndexer.test.ts b/Composer/packages/lib/indexers/__tests__/luIndexer.test.ts index da10dc5595..48268c1dd3 100644 --- a/Composer/packages/lib/indexers/__tests__/luIndexer.test.ts +++ b/Composer/packages/lib/indexers/__tests__/luIndexer.test.ts @@ -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', () => { @@ -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'); }); }); diff --git a/Composer/packages/lib/indexers/__tests__/luUtil.test.ts b/Composer/packages/lib/indexers/__tests__/luUtil.test.ts index 4caf2fb24c..aa1a2e39dd 100644 --- a/Composer/packages/lib/indexers/__tests__/luUtil.test.ts +++ b/Composer/packages/lib/indexers/__tests__/luUtil.test.ts @@ -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); }); diff --git a/Composer/packages/lib/indexers/src/botIndexer.ts b/Composer/packages/lib/indexers/src/botIndexer.ts index 86c30f8a05..e7b4730594 100644 --- a/Composer/packages/lib/indexers/src/botIndexer.ts +++ b/Composer/packages/lib/indexers/src/botIndexer.ts @@ -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 []; @@ -147,7 +147,7 @@ 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 { @@ -155,7 +155,7 @@ const checkQnALocales = (assets: { dialogs: DialogInfo[]; setting: DialogSetting setting: { languages }, } = assets; - // if use LUIS, continue + // if not using QnA, continue const useQnA = dialogs.some((item) => !!item.qnaFile); if (!useQnA) return [];