From b086d086c8a522802945a2550b9d92d3ae64f40f Mon Sep 17 00:00:00 2001 From: Chenyi An Date: Fri, 27 Sep 2024 11:11:56 +0800 Subject: [PATCH] fix: ut --- .../driver/teamsApp/createAppPackage.test.ts | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/packages/fx-core/tests/component/driver/teamsApp/createAppPackage.test.ts b/packages/fx-core/tests/component/driver/teamsApp/createAppPackage.test.ts index 652d0d8688..813bcae48a 100644 --- a/packages/fx-core/tests/component/driver/teamsApp/createAppPackage.test.ts +++ b/packages/fx-core/tests/component/driver/teamsApp/createAppPackage.test.ts @@ -192,6 +192,38 @@ describe("teamsApp/createAppPackage", async () => { } }); + it("should throw error if file not exists case 6", async () => { + const args: CreateAppPackageArgs = { + manifestPath: + "./tests/plugins/resource/appstudio/resources-multi-env/templates/appPackage/v3.manifest.template.json", + outputZipPath: + "./tests/plugins/resource/appstudio/resources-multi-env/build/appPackage/appPackage.dev.zip", + outputJsonPath: + "./tests/plugins/resource/appstudio/resources-multi-env/build/appPackage/manifest.dev.json", + }; + sinon.stub(fs, "pathExists").callsFake((filePath) => { + if (filePath.includes("fake.json")) { + return false; + } else { + return true; + } + }); + + const manifest = new TeamsAppManifest(); + manifest.localizationInfo = { + additionalLanguages: [{ file: "aaa", languageTag: "zh" }], + defaultLanguageTag: "en", + defaultLanguageFile: "fake.json", + }; + sinon.stub(manifestUtils, "getManifestV3").resolves(ok(manifest)); + + const result = (await teamsAppDriver.execute(args, mockedDriverContext)).result; + chai.assert(result.isErr()); + if (result.isErr()) { + chai.assert.isTrue(result.error instanceof FileNotFoundError); + } + }); + describe("api plugin error case", async () => { it("should throw error if pluginFile not exists for API plugin", async () => { const args: CreateAppPackageArgs = { @@ -522,6 +554,7 @@ describe("teamsApp/createAppPackage", async () => { file: "resources/de.json", }, ], + defaultLanguageFile: "resources/de.json", }; sinon.stub(manifestUtils, "getManifestV3").resolves(ok(manifest)); @@ -893,6 +926,69 @@ describe("teamsApp/createAppPackage", async () => { } }); + it("version > 1.6: happy path - API plugin", async () => { + const args: CreateAppPackageArgs = { + manifestPath: + "./tests/plugins/resource/appstudio/resources-multi-env/templates/appPackage/v3.manifest.template.json", + outputZipPath: + "./tests/plugins/resource/appstudio/resources-multi-env/build/appPackage/appPackage.dev.zip", + outputFolder: "./tests/plugins/resource/appstudio/resources-multi-env/build/appPackage", + }; + + const manifest = new TeamsAppManifest(); + manifest.copilotExtensions = { + plugins: [ + { + file: "resources/ai-plugin.json", + id: "plugin1", + }, + ], + }; + manifest.icons = { + color: "resources/color.png", + outline: "resources/outline.png", + }; + sinon.stub(manifestUtils, "getManifestV3").resolves(ok(manifest)); + sinon.stub(fs, "chmod").callsFake(async () => {}); + const writeFileStub = sinon.stub(fs, "writeFile").callsFake(async () => {}); + + const result = (await teamsAppDriver.execute(args, mockedDriverContext)).result; + if (result.isErr()) { + console.log(result.error); + } + chai.assert.isTrue(result.isOk()); + const outputExist = await fs.pathExists(args.outputZipPath); + chai.assert.isTrue(outputExist); + chai.assert.isTrue(writeFileStub.calledTwice); + if (outputExist) { + const zip = new AdmZip(args.outputZipPath); + let aiPluginContent = ""; + let openapiContent = ""; + + const entries = zip.getEntries(); + entries.forEach((e) => { + const name = e.entryName; + if (name.endsWith("ai-plugin.json")) { + const data = e.getData(); + aiPluginContent = data.toString("utf8"); + } + + if (name.endsWith("openai.yml")) { + const data = e.getData(); + openapiContent = data.toString("utf8"); + } + }); + + chai.assert( + openapiContent && + aiPluginContent && + openapiContent.search("APP_NAME_SUFFIX") < 0 && + aiPluginContent.search(openapiServerPlaceholder) < 0 + ); + await fs.remove(args.outputZipPath); + } + }); + it("invalid color file", async () => { const args: CreateAppPackageArgs = { manifestPath: