2022-07-21 02:48:49 -05:00
|
|
|
import { Application, ApplicationType } from '@logto/schemas';
|
2022-07-20 04:24:41 -05:00
|
|
|
import { demoAppApplicationId } from '@logto/schemas/lib/seeds';
|
|
|
|
|
|
|
|
import { authedAdminApi } from '@/api';
|
|
|
|
|
2022-07-21 02:48:49 -05:00
|
|
|
const createApplication = (name: string, type: ApplicationType) =>
|
|
|
|
authedAdminApi
|
|
|
|
.post('applications', {
|
|
|
|
json: {
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.json<Application>();
|
2022-07-20 04:24:41 -05:00
|
|
|
|
|
|
|
describe('admin console application', () => {
|
|
|
|
it('should get demo app details successfully', async () => {
|
|
|
|
const demoApp = await authedAdminApi
|
|
|
|
.get(`applications/${demoAppApplicationId}`)
|
|
|
|
.json<Application>();
|
|
|
|
|
|
|
|
expect(demoApp.id).toBe(demoAppApplicationId);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create application successfully', async () => {
|
2022-07-21 02:48:49 -05:00
|
|
|
const applicationName = 'test-create-app';
|
|
|
|
const applicationType = ApplicationType.SPA;
|
2022-07-20 04:24:41 -05:00
|
|
|
|
2022-07-21 02:48:49 -05:00
|
|
|
const application = await createApplication(applicationName, applicationType);
|
2022-07-20 04:24:41 -05:00
|
|
|
|
2022-07-21 02:48:49 -05:00
|
|
|
expect(application.name).toBe(applicationName);
|
|
|
|
expect(application.type).toBe(applicationType);
|
2022-07-20 04:24:41 -05:00
|
|
|
|
2022-07-21 02:48:49 -05:00
|
|
|
const fetchedApplication = await authedAdminApi
|
|
|
|
.get(`applications/${application.id}`)
|
|
|
|
.json<Application[]>();
|
2022-07-20 04:24:41 -05:00
|
|
|
|
2022-07-21 02:48:49 -05:00
|
|
|
expect(fetchedApplication).toBeTruthy();
|
2022-07-20 04:24:41 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should update application details successfully', async () => {
|
2022-07-21 02:48:49 -05:00
|
|
|
const application = await createApplication('test-update-app', ApplicationType.SPA);
|
2022-07-20 04:24:41 -05:00
|
|
|
|
2022-07-21 02:48:49 -05:00
|
|
|
const newApplicationDescription = `new_${application.description ?? ''}`;
|
2022-07-20 04:24:41 -05:00
|
|
|
|
2022-07-21 02:48:49 -05:00
|
|
|
const newRedirectUris = application.oidcClientMetadata.redirectUris.concat([
|
|
|
|
'https://logto.dev/callback',
|
|
|
|
]);
|
2022-07-20 04:24:41 -05:00
|
|
|
|
|
|
|
await authedAdminApi
|
|
|
|
.patch(`applications/${application.id}`, {
|
|
|
|
json: {
|
|
|
|
description: newApplicationDescription,
|
|
|
|
oidcClientMetadata: {
|
|
|
|
redirectUris: newRedirectUris,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.json<Application>();
|
|
|
|
|
|
|
|
const updatedApplication = await authedAdminApi
|
|
|
|
.get(`applications/${application.id}`)
|
|
|
|
.json<Application>();
|
|
|
|
|
|
|
|
expect(updatedApplication.description).toBe(newApplicationDescription);
|
|
|
|
expect(updatedApplication.oidcClientMetadata.redirectUris).toEqual(newRedirectUris);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete application successfully', async () => {
|
2022-07-21 02:48:49 -05:00
|
|
|
const application = await createApplication('test-delete-app', ApplicationType.SPA);
|
2022-07-20 04:24:41 -05:00
|
|
|
|
2022-07-21 02:48:49 -05:00
|
|
|
await authedAdminApi.delete(`applications/${application.id}`);
|
2022-07-20 04:24:41 -05:00
|
|
|
|
2022-07-21 02:48:49 -05:00
|
|
|
const fetchResponseAfterDeletion = await authedAdminApi.get(`applications/${application.id}`, {
|
|
|
|
throwHttpErrors: false,
|
|
|
|
});
|
2022-07-20 04:24:41 -05:00
|
|
|
|
2022-07-21 02:48:49 -05:00
|
|
|
expect(fetchResponseAfterDeletion.statusCode).toBe(404);
|
2022-07-20 04:24:41 -05:00
|
|
|
});
|
|
|
|
});
|