1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-23 01:16:27 +02:00

refactor: add missing tokenUserSchema fields (#1742)

This commit is contained in:
olav 2022-06-22 15:37:26 +02:00 committed by GitHub
parent ab75d4085e
commit e013a72ddd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 23 deletions

View File

@ -1,15 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`tokenUserSchema empty 1`] = ` exports[`tokenUserSchema 1`] = `
Object { Object {
"data": Object {}, "data": Object {},
"errors": Array [ "errors": Array [
Object { Object {
"instancePath": "", "instancePath": "",
"keyword": "required", "keyword": "required",
"message": "must have required property 'createdBy'", "message": "must have required property 'id'",
"params": Object { "params": Object {
"missingProperty": "createdBy", "missingProperty": "id",
}, },
"schemaPath": "#/required", "schemaPath": "#/required",
}, },

View File

@ -3,10 +3,13 @@ import { TokenUserSchema } from './token-user-schema';
test('tokenUserSchema', () => { test('tokenUserSchema', () => {
const data: TokenUserSchema = { const data: TokenUserSchema = {
id: 0,
name: '',
email: '',
createdBy: '', createdBy: '',
token: '', token: '',
role: { role: {
id: 1, id: 0,
description: '', description: '',
name: '', name: '',
type: '', type: '',
@ -16,9 +19,7 @@ test('tokenUserSchema', () => {
expect( expect(
validateSchema('#/components/schemas/tokenUserSchema', data), validateSchema('#/components/schemas/tokenUserSchema', data),
).toBeUndefined(); ).toBeUndefined();
});
test('tokenUserSchema empty', () => {
expect( expect(
validateSchema('#/components/schemas/tokenUserSchema', {}), validateSchema('#/components/schemas/tokenUserSchema', {}),
).toMatchSnapshot(); ).toMatchSnapshot();

View File

@ -5,14 +5,24 @@ export const tokenUserSchema = {
$id: '#/components/schemas/tokenUserSchema', $id: '#/components/schemas/tokenUserSchema',
type: 'object', type: 'object',
additionalProperties: false, additionalProperties: false,
required: ['createdBy', 'token', 'role'], required: ['id', 'name', 'email', 'token', 'createdBy', 'role'],
properties: { properties: {
createdBy: { id: {
type: 'number',
},
name: {
type: 'string',
},
email: {
type: 'string', type: 'string',
}, },
token: { token: {
type: 'string', type: 'string',
}, },
createdBy: {
type: 'string',
nullable: true,
},
role: { role: {
$ref: '#/components/schemas/roleSchema', $ref: '#/components/schemas/roleSchema',
}, },

View File

@ -27,6 +27,7 @@ import DisabledError from '../error/disabled-error';
import PasswordMismatch from '../error/password-mismatch'; import PasswordMismatch from '../error/password-mismatch';
import BadDataError from '../error/bad-data-error'; import BadDataError from '../error/bad-data-error';
import { isDefined } from '../util/isDefined'; import { isDefined } from '../util/isDefined';
import { TokenUserSchema } from '../openapi/spec/token-user-schema';
const systemUser = new User({ id: -1, username: 'system' }); const systemUser = new User({ id: -1, username: 'system' });
@ -56,19 +57,6 @@ interface IUserWithRole extends IUser {
rootRole: number; rootRole: number;
} }
interface IRoleDescription {
id: number;
description: string;
name: string;
type: string;
}
interface ITokenUser extends IUpdateUser {
createdBy: string;
token: string;
role: IRoleDescription;
}
const saltRounds = 10; const saltRounds = 10;
class UserService { class UserService {
@ -362,7 +350,7 @@ class UserService {
return this.store.setPasswordHash(userId, passwordHash); return this.store.setPasswordHash(userId, passwordHash);
} }
async getUserForToken(token: string): Promise<ITokenUser> { async getUserForToken(token: string): Promise<TokenUserSchema> {
const { createdBy, userId } = await this.resetTokenService.isValid( const { createdBy, userId } = await this.resetTokenService.isValid(
token, token,
); );

View File

@ -1502,6 +1502,16 @@ Object {
"additionalProperties": false, "additionalProperties": false,
"properties": Object { "properties": Object {
"createdBy": Object { "createdBy": Object {
"nullable": true,
"type": "string",
},
"email": Object {
"type": "string",
},
"id": Object {
"type": "number",
},
"name": Object {
"type": "string", "type": "string",
}, },
"role": Object { "role": Object {
@ -1512,8 +1522,11 @@ Object {
}, },
}, },
"required": Array [ "required": Array [
"createdBy", "id",
"name",
"email",
"token", "token",
"createdBy",
"role", "role",
], ],
"type": "object", "type": "object",