From 0c822dd1ceba50364c22a10d882331119c97d8da Mon Sep 17 00:00:00 2001 From: Chenyi An Date: Fri, 11 Oct 2024 16:06:44 +0800 Subject: [PATCH] fix: ut --- packages/fx-core/resource/package.nls.json | 2 +- .../src/client/teamsDevPortalClient.ts | 14 ++++----- .../src/component/driver/teamsApp/errors.ts | 8 ++--- .../fx-core/tests/client/tdpClient.test.ts | 30 ++++++++++++------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/packages/fx-core/resource/package.nls.json b/packages/fx-core/resource/package.nls.json index e657f1c18a..f72660163e 100644 --- a/packages/fx-core/resource/package.nls.json +++ b/packages/fx-core/resource/package.nls.json @@ -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", diff --git a/packages/fx-core/src/client/teamsDevPortalClient.ts b/packages/fx-core/src/client/teamsDevPortalClient.ts index 6e8da62edb..4368e93567 100644 --- a/packages/fx-core/src/client/teamsDevPortalClient.ts +++ b/packages/fx-core/src/client/teamsDevPortalClient.ts @@ -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 ); } @@ -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 ); } @@ -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 ); } @@ -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 ); } @@ -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], @@ -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], @@ -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)}` : "" diff --git a/packages/fx-core/src/component/driver/teamsApp/errors.ts b/packages/fx-core/src/component/driver/teamsApp/errors.ts index 5659f403f9..ff782baf5f 100644 --- a/packages/fx-core/src/component/driver/teamsApp/errors.ts +++ b/packages/fx-core/src/component/driver/teamsApp/errors.ts @@ -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}` : ""), ], }; diff --git a/packages/fx-core/tests/client/tdpClient.test.ts b/packages/fx-core/tests/client/tdpClient.test.ts index e75217b24a..f995c8b7d8 100644 --- a/packages/fx-core/tests/client/tdpClient.test.ts +++ b/packages/fx-core/tests/client/tdpClient.test.ts @@ -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 () => { @@ -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) + ); } }); }); @@ -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)); } }); @@ -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) ); } }); @@ -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)); } }); @@ -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")); } }); }); @@ -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." + ) + ); } }); }); @@ -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")); } }); });