Skip to content

Commit

Permalink
fix: ut
Browse files Browse the repository at this point in the history
  • Loading branch information
anchenyi committed Oct 11, 2024
1 parent 67e4909 commit 0c822dd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/fx-core/resource/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"plugins.appstudio.previewOnly": "Preview only",
"plugins.appstudio.previewAndUpdate": "Preview and update",
"plugins.appstudio.overwriteAndUpdate": "Overwrite and update",
"plugins.appstudio.emptyAppPackage": "Unable to find any files in the app %s package.",
"plugins.appstudio.emptyAppPackage": "unable to find any files in the app %s package.",
"plugins.appstudio.unprocessedFile": "Teams Toolkit did not process %s.",
"plugins.appstudio.viewDeveloperPortal": "View in Developer Portal",
"plugins.bot.questionHostTypeTrigger.title": "Select triggers",
Expand Down
14 changes: 7 additions & 7 deletions packages/fx-core/src/client/teamsDevPortalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class TeamsDevPortalClient {
return app;
} else {
throw this.wrapException(
new Exception("Cannot create teams app"),
new Exception("cannot create teams app"),
APP_STUDIO_API_NAMES.CREATE_APP
);
}
Expand Down Expand Up @@ -228,7 +228,7 @@ export class TeamsDevPortalClient {
throw this.wrapException(e, APP_STUDIO_API_NAMES.LIST_APPS);
}
throw this.wrapException(
new Exception("Cannot get the app definitions"),
new Exception("cannot get the app definitions"),
APP_STUDIO_API_NAMES.LIST_APPS
);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ export class TeamsDevPortalClient {
throw this.wrapException(e, APP_STUDIO_API_NAMES.DELETE_APP);
}
throw this.wrapException(
new Exception("Cannot delete the app: " + teamsAppId),
new Exception("cannot delete the app: " + teamsAppId),
APP_STUDIO_API_NAMES.DELETE_APP
);
}
Expand Down Expand Up @@ -285,7 +285,7 @@ export class TeamsDevPortalClient {
throw this.wrapException(e, APP_STUDIO_API_NAMES.GET_APP);
}
throw this.wrapException(
new Exception(`Cannot get the app definition with app ID ${teamsAppId}`),
new Exception(`cannot get the app definition with app ID ${teamsAppId}`),
APP_STUDIO_API_NAMES.GET_APP
);
}
Expand Down Expand Up @@ -398,7 +398,7 @@ export class TeamsDevPortalClient {
}
} else {
throw this.wrapException(
new Exception("Empty response"),
new Exception("empty response"),
APP_STUDIO_API_NAMES.PUBLISH_APP,
AppStudioError.TeamsAppPublishFailedError.name,
AppStudioError.TeamsAppPublishFailedError.message(teamsAppId, "POST /api/publishing")[0],
Expand Down Expand Up @@ -463,7 +463,7 @@ export class TeamsDevPortalClient {
}
} else {
throw this.wrapException(
new Exception("Empty response"),
new Exception("empty response"),
APP_STUDIO_API_NAMES.PUBLISH_APP,
AppStudioError.TeamsAppPublishFailedError.name,
AppStudioError.TeamsAppPublishFailedError.message(teamsAppId, requestPath)[0],
Expand Down Expand Up @@ -978,7 +978,7 @@ export class TeamsDevPortalClient {
disPlayMessage?: string
): Error {
e.name = name;
const correlationId = e.response?.headers[Constants.CORRELATION_ID];
const correlationId = e.response?.headers?.[Constants.CORRELATION_ID];
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
const extraData = `${potentialReason} ${
e.response?.data ? `data: ${JSON.stringify(e.response.data)}` : ""
Expand Down
8 changes: 4 additions & 4 deletions packages/fx-core/src/component/driver/teamsApp/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ export class AppStudioError {
correlationId?: string
): [string, string] => [
getDefaultString("error.appstudio.publishFailed", teamsAppId) +
`Request path: ${requestPath}` +
(correlationId ? `X-Correlation-ID: ${correlationId}` : ""),
` Request path: ${requestPath}` +
(correlationId ? ` X-Correlation-ID: ${correlationId}` : ""),
getLocalizedString("error.appstudio.publishFailed", teamsAppId) +
`Request path: ${requestPath}` +
(correlationId ? `X-Correlation-ID: ${correlationId}` : ""),
` Request path: ${requestPath}` +
(correlationId ? ` X-Correlation-ID: ${correlationId}` : ""),
],
};

Expand Down
30 changes: 20 additions & 10 deletions packages/fx-core/tests/client/tdpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ describe("TeamsDevPortalClient Test", () => {
try {
await teamsDevPortalClient.publishTeamsApp(token, "fakeId", Buffer.from(""));
} catch (e) {
chai.assert.equal(e.name, AppStudioError.TeamsAppPublishFailedError.name);
chai.assert.equal(e.name, DeveloperPortalAPIFailedError.name);
chai.assert.isTrue(e.message.includes(AppStudioError.TeamsAppPublishFailedError.name));
}
});
it("API Failure", async () => {
Expand Down Expand Up @@ -293,7 +294,10 @@ describe("TeamsDevPortalClient Test", () => {
try {
await teamsDevPortalClient.publishTeamsApp(token, "fakeId", Buffer.from(""));
} catch (error) {
chai.assert.equal(error.name, AppStudioError.TeamsAppPublishConflictError.name);
chai.assert.equal(error.name, DeveloperPortalAPIFailedError.name);
chai.assert.isTrue(
error.message.includes(AppStudioError.TeamsAppPublishConflictError.name)
);
}
});
});
Expand Down Expand Up @@ -341,7 +345,8 @@ describe("TeamsDevPortalClient Test", () => {
try {
await teamsDevPortalClient.importApp(token, Buffer.from(""));
} catch (error) {
chai.assert.equal(error.name, AppStudioError.TeamsAppCreateConflictError.name);
chai.assert.equal(error.name, DeveloperPortalAPIFailedError.name);
chai.assert.isTrue(error.message.includes(AppStudioError.TeamsAppCreateConflictError.name));
}
});

Expand All @@ -360,9 +365,9 @@ describe("TeamsDevPortalClient Test", () => {
try {
await teamsDevPortalClient.importApp(token, Buffer.from(""));
} catch (error) {
chai.assert.equal(
error.name,
AppStudioError.TeamsAppCreateConflictWithPublishedAppError.name
chai.assert.equal(error.name, DeveloperPortalAPIFailedError.name);
chai.assert.isTrue(
error.message.includes(AppStudioError.TeamsAppCreateConflictWithPublishedAppError.name)
);
}
});
Expand Down Expand Up @@ -407,7 +412,8 @@ describe("TeamsDevPortalClient Test", () => {
try {
await teamsDevPortalClient.importApp(token, Buffer.from(""));
} catch (error) {
chai.assert.equal(error.name, AppStudioError.InvalidTeamsAppIdError.name);
chai.assert.equal(error.name, DeveloperPortalAPIFailedError.name);
chai.assert.isTrue(error.message.includes(AppStudioError.InvalidTeamsAppIdError.name));
}
});

Expand Down Expand Up @@ -545,7 +551,7 @@ describe("TeamsDevPortalClient Test", () => {
try {
await teamsDevPortalClient.getApp(token, "anotherId");
} catch (e) {
chai.assert.isTrue(e.message.includes("Cannot get the app definition with app ID"));
chai.assert.isTrue(e.message.includes("cannot get the app definition with app ID"));
}
});
});
Expand Down Expand Up @@ -1277,7 +1283,11 @@ describe("TeamsDevPortalClient Test", () => {
await teamsDevPortalClient.listApps(token);
chai.assert.fail("should throw error");
} catch (e) {
chai.assert.equal(e.message, "Cannot get the app definitions");
chai.assert.isTrue(
e.message.includes(
"Unable to make API call to Developer Portal: API failed, cannot get the app definitions, API name: list-app, X-Correlation-ID: undefined. This may be due to a temporary service error. Try again after a few minutes."
)
);
}
});
});
Expand Down Expand Up @@ -1335,7 +1345,7 @@ describe("TeamsDevPortalClient Test", () => {
await teamsDevPortalClient.deleteApp(token, "testid");
chai.assert.fail("should throw error");
} catch (e) {
chai.assert.equal(e.message, "Cannot delete the app: " + "testid");
chai.assert.isTrue(e.message.includes("cannot delete the app: " + "testid"));
}
});
});
Expand Down

0 comments on commit 0c822dd

Please sign in to comment.