Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add schemas to user admin controller (#1692)
* refactor: add schemas to user admin controller * refactor: remove unused SessionService * refactor: fix search query type confusion * refactor: add schemas to user controller (#1693) * refactor: add schemas to user controller * refactor: fix getAllUserSplashes method name * refactor: name and email should not be required on create * refactor: only some user fields may be updated * refactor: should not require any fields on user update (#1730) * refactor: send 400 instead of 500 on missing username and email * refactor: should not require any fields for user update * refactor: note that earlier versions required name or email * refactor: merge roleDescriptionSchema and roleSchema
- Loading branch information
Showing
43 changed files
with
1,420 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`meSchema empty 1`] = ` | ||
Object { | ||
"data": Object {}, | ||
"errors": Array [ | ||
Object { | ||
"instancePath": "", | ||
"keyword": "required", | ||
"message": "must have required property 'user'", | ||
"params": Object { | ||
"missingProperty": "user", | ||
}, | ||
"schemaPath": "#/required", | ||
}, | ||
], | ||
"schema": "#/components/schemas/meSchema", | ||
} | ||
`; | ||
|
||
exports[`meSchema missing permissions 1`] = ` | ||
Object { | ||
"data": Object { | ||
"user": Object { | ||
"id": 1, | ||
}, | ||
}, | ||
"errors": Array [ | ||
Object { | ||
"instancePath": "", | ||
"keyword": "required", | ||
"message": "must have required property 'permissions'", | ||
"params": Object { | ||
"missingProperty": "permissions", | ||
}, | ||
"schemaPath": "#/required", | ||
}, | ||
], | ||
"schema": "#/components/schemas/meSchema", | ||
} | ||
`; | ||
|
||
exports[`meSchema missing splash 1`] = ` | ||
Object { | ||
"data": Object { | ||
"feedback": Array [], | ||
"permissions": Array [], | ||
"user": Object { | ||
"id": 1, | ||
}, | ||
}, | ||
"errors": Array [ | ||
Object { | ||
"instancePath": "", | ||
"keyword": "required", | ||
"message": "must have required property 'splash'", | ||
"params": Object { | ||
"missingProperty": "splash", | ||
}, | ||
"schemaPath": "#/required", | ||
}, | ||
], | ||
"schema": "#/components/schemas/meSchema", | ||
} | ||
`; |
8 changes: 4 additions & 4 deletions
8
...ts__/role-description-schema.test.ts.snap → ...ec/__snapshots__/role-schema.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`roleDescriptionSchema empty 1`] = ` | ||
exports[`roleSchema 1`] = ` | ||
Object { | ||
"data": Object {}, | ||
"errors": Array [ | ||
Object { | ||
"instancePath": "", | ||
"keyword": "required", | ||
"message": "must have required property 'description'", | ||
"message": "must have required property 'id'", | ||
"params": Object { | ||
"missingProperty": "description", | ||
"missingProperty": "id", | ||
}, | ||
"schemaPath": "#/required", | ||
}, | ||
], | ||
"schema": "#/components/schemas/roleDescriptionSchema", | ||
"schema": "#/components/schemas/roleSchema", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { FromSchema } from 'json-schema-to-ts'; | ||
|
||
export const createUserSchema = { | ||
$id: '#/components/schemas/createUserSchema', | ||
type: 'object', | ||
additionalProperties: false, | ||
required: ['rootRole'], | ||
properties: { | ||
username: { | ||
type: 'string', | ||
}, | ||
email: { | ||
type: 'string', | ||
}, | ||
name: { | ||
type: 'string', | ||
}, | ||
password: { | ||
type: 'string', | ||
}, | ||
rootRole: { | ||
type: 'number', | ||
}, | ||
sendEmail: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
components: {}, | ||
} as const; | ||
|
||
export type CreateUserSchema = FromSchema<typeof createUserSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { validateSchema } from '../validate'; | ||
import { EmailSchema } from './email-schema'; | ||
|
||
test('emailSchema', () => { | ||
const data: EmailSchema = { | ||
email: '', | ||
}; | ||
|
||
expect( | ||
validateSchema('#/components/schemas/emailSchema', data), | ||
).toBeUndefined(); | ||
|
||
expect( | ||
validateSchema('#/components/schemas/emailSchema', {}), | ||
).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { FromSchema } from 'json-schema-to-ts'; | ||
|
||
export const emailSchema = { | ||
$id: '#/components/schemas/emailSchema', | ||
type: 'object', | ||
additionalProperties: false, | ||
required: ['email'], | ||
properties: { | ||
email: { | ||
type: 'string', | ||
}, | ||
}, | ||
components: {}, | ||
} as const; | ||
|
||
export type EmailSchema = FromSchema<typeof emailSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { FromSchema } from 'json-schema-to-ts'; | ||
|
||
export const idSchema = { | ||
$id: '#/components/schemas/idSchema', | ||
type: 'object', | ||
additionalProperties: false, | ||
required: ['id'], | ||
properties: { | ||
id: { | ||
type: 'string', | ||
}, | ||
}, | ||
components: {}, | ||
} as const; | ||
|
||
export type IdSchema = FromSchema<typeof idSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { validateSchema } from '../validate'; | ||
import { MeSchema } from './me-schema'; | ||
|
||
test('meSchema', () => { | ||
const data: MeSchema = { | ||
user: { id: 1 }, | ||
permissions: [{ permission: 'a' }], | ||
feedback: [{ userId: 1, feedbackId: 'a', neverShow: false }], | ||
splash: { a: true }, | ||
}; | ||
|
||
expect( | ||
validateSchema('#/components/schemas/meSchema', data), | ||
).toBeUndefined(); | ||
}); | ||
|
||
test('meSchema empty', () => { | ||
expect( | ||
validateSchema('#/components/schemas/meSchema', {}), | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
test('meSchema missing permissions', () => { | ||
expect( | ||
validateSchema('#/components/schemas/meSchema', { user: { id: 1 } }), | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
test('meSchema missing splash', () => { | ||
expect( | ||
validateSchema('#/components/schemas/meSchema', { | ||
user: { id: 1 }, | ||
permissions: [], | ||
feedback: [], | ||
}), | ||
).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { FromSchema } from 'json-schema-to-ts'; | ||
import { userSchema } from './user-schema'; | ||
import { permissionSchema } from './permission-schema'; | ||
import { feedbackSchema } from './feedback-schema'; | ||
|
||
export const meSchema = { | ||
$id: '#/components/schemas/meSchema', | ||
type: 'object', | ||
additionalProperties: false, | ||
required: ['user', 'permissions', 'feedback', 'splash'], | ||
properties: { | ||
user: { | ||
$ref: '#/components/schemas/userSchema', | ||
}, | ||
permissions: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/components/schemas/permissionSchema', | ||
}, | ||
}, | ||
feedback: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/components/schemas/feedbackSchema', | ||
}, | ||
}, | ||
splash: { | ||
type: 'object', | ||
additionalProperties: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
}, | ||
components: { | ||
schemas: { | ||
userSchema, | ||
permissionSchema, | ||
feedbackSchema, | ||
}, | ||
}, | ||
} as const; | ||
|
||
export type MeSchema = FromSchema<typeof meSchema>; |
Oops, something went wrong.