From ce5377d729adfb17fd01fe27f4f29494322148bc Mon Sep 17 00:00:00 2001 From: wangsijie Date: Mon, 15 May 2023 10:25:02 +0800 Subject: [PATCH] test(core): add integration test for application isAdmin (#3829) --- packages/core/src/routes/application.ts | 4 +++- .../integration-tests/src/api/application.ts | 4 ++-- .../src/tests/api/application.test.ts | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/core/src/routes/application.ts b/packages/core/src/routes/application.ts index 12f5f8ece..fc709732d 100644 --- a/packages/core/src/routes/application.ts +++ b/packages/core/src/routes/application.ts @@ -161,7 +161,9 @@ export default function applicationRoutes( } } - ctx.body = await updateApplicationById(id, rest); + ctx.body = await (Object.keys(rest).length > 0 + ? updateApplicationById(id, rest) + : findApplicationById(id)); return next(); } diff --git a/packages/integration-tests/src/api/application.ts b/packages/integration-tests/src/api/application.ts index 2219a89d7..946706dc5 100644 --- a/packages/integration-tests/src/api/application.ts +++ b/packages/integration-tests/src/api/application.ts @@ -20,7 +20,7 @@ export const createApplication = async (name: string, type: ApplicationType) => export const getApplications = async () => authedAdminApi.get('applications').json(); export const getApplication = async (applicationId: string) => - authedAdminApi.get(`applications/${applicationId}`).json(); + authedAdminApi.get(`applications/${applicationId}`).json(); export const updateApplication = async ( applicationId: string, @@ -28,7 +28,7 @@ export const updateApplication = async ( Omit & { oidcClientMetadata: Partial; } - > + > & { isAdmin?: boolean } ) => authedAdminApi .patch(`applications/${applicationId}`, { diff --git a/packages/integration-tests/src/tests/api/application.test.ts b/packages/integration-tests/src/tests/api/application.test.ts index 84f51eaac..adb248353 100644 --- a/packages/integration-tests/src/tests/api/application.test.ts +++ b/packages/integration-tests/src/tests/api/application.test.ts @@ -46,6 +46,24 @@ describe('admin console application', () => { expect(updatedApplication.oidcClientMetadata.redirectUris).toEqual(newRedirectUris); }); + it('should update application "admin" successfully', async () => { + const application = await createApplication( + 'test-update-is-admin', + ApplicationType.MachineToMachine + ); + await updateApplication(application.id, { + isAdmin: true, + }); + const updatedApplication = await getApplication(application.id); + expect(updatedApplication.isAdmin).toBeTruthy(); + + await updateApplication(application.id, { + isAdmin: false, + }); + const updatedAgainApplication = await getApplication(application.id); + expect(updatedAgainApplication.isAdmin).toBeFalsy(); + }); + it('should fetch all applications created above', async () => { const applications = await getApplications(); const applicationNames = applications.map(({ name }) => name);