Skip to content

Commit

Permalink
fix: fix ut coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinGu07 committed Jun 20, 2024
1 parent ebf4371 commit 91c2e9e
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CancellationToken } from "../../../mocks/vsc";
import { officeSampleProvider } from "../../../../src/officeChat/commands/create/officeSamples";
import { ProjectMetadata } from "../../../../src/chat/commands/create/types";
import { core } from "../../../../src/globalVariables";
import { CreateProjectResult, ok } from "@microsoft/teamsfx-api";
import { CreateProjectResult, FxError, err, ok } from "@microsoft/teamsfx-api";

chai.use(chaiPromised);

Expand Down Expand Up @@ -231,14 +231,26 @@ describe("File: office chat create helper", () => {
sandbox.stub(fs, "ensureDir").resolves();
sandbox.stub(fs, "writeFile").resolves();
tempFolder = "testFolder";
sandbox.stub(core, "createProjectByCustomizedGenerator").resolves(ok(result));
});
afterEach(() => {
sandbox.restore();
});

it("fail to generate the project", async () => {
sandbox
.stub(core, "createProjectByCustomizedGenerator")
.resolves(err(undefined as any as FxError));
try {
await officeChathelper.buildTemplateFileTree({}, tempFolder, "test", "test");
chai.assert.fail("should not reach here");
} catch (error) {
chai.assert.strictEqual((error as Error).message, "Failed to generate the project.");
}
});

it("traverse the folder", async () => {
sandbox.stub(fs, "readFile").resolves(Buffer.from(""));
sandbox.stub(core, "createProjectByCustomizedGenerator").resolves(ok(result));
const data = {
capabilities: "test",
"project-type": "test",
Expand Down Expand Up @@ -279,6 +291,7 @@ describe("File: office chat create helper", () => {

it("fail to merge taskpane code snippet", async () => {
sandbox.stub(fs, "readFile").rejects(new Error("test"));
sandbox.stub(core, "createProjectByCustomizedGenerator").resolves(ok(result));
const data = {
capabilities: "test",
"project-type": "test",
Expand All @@ -302,6 +315,7 @@ describe("File: office chat create helper", () => {

it("fail to merge taskpane code snippet", async () => {
sandbox.stub(fs, "readFile").rejects(new Error("test"));
sandbox.stub(core, "createProjectByCustomizedGenerator").resolves(ok(result));
const data = {
capabilities: "excel-custom-functions-test",
"project-type": "test",
Expand Down

0 comments on commit 91c2e9e

Please sign in to comment.