From eef83c7c57d211dac2836979e4af05826a3ff297 Mon Sep 17 00:00:00 2001 From: Yuqi Zhou Date: Fri, 15 Sep 2023 17:06:50 +0800 Subject: [PATCH 1/3] fix: update response templates folder name refactor: more test: ut --- packages/api/review/teamsfx-api.api.md | 6 +++--- packages/api/src/constants.ts | 2 +- .../src/component/generator/copilotPlugin/generator.ts | 4 ++-- packages/fx-core/src/core/FxCore.ts | 4 ++-- .../component/generator/copilotPluginGenerator.test.ts | 4 +++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/api/review/teamsfx-api.api.md b/packages/api/review/teamsfx-api.api.md index cf7989709d..4fbd9583e9 100644 --- a/packages/api/review/teamsfx-api.api.md +++ b/packages/api/review/teamsfx-api.api.md @@ -12,9 +12,6 @@ import { IWebApplicationInfo } from '@microsoft/teams-manifest'; import { Result } from 'neverthrow'; import { TokenCredential } from '@azure/core-auth'; -// @public (undocumented) -export const AdaptiveFolderName = "adaptiveCards"; - // @public (undocumented) export interface ApiOperation { // (undocumented) @@ -612,6 +609,9 @@ export const ProductName = "teamsfx"; // @public (undocumented) export type Question = SingleSelectQuestion | MultiSelectQuestion | TextInputQuestion | SingleFileQuestion | MultiFileQuestion | FolderQuestion | SingleFileQuestion | SingleFileOrInputQuestion; +// @public (undocumented) +export const ResponseTemplatesFolderName = "responseTemplates"; + // @public export type SelectFileConfig = UIConfig & { filters?: { diff --git a/packages/api/src/constants.ts b/packages/api/src/constants.ts index 75cae79837..696b0cc68b 100644 --- a/packages/api/src/constants.ts +++ b/packages/api/src/constants.ts @@ -5,7 +5,7 @@ export const ConfigFolderName = "fx"; export const AppPackageFolderName = "appPackage"; export const BuildFolderName = "build"; -export const AdaptiveFolderName = "adaptiveCards"; +export const ResponseTemplatesFolderName = "responseTemplates"; export const TemplateFolderName = "templates"; export const ProductName = "teamsfx"; export const AutoGeneratedReadme = "README-auto-generated.md"; diff --git a/packages/fx-core/src/component/generator/copilotPlugin/generator.ts b/packages/fx-core/src/component/generator/copilotPlugin/generator.ts index 7db2400169..ea10c8921f 100644 --- a/packages/fx-core/src/component/generator/copilotPlugin/generator.ts +++ b/packages/fx-core/src/component/generator/copilotPlugin/generator.ts @@ -16,7 +16,7 @@ import { Platform, Result, UserError, - AdaptiveFolderName, + ResponseTemplatesFolderName, AppPackageFolderName, Warning, } from "@microsoft/teamsfx-api"; @@ -202,7 +202,7 @@ export class CopilotPluginGenerator { const adaptiveCardFolder = path.join( destinationPath, AppPackageFolderName, - AdaptiveFolderName + ResponseTemplatesFolderName ); const generateResult = await specParser.generate( manifestPath, diff --git a/packages/fx-core/src/core/FxCore.ts b/packages/fx-core/src/core/FxCore.ts index 2d8ed40d6c..602acd169d 100644 --- a/packages/fx-core/src/core/FxCore.ts +++ b/packages/fx-core/src/core/FxCore.ts @@ -3,7 +3,7 @@ import { hooks } from "@feathersjs/hooks"; import { - AdaptiveFolderName, + ResponseTemplatesFolderName, ApiOperation, AppPackageFolderName, BuildFolderName, @@ -1120,7 +1120,7 @@ export class FxCore { const adaptiveCardFolder = path.join( inputs.projectPath!, AppPackageFolderName, - AdaptiveFolderName + ResponseTemplatesFolderName ); const context = createContextV3(); diff --git a/packages/fx-core/tests/component/generator/copilotPluginGenerator.test.ts b/packages/fx-core/tests/component/generator/copilotPluginGenerator.test.ts index 0df4bc2c11..b57569f92f 100644 --- a/packages/fx-core/tests/component/generator/copilotPluginGenerator.test.ts +++ b/packages/fx-core/tests/component/generator/copilotPluginGenerator.test.ts @@ -12,6 +12,7 @@ import { ok, OpenAIManifestAuthType, Platform, + ResponseTemplatesFolderName, SystemError, TeamsAppManifest, } from "@microsoft/teamsfx-api"; @@ -147,7 +148,7 @@ describe("copilotPluginGenerator", function () { sandbox.stub(fs, "ensureDir").resolves(); sandbox.stub(manifestUtils, "_readAppManifest").resolves(ok({ ...teamsManifest })); sandbox.stub(specParserUtils, "isYamlSpecFile").resolves(false); - sandbox.stub(SpecParser.prototype, "generate").resolves({ + const generateParser = sandbox.stub(SpecParser.prototype, "generate").resolves({ allSuccess: true, warnings: [ { type: WarningType.GenerateCardFailed, content: "test", data: "getPets" }, @@ -168,6 +169,7 @@ describe("copilotPluginGenerator", function () { assert.equal(result.value.warnings![2].type, WarningType.GenerateCardFailed); assert.equal(result.value.warnings![3].type, WarningType.OperationOnlyContainsOptionalParam); assert.equal(result.value.warnings![3].content, ""); + assert.isTrue(generateParser.args[0][3].includes(ResponseTemplatesFolderName)); } }); From 17c45ab72b08d893426644d86748817caf98d4cb Mon Sep 17 00:00:00 2001 From: Yuqi Zhou Date: Fri, 15 Sep 2023 17:06:50 +0800 Subject: [PATCH 2/3] fix: update response templates folder name refactor: more test: ut --- packages/api/review/teamsfx-api.api.md | 6 +++--- packages/api/src/constants.ts | 2 +- .../src/component/generator/copilotPlugin/generator.ts | 4 ++-- packages/fx-core/src/core/FxCore.ts | 4 ++-- .../component/generator/copilotPluginGenerator.test.ts | 4 +++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/api/review/teamsfx-api.api.md b/packages/api/review/teamsfx-api.api.md index cf7989709d..4fbd9583e9 100644 --- a/packages/api/review/teamsfx-api.api.md +++ b/packages/api/review/teamsfx-api.api.md @@ -12,9 +12,6 @@ import { IWebApplicationInfo } from '@microsoft/teams-manifest'; import { Result } from 'neverthrow'; import { TokenCredential } from '@azure/core-auth'; -// @public (undocumented) -export const AdaptiveFolderName = "adaptiveCards"; - // @public (undocumented) export interface ApiOperation { // (undocumented) @@ -612,6 +609,9 @@ export const ProductName = "teamsfx"; // @public (undocumented) export type Question = SingleSelectQuestion | MultiSelectQuestion | TextInputQuestion | SingleFileQuestion | MultiFileQuestion | FolderQuestion | SingleFileQuestion | SingleFileOrInputQuestion; +// @public (undocumented) +export const ResponseTemplatesFolderName = "responseTemplates"; + // @public export type SelectFileConfig = UIConfig & { filters?: { diff --git a/packages/api/src/constants.ts b/packages/api/src/constants.ts index 75cae79837..696b0cc68b 100644 --- a/packages/api/src/constants.ts +++ b/packages/api/src/constants.ts @@ -5,7 +5,7 @@ export const ConfigFolderName = "fx"; export const AppPackageFolderName = "appPackage"; export const BuildFolderName = "build"; -export const AdaptiveFolderName = "adaptiveCards"; +export const ResponseTemplatesFolderName = "responseTemplates"; export const TemplateFolderName = "templates"; export const ProductName = "teamsfx"; export const AutoGeneratedReadme = "README-auto-generated.md"; diff --git a/packages/fx-core/src/component/generator/copilotPlugin/generator.ts b/packages/fx-core/src/component/generator/copilotPlugin/generator.ts index 7db2400169..ea10c8921f 100644 --- a/packages/fx-core/src/component/generator/copilotPlugin/generator.ts +++ b/packages/fx-core/src/component/generator/copilotPlugin/generator.ts @@ -16,7 +16,7 @@ import { Platform, Result, UserError, - AdaptiveFolderName, + ResponseTemplatesFolderName, AppPackageFolderName, Warning, } from "@microsoft/teamsfx-api"; @@ -202,7 +202,7 @@ export class CopilotPluginGenerator { const adaptiveCardFolder = path.join( destinationPath, AppPackageFolderName, - AdaptiveFolderName + ResponseTemplatesFolderName ); const generateResult = await specParser.generate( manifestPath, diff --git a/packages/fx-core/src/core/FxCore.ts b/packages/fx-core/src/core/FxCore.ts index 2d8ed40d6c..602acd169d 100644 --- a/packages/fx-core/src/core/FxCore.ts +++ b/packages/fx-core/src/core/FxCore.ts @@ -3,7 +3,7 @@ import { hooks } from "@feathersjs/hooks"; import { - AdaptiveFolderName, + ResponseTemplatesFolderName, ApiOperation, AppPackageFolderName, BuildFolderName, @@ -1120,7 +1120,7 @@ export class FxCore { const adaptiveCardFolder = path.join( inputs.projectPath!, AppPackageFolderName, - AdaptiveFolderName + ResponseTemplatesFolderName ); const context = createContextV3(); diff --git a/packages/fx-core/tests/component/generator/copilotPluginGenerator.test.ts b/packages/fx-core/tests/component/generator/copilotPluginGenerator.test.ts index 0df4bc2c11..b57569f92f 100644 --- a/packages/fx-core/tests/component/generator/copilotPluginGenerator.test.ts +++ b/packages/fx-core/tests/component/generator/copilotPluginGenerator.test.ts @@ -12,6 +12,7 @@ import { ok, OpenAIManifestAuthType, Platform, + ResponseTemplatesFolderName, SystemError, TeamsAppManifest, } from "@microsoft/teamsfx-api"; @@ -147,7 +148,7 @@ describe("copilotPluginGenerator", function () { sandbox.stub(fs, "ensureDir").resolves(); sandbox.stub(manifestUtils, "_readAppManifest").resolves(ok({ ...teamsManifest })); sandbox.stub(specParserUtils, "isYamlSpecFile").resolves(false); - sandbox.stub(SpecParser.prototype, "generate").resolves({ + const generateParser = sandbox.stub(SpecParser.prototype, "generate").resolves({ allSuccess: true, warnings: [ { type: WarningType.GenerateCardFailed, content: "test", data: "getPets" }, @@ -168,6 +169,7 @@ describe("copilotPluginGenerator", function () { assert.equal(result.value.warnings![2].type, WarningType.GenerateCardFailed); assert.equal(result.value.warnings![3].type, WarningType.OperationOnlyContainsOptionalParam); assert.equal(result.value.warnings![3].content, ""); + assert.isTrue(generateParser.args[0][3].includes(ResponseTemplatesFolderName)); } }); From 40a13d6535fa6bd5ee26dcc89ca13b0c1d9b23eb Mon Sep 17 00:00:00 2001 From: Yuqi Zhou Date: Mon, 18 Sep 2023 13:40:29 +0800 Subject: [PATCH 3/3] build: ignore const --- packages/api/.nycrc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/api/.nycrc b/packages/api/.nycrc index 1a1c7b320f..d4b6b6f3cd 100644 --- a/packages/api/.nycrc +++ b/packages/api/.nycrc @@ -4,5 +4,8 @@ "include": ["src/**/*.ts", "src/**/*.js"], "reporter": ["text", "html", "cobertura", "lcov"], "check-coverage": true, + "exclude": [ + "src/constants.ts" + ], "lines": 75 -} +} \ No newline at end of file