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:
parent
a71e0dfdb6
commit
a9466667c0
2 changed files with 31 additions and 10 deletions
|
@ -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 () => {
|
||||
|
|
|
@ -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>(),
|
||||
]);
|
||||
|
|
Loading…
Add table
Reference in a new issue