mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
test(core): add integration test for application isAdmin (#3829)
This commit is contained in:
parent
fd6ab3874b
commit
ce5377d729
3 changed files with 23 additions and 3 deletions
|
@ -161,7 +161,9 @@ export default function applicationRoutes<T extends AuthedRouter>(
|
|||
}
|
||||
}
|
||||
|
||||
ctx.body = await updateApplicationById(id, rest);
|
||||
ctx.body = await (Object.keys(rest).length > 0
|
||||
? updateApplicationById(id, rest)
|
||||
: findApplicationById(id));
|
||||
|
||||
return next();
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ export const createApplication = async (name: string, type: ApplicationType) =>
|
|||
export const getApplications = async () => authedAdminApi.get('applications').json<Application[]>();
|
||||
|
||||
export const getApplication = async (applicationId: string) =>
|
||||
authedAdminApi.get(`applications/${applicationId}`).json<Application>();
|
||||
authedAdminApi.get(`applications/${applicationId}`).json<Application & { isAdmin: boolean }>();
|
||||
|
||||
export const updateApplication = async (
|
||||
applicationId: string,
|
||||
|
@ -28,7 +28,7 @@ export const updateApplication = async (
|
|||
Omit<CreateApplication, 'id' | 'created_at' | 'oidcClientMetadata'> & {
|
||||
oidcClientMetadata: Partial<OidcClientMetadata>;
|
||||
}
|
||||
>
|
||||
> & { isAdmin?: boolean }
|
||||
) =>
|
||||
authedAdminApi
|
||||
.patch(`applications/${applicationId}`, {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue