Skip to content

Commit

Permalink
fix: ut
Browse files Browse the repository at this point in the history
  • Loading branch information
anchenyi committed Sep 27, 2024
1 parent c966259 commit b086d08
Showing 1 changed file with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -522,6 +554,7 @@ describe("teamsApp/createAppPackage", async () => {
file: "resources/de.json",
},
],
defaultLanguageFile: "resources/de.json",
};
sinon.stub(manifestUtils, "getManifestV3").resolves(ok(manifest));

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b086d08

Please sign in to comment.