-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhelpers.js
More file actions
52 lines (46 loc) · 1.48 KB
/
helpers.js
File metadata and controls
52 lines (46 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import OpenAPIResponseValidator from 'openapi-response-validator';
import client from 'next-auth/client';
import getSchema from './openApiSchema';
import { Roles } from '../../lib/constants';
const getOpenApiValidatorForRequest = async (endpoint, method = 'get') => {
const expectedSchema = await getSchema();
expectedSchema.responses =
expectedSchema.responses[endpoint][method].responses;
const validator = new OpenAPIResponseValidator(expectedSchema);
return validator;
};
const mockSessionWithUserType = (userType, entityId = 1, setUserId = true) => {
let mockSession = Object.values(Roles).includes(userType)
? {
expires: '1',
user: {
email: `${userType}@example.com`,
name: userType,
image: null,
roles: [userType],
userId: setUserId ? userType : null,
},
}
: null;
switch (userType) {
case Roles.USER_TYPE_CLINICIAN: {
mockSession.user.departmentId = entityId;
break;
}
case Roles.USER_TYPE_DEPARTMENT: {
mockSession.user.departmentId = entityId;
break;
}
case Roles.USER_TYPE_HOSPITAL: {
mockSession.user.hospitalId = entityId;
break;
}
case Roles.USER_TYPE_HEALTH_BOARD: {
mockSession.user.healthBoardId = entityId;
break;
}
}
client.useSession.mockReturnValue([mockSession, false]);
client.getSession.mockReturnValue(mockSession);
};
module.exports = { getOpenApiValidatorForRequest, mockSessionWithUserType };