import { Application } from '@logto/schemas'; import { demoAppApplicationId } from '@logto/schemas/lib/seeds'; import { authedAdminApi } from '@/api'; const testApplication = { id: '', name: 'test-app', type: 'SPA', }; describe('admin console application', () => { it('should get demo app details successfully', async () => { const demoApp = await authedAdminApi .get(`applications/${demoAppApplicationId}`) .json(); expect(demoApp.id).toBe(demoAppApplicationId); }); it('should create application successfully', async () => { const application = await authedAdminApi .post('applications', { json: { name: testApplication.name, type: testApplication.type }, }) .json(); expect(application.name).toBe(testApplication.name); expect(application.type).toBe(testApplication.type); // eslint-disable-next-line @silverhand/fp/no-mutation testApplication.id = application.id; const applications = await authedAdminApi.get('applications').json(); expect(applications.some((app) => app.id === application.id)).toBeTruthy(); }); it('should update application details successfully', async () => { expect(testApplication.id).toBeTruthy(); const application = await authedAdminApi .get(`applications/${testApplication.id}`) .json(); const newApplicationDescription = 'new application description'; expect(application.description).not.toBe(newApplicationDescription); const newRedirectUris = ['https://logto.dev/callback']; expect(application.oidcClientMetadata.redirectUris).not.toEqual(newRedirectUris); await authedAdminApi .patch(`applications/${application.id}`, { json: { description: newApplicationDescription, oidcClientMetadata: { redirectUris: newRedirectUris, }, }, }) .json(); const updatedApplication = await authedAdminApi .get(`applications/${application.id}`) .json(); expect(updatedApplication.description).toBe(newApplicationDescription); expect(updatedApplication.oidcClientMetadata.redirectUris).toEqual(newRedirectUris); }); it('should delete application successfully', async () => { expect(testApplication.id).toBeTruthy(); await authedAdminApi.delete(`applications/${testApplication.id}`); const applications = await authedAdminApi.get('applications').json(); const hasTestApplication = applications.some((app) => app.id === testApplication.id); expect(hasTestApplication).toBeFalsy(); }); });