0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -05:00

refactor(core): post application (#552)

This commit is contained in:
IceHe.xyz 2022-04-14 15:54:21 +08:00 committed by GitHub
parent a71e0dfdb6
commit a9466667c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 10 deletions

View file

@ -58,13 +58,30 @@ describe('application route', () => {
});
it('POST /applications', async () => {
const name = 'FooApplication';
const description = 'FooDescription';
const type = ApplicationType.Traditional;
const response = await applicationRequest
.post('/applications')
.send({ name, type, description });
expect(response.status).toEqual(200);
expect(response.body).toEqual({
...mockApplicationDTO,
id: 'randomId',
name,
description,
type,
});
});
it('POST /applications with custom client metadata', async () => {
const name = 'FooApplication';
const type = ApplicationType.Traditional;
const response = await applicationRequest
.post('/applications')
.send({ name, type, customClientMetadata });
expect(response.status).toEqual(200);
expect(response.body).toEqual({
...mockApplicationDTO,
@ -77,6 +94,7 @@ describe('application route', () => {
it('POST /applications should throw with invalid input body', async () => {
const name = 'FooApplication';
const description = 'FooDescription';
const type = ApplicationType.Traditional;
await expect(applicationRequest.post('/applications')).resolves.toHaveProperty('status', 400);
@ -84,10 +102,10 @@ describe('application route', () => {
applicationRequest.post('/applications').send({ customClientMetadata })
).resolves.toHaveProperty('status', 400);
await expect(
applicationRequest.post('/applications').send({ name, customClientMetadata })
applicationRequest.post('/applications').send({ name, description, customClientMetadata })
).resolves.toHaveProperty('status', 400);
await expect(
applicationRequest.post('/applications').send({ type, customClientMetadata })
applicationRequest.post('/applications').send({ type, description, customClientMetadata })
).resolves.toHaveProperty('status', 400);
await expect(
applicationRequest.post('/applications').send({
@ -110,13 +128,18 @@ describe('application route', () => {
it('PATCH /applications/:applicationId', async () => {
const name = 'FooApplication';
const description = 'FooDescription';
const response = await applicationRequest
.patch('/applications/foo')
.send({ name, customClientMetadata });
.send({ name, description, customClientMetadata });
expect(response.status).toEqual(200);
expect(response.body).toEqual({ ...mockApplicationDTO, name, customClientMetadata });
expect(response.body).toEqual({
...mockApplicationDTO,
name,
description,
customClientMetadata,
});
});
it('PATCH /applications/:applicationId expect to throw with invalid properties', async () => {

View file

@ -52,15 +52,13 @@ export default function applicationRoutes<T extends AuthedRouter>(router: T) {
.merge(Applications.createGuard.pick({ name: true, type: true })),
}),
async (ctx, next) => {
const { name, type, oidcClientMetadata, customClientMetadata } = ctx.guard.body;
const { oidcClientMetadata, ...rest } = ctx.guard.body;
const [application, oidcConfig] = await Promise.all([
insertApplication({
id: applicationId(),
type,
name,
oidcClientMetadata: buildOidcClientMetadata(oidcClientMetadata),
customClientMetadata,
...rest,
}),
got(discoveryUrl).json<SnakeCaseOidcConfig>(),
]);