Skip to content

Commit

Permalink
fix: update teams-app cli (#8499)
Browse files Browse the repository at this point in the history
* fix: update teams-app cli
  • Loading branch information
nliu-ms authored Apr 24, 2023
1 parent 388591c commit dfb53c1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
26 changes: 8 additions & 18 deletions packages/cli/src/cmds/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
TelemetryProperty,
TelemetrySuccess,
} from "../telemetry/cliTelemetryEvents";
import { getSystemInputs, askManifestFilePath, askTeamsManifestFilePath } from "../utils";
import { getSystemInputs } from "../utils";
import { YargsCommand } from "../yargsCommand";
import {
EnvOptions,
Expand All @@ -23,6 +23,7 @@ import {
} from "../constants";
import CLIUIInstance from "../userInteraction";
import { EnvNotSpecified } from "../error";
import { CoreQuestionNames } from "@microsoft/teamsfx-core/build/core/question";
export class UpdateAadApp extends YargsCommand {
public readonly commandHead = "aad-app";
public readonly command = this.commandHead;
Expand Down Expand Up @@ -100,24 +101,13 @@ export class UpdateTeamsApp extends YargsCommand {
const core = resultFolder.value;
const inputs = getSystemInputs(rootFolder, args.env);

let manifestTemplatePath;
if (args[TeamsAppManifestFilePathName]) {
manifestTemplatePath = args[TeamsAppManifestFilePathName];
} else {
const manifestTemplatePathRes = await askTeamsManifestFilePath();
if (manifestTemplatePathRes.isErr()) {
CliTelemetry.sendTelemetryErrorEvent(
TelemetryEvent.UpdateTeamsApp,
manifestTemplatePathRes.error
);
return err(manifestTemplatePathRes.error);
}
manifestTemplatePath = manifestTemplatePathRes.value;
}
if (!path.isAbsolute(manifestTemplatePath)) {
manifestTemplatePath = path.join(inputs.projectPath!, manifestTemplatePath);
inputs[CoreQuestionNames.TeamsAppManifestFilePath] = args[TeamsAppManifestFilePathName];
// Throw error if --env not specified
if (!args.env && !CLIUIInstance.interactive) {
const error = new EnvNotSpecified();
CliTelemetry.sendTelemetryErrorEvent(TelemetryEvent.UpdateAadApp, error);
return err(error);
}
inputs.manifestTemplatePath = manifestTemplatePath;

const result = await core.deployTeamsManifest(inputs);
if (result.isErr()) {
Expand Down
12 changes: 9 additions & 3 deletions packages/cli/src/cmds/validate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Result, FxError, err, AppPackageFolderName, ok, Func } from "@microsoft/teamsfx-api";
import { Result, FxError, err, ok, Func } from "@microsoft/teamsfx-api";
import { environmentManager, isV3Enabled } from "@microsoft/teamsfx-core";
import { CoreQuestionNames } from "@microsoft/teamsfx-core/build/core/question";
import path from "path";
import { Argv } from "yargs";
import activate from "../activate";
Expand All @@ -12,7 +11,6 @@ import {
EnvOptions,
ValidateApplicationOptions,
AppPackageFilePathParamName,
ManifestFilePathParamName,
} from "../constants";
import CliTelemetry, { makeEnvRelatedProperty } from "../telemetry/cliTelemetry";
import {
Expand All @@ -22,6 +20,8 @@ import {
} from "../telemetry/cliTelemetryEvents";
import { getSystemInputs } from "../utils";
import { YargsCommand } from "../yargsCommand";
import CLIUIInstance from "../userInteraction";
import { EnvNotSpecified } from "../error";

export class ManifestValidate extends YargsCommand {
public readonly commandHead = `validate`;
Expand Down Expand Up @@ -56,6 +56,12 @@ export class ManifestValidate extends YargsCommand {
inputs.validateMethod = "validateAgainstAppPackage";
} else {
inputs.validateMethod = "validateAgainstSchema";
// Throw error if --env not specified
if (!args.env && !CLIUIInstance.interactive) {
const error = new EnvNotSpecified();
CliTelemetry.sendTelemetryErrorEvent(TelemetryEvent.UpdateAadApp, error);
return err(error);
}
}
result = await core.validateApplication(inputs);
} else {
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/tests/unit/cmds/update.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,19 @@ describe("Update Teams app manifest Command Tests", function () {
expect(e.message).equals("Fake_Err_msg");
}
});

it("Update Teams app - Run command failed without env", async () => {
sandbox.stub(FxCore.prototype, "deployTeamsManifest").resolves(ok(""));
const cmd = new Update();
const updateTeamsAppManifest = cmd.subCommands.find((cmd) => cmd.commandHead === "teams-app");
const args = {
folder: "fake_test",
"manifest-file-path": "./appPackage/manifest.json",
};
const res = await updateTeamsAppManifest!.runCommand(args);
expect(res.isErr()).to.be.true;
if (res.isErr()) {
expect(res.error.message).equal("The --env argument is not specified");
}
});
});
19 changes: 19 additions & 0 deletions packages/cli/tests/unit/cmds/validate.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { NotSupportedProjectType } from "../../../src/error";
import mockedEnv, { RestoreFn } from "mocked-env";
import { VersionCheckRes } from "@microsoft/teamsfx-core/build/core/types";
import { VersionState } from "@microsoft/teamsfx-core/build/common/versionMetadata";
import CLIUIInstance from "../../../src/userInteraction";

describe("teamsfx validate", () => {
const sandbox = sinon.createSandbox();
Expand Down Expand Up @@ -120,6 +121,7 @@ describe("teamsfx validate", () => {
const cmd = new ManifestValidate();
const args = {
[constants.ManifestFilePathParamName]: "./manifest.json",
env: "dev",
};
await cmd.handler(args);
expect(telemetryEvents).deep.equals([
Expand All @@ -129,6 +131,23 @@ describe("teamsfx validate", () => {
expect(telemetryEventStatus).equals(TelemetrySuccess.Yes);
});

it("Validate Command Running Check - Run command failed without env", async () => {
mockedEnvRestore = mockedEnv({
TEAMSFX_V3: "true",
});
sandbox.stub(FxCore.prototype, "validateApplication").resolves(ok(new Map()));
const cmd = new ManifestValidate();
const args = {
[constants.ManifestFilePathParamName]: "./manifest.json",
};
CLIUIInstance.interactive = false;
const res = await cmd.runCommand(args);
expect(res.isErr()).to.be.true;
if (res.isErr()) {
expect(res.error.message).equal("The --env argument is not specified");
}
});

it("Validate Command Running Check", async () => {
mockedEnvRestore = mockedEnv({
TEAMSFX_V3: "false",
Expand Down

0 comments on commit dfb53c1

Please sign in to comment.