test: Add types to getUser test file
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
import request from 'supertest';
|
import request, { Test } from 'supertest';
|
||||||
import app from '../../app';
|
import app from '../../app';
|
||||||
import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id';
|
import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id';
|
||||||
import Crypto from 'crypto';
|
import Crypto from 'crypto';
|
||||||
import createRole from '../../../test/fixtures/role';
|
import createRole from '../../../test/fixtures/role';
|
||||||
import createPermission from '../../../test/fixtures/permission';
|
import createPermission from '../../../test/fixtures/permission';
|
||||||
import createUser from '../../../test/fixtures/user';
|
import createUser from '../../../test/fixtures/user';
|
||||||
|
import { IRole, IUser } from '@automatisch/types';
|
||||||
|
|
||||||
describe('getUser', () => {
|
describe('getUser', () => {
|
||||||
describe('with unauthorized user', () => {
|
describe('with unauthorized user', () => {
|
||||||
@@ -32,11 +33,11 @@ describe('getUser', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('with authorized user', () => {
|
describe('with authorized user', () => {
|
||||||
let role: any,
|
let role: IRole,
|
||||||
currentUser: any,
|
currentUser: IUser,
|
||||||
anotherUser: any,
|
anotherUser: IUser,
|
||||||
token: any,
|
token: string,
|
||||||
requestObject: any;
|
requestObject: Test;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
role = await createRole({
|
role = await createRole({
|
||||||
@@ -87,12 +88,12 @@ describe('getUser', () => {
|
|||||||
const expectedResponsePayload = {
|
const expectedResponsePayload = {
|
||||||
data: {
|
data: {
|
||||||
getUser: {
|
getUser: {
|
||||||
createdAt: anotherUser.created_at.getTime().toString(),
|
createdAt: (anotherUser.createdAt as Date).getTime().toString(),
|
||||||
email: anotherUser.email,
|
email: anotherUser.email,
|
||||||
fullName: anotherUser.full_name,
|
fullName: anotherUser.fullName,
|
||||||
id: anotherUser.id,
|
id: anotherUser.id,
|
||||||
role: { id: role.id, name: role.name },
|
role: { id: role.id, name: role.name },
|
||||||
updatedAt: anotherUser.updated_at.getTime().toString(),
|
updatedAt: (anotherUser.updatedAt as Date).getTime().toString(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
7
packages/backend/test/fixtures/permission.ts
vendored
7
packages/backend/test/fixtures/permission.ts
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
import { IPermission } from '@automatisch/types';
|
||||||
import createRole from './role';
|
import createRole from './role';
|
||||||
|
|
||||||
type PermissionParams = {
|
type PermissionParams = {
|
||||||
@@ -6,9 +7,11 @@ type PermissionParams = {
|
|||||||
subject?: string;
|
subject?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const createPermission = async (params: PermissionParams = {}) => {
|
const createPermission = async (
|
||||||
|
params: PermissionParams = {}
|
||||||
|
): Promise<IPermission> => {
|
||||||
const permissionData = {
|
const permissionData = {
|
||||||
role_id: params?.roleId || (await createRole()).id,
|
roleId: params?.roleId || (await createRole()).id,
|
||||||
action: params?.action || 'read',
|
action: params?.action || 'read',
|
||||||
subject: params?.subject || 'User',
|
subject: params?.subject || 'User',
|
||||||
};
|
};
|
||||||
|
4
packages/backend/test/fixtures/role.ts
vendored
4
packages/backend/test/fixtures/role.ts
vendored
@@ -1,9 +1,11 @@
|
|||||||
|
import { IRole } from '@automatisch/types';
|
||||||
|
|
||||||
type RoleParams = {
|
type RoleParams = {
|
||||||
name?: string;
|
name?: string;
|
||||||
key?: string;
|
key?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const createRole = async (params: RoleParams = {}) => {
|
const createRole = async (params: RoleParams = {}): Promise<IRole> => {
|
||||||
params.name = params?.name || 'Viewer';
|
params.name = params?.name || 'Viewer';
|
||||||
params.key = params?.key || 'viewer';
|
params.key = params?.key || 'viewer';
|
||||||
|
|
||||||
|
4
packages/backend/test/fixtures/user.ts
vendored
4
packages/backend/test/fixtures/user.ts
vendored
@@ -10,8 +10,8 @@ type UserParams = {
|
|||||||
|
|
||||||
const createUser = async (params: UserParams = {}) => {
|
const createUser = async (params: UserParams = {}) => {
|
||||||
const userData = {
|
const userData = {
|
||||||
role_id: params?.roleId || (await createRole()).id,
|
roleId: params?.roleId || (await createRole()).id,
|
||||||
full_name: params?.fullName || faker.person.fullName(),
|
fullName: params?.fullName || faker.person.fullName(),
|
||||||
email: params?.email || faker.internet.email(),
|
email: params?.email || faker.internet.email(),
|
||||||
password: params?.password || faker.internet.password(),
|
password: params?.password || faker.internet.password(),
|
||||||
};
|
};
|
||||||
|
2
packages/types/index.d.ts
vendored
2
packages/types/index.d.ts
vendored
@@ -99,6 +99,8 @@ export interface IUser {
|
|||||||
steps: IStep[];
|
steps: IStep[];
|
||||||
role: IRole;
|
role: IRole;
|
||||||
permissions: IPermission[];
|
permissions: IPermission[];
|
||||||
|
createdAt: string | Date;
|
||||||
|
updatedAt: string | Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IRole {
|
export interface IRole {
|
||||||
|
Reference in New Issue
Block a user