@getjones/test-infra 2.8.9 → 2.8.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getjones/test-infra",
3
- "version": "2.8.9",
3
+ "version": "2.8.11",
4
4
  "description": "Providing internal and openapi interface",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,7 +1,8 @@
1
1
  const chartTypes = {
2
2
  requiringAttention: 'requiringAttention',
3
3
  expirationDatePerMonth: 'expirationDatePerMonth',
4
- waivedByRequirement: 'waivedByRequirement'
4
+ waivedByRequirement: 'waivedByRequirement',
5
+ notCompliantForRequirement: 'notCompliantForRequirement'
5
6
  };
6
7
  const sortBy = {
7
8
  companyName: 'SORT_BY_COMPANYNAME',
@@ -6,7 +6,7 @@ const DEFAULT_POLICY_DATE = '24/05/2030';
6
6
  const DEFAULT_AM_SCORE = 'A';
7
7
 
8
8
  //Excluded from creating global record: 'ABC-12345-XYZ', 'ABC-123-XYZ', 'ABC-123'. When GR is needed - use different GL number.
9
- const DEFAULT_POLICY_NUMBER = 'ABC-12345-XYZ';
9
+ const DEFAULT_POLICY_NUMBER = 'ABC-12345-XYZ';
10
10
 
11
11
  const {
12
12
  certificateIssueDate,
@@ -4,6 +4,8 @@ const { backendUrl } = require('../../../../../env').getEnv();
4
4
  const Endpoints = {
5
5
  getAccount: `${backendUrl}/saas/accounts`,
6
6
  create: `${backendUrl}/saas/createaccount`,
7
+ createInnerSystemAccount: `${backendUrl}/saas/superuser/user`,
8
+ getInnerSystemAccountsPerRole: `${backendUrl}/saas/users`,
7
9
  delete: `${backendUrl}/saas/account`,
8
10
  edit: accountId => `${backendUrl}/saas/account/${accountId}/settings`
9
11
  };
@@ -12,6 +14,15 @@ const create = (account, context) => {
12
14
  return requests.postRequestHandler(Endpoints.create, account, context);
13
15
  };
14
16
 
17
+ const createInnerSystemAccount = (innerSystemUser, icsContext) => {
18
+ return requests.postRequestHandler(Endpoints.createInnerSystemAccount, innerSystemUser, icsContext);
19
+ };
20
+
21
+ const getInnerSystemAccountsPerRole = (roles, icsContext) => {
22
+ const params = { roles };
23
+ return requests.getRequestHandler(Endpoints.getInnerSystemAccountsPerRole, params, icsContext);
24
+ };
25
+
15
26
  const deleteAccount = (accountId, context) => {
16
27
  return requests.deleteRequestHandler(Endpoints.delete, context, {}, { 'userId': accountId });
17
28
  };
@@ -25,4 +36,4 @@ const getByName = (accountName, context) => {
25
36
  return requests.getRequestHandler(Endpoints.getAccount, params, context);
26
37
  };
27
38
 
28
- module.exports = { create, getByName, deleteAccount, updateAccountSettings };
39
+ module.exports = { create, getByName, deleteAccount, updateAccountSettings, createInnerSystemAccount, getInnerSystemAccountsPerRole };
@@ -1,7 +1,11 @@
1
1
  const env = require('../../../../../env');
2
2
  const accountsAPI = require('./accounts.core.api');
3
3
  const CreateAccountModel = require('../../models/core/create.account.model');
4
+ const CreateInnerSystemAccountModel = require('../../models/core/create.inner.system.account.model');
4
5
  const { validateType } = require('../../../../../common/validations/typeValidations');
6
+ const httpResponseStatusCodes = require('../../../../../common/httpResponseStatusCodes.json');
7
+ const { ROLES } = require('../../../../../../../../src/saas/internal-api/common/users/consts');
8
+ const userTypes = require('../../../../../common/consts/userTypes');
5
9
 
6
10
  const { accountCreationSecret } = env.getEnv();
7
11
 
@@ -16,6 +20,48 @@ const createAccount = async (createAccountModel, context) => {
16
20
  return accountsAPI.create(createAccountModel, context);
17
21
  };
18
22
 
23
+ const createInnerSystemAccount = async (innerSystemCreateAccountModel, icsContext) => {
24
+ validateType(innerSystemCreateAccountModel, CreateInnerSystemAccountModel);
25
+ const response = await accountsAPI.createInnerSystemAccount(innerSystemCreateAccountModel, icsContext);
26
+
27
+ if (response.status !== httpResponseStatusCodes.OK) {
28
+ throw Error(`Create inner system account failed\n${response}`);
29
+ }
30
+
31
+ return response.data;
32
+ };
33
+
34
+ const getInnerSystemAccountsPerRole = async icsContext => {
35
+ const roles = `${userTypes.ICS},${ROLES.auditor},${ROLES.operator}`;
36
+ const response = await accountsAPI.getInnerSystemAccountsPerRole(roles, icsContext);
37
+
38
+ if (response.status !== httpResponseStatusCodes.OK) {
39
+ throw Error(`Get inner system accounts failed\n${response}`);
40
+ }
41
+
42
+ return response.data;
43
+ };
44
+
45
+ const getOrCreateInnerSystemAccount = async (innerSystemCreateAccountModel, role, icsContext) => {
46
+ const accountEmail = innerSystemCreateAccountModel.email;
47
+ const account = await getInnerSystemAccountByEmail(accountEmail, role, icsContext);
48
+
49
+ if (account) {
50
+ return account;
51
+ }
52
+
53
+ await createInnerSystemAccount(innerSystemCreateAccountModel, icsContext);
54
+ return getInnerSystemAccountByEmail(accountEmail, role, icsContext);
55
+ };
56
+
57
+ const getInnerSystemAccountByEmail = async (accountEmail, role, icsContext) => {
58
+ const accountsPerRole = await getInnerSystemAccountsPerRole(icsContext);
59
+ const accountsOfRole = accountsPerRole[role];
60
+ const account = accountsOfRole.find(({ email }) => email === accountEmail);
61
+
62
+ return account;
63
+ };
64
+
19
65
  const getAccount = async (accountName, context) => {
20
66
  const response = await accountsAPI.getByName(accountName, context);
21
67
 
@@ -73,5 +119,6 @@ module.exports = {
73
119
  getAccountId,
74
120
  createAccount,
75
121
  deleteAccountByName,
76
- deleteAccountById
122
+ deleteAccountById,
123
+ getOrCreateInnerSystemAccount
77
124
  };
@@ -1,5 +1,6 @@
1
1
  const CreateAccountModel = require('./models/core/create.account.model');
2
- const coreModels = { CreateAccountModel };
2
+ const CreateInnerSystemAccountModel = require('./models/core/create.inner.system.account.model');
3
+ const coreModels = { CreateAccountModel, CreateInnerSystemAccountModel };
3
4
 
4
5
  const UpdateAccountSettingsModel = require('./models/settings/update.settings.model');
5
6
  const settingsModels = { UpdateAccountSettingsModel };
@@ -0,0 +1,18 @@
1
+ const env = require('../../../../../env');
2
+ const { credentials } = env.getEnv();
3
+
4
+ class CreateInnerSystemAccountModel {
5
+ constructor({
6
+ fullName = '',
7
+ email = '',
8
+ password = credentials.strongPassword,
9
+ userRole
10
+ }) {
11
+ this.fullName = fullName;
12
+ this.email = email;
13
+ this.password = password;
14
+ this.role = userRole;
15
+ }
16
+ }
17
+
18
+ module.exports = CreateInnerSystemAccountModel;
@@ -102,12 +102,13 @@ const getPolicyAuditIdFromRecord = (record, policyName, attributeName) => {
102
102
  return attribute.auditId;
103
103
  };
104
104
 
105
- const waiveAll = async (record, context, { reason = WAIVER_REASONS.BUSINESS_DECISION, note = 'WAIVED AUTOMATICALLY' } = {}) => {
105
+ // private method - please refer to waiveAll / acceptAll
106
+ const overrideAll = async (record, reason, context, { note = 'OVERRIDDEN AUTOMATICALLY' } = {}) => {
106
107
  const allWaivablePolicies = auditUtil.getAllWaivablePolicies(record, context);
107
108
 
108
109
  for (const waivable of allWaivablePolicies) {
109
110
  const waiveModel = getWaiveModel(record, waivable.policyName, waivable.attributeName, reason, note);
110
- const waiveResponse = await waive(waiveModel, context);
111
+ const waiveResponse = await overrideGap({ waiveRequestModel: waiveModel, context });
111
112
 
112
113
  if (waiveResponse.status !== httpResponseStatusCodes.OK) {
113
114
  throw Error(`Failed to waive ${waivable.policyName} - ${waivable.attributeName} for ${record.company}`);
@@ -115,9 +116,22 @@ const waiveAll = async (record, context, { reason = WAIVER_REASONS.BUSINESS_DECI
115
116
  }
116
117
  };
117
118
 
119
+ const waiveAll = async (record, context, { reason = WAIVER_REASONS.BUSINESS_DECISION, note = 'WAIVED AUTOMATICALLY' } = {}) => {
120
+ if (reason === WAIVER_REASONS.ACCEPT_NO_EXPOSURE) {
121
+ throw Error('Invalid override gap reason to waive');
122
+ }
123
+
124
+ await overrideAll(record, reason, context, { note });
125
+ };
126
+
127
+ const acceptAll = async (record, context, { note = 'ACCEPTED AUTOMATICALLY' } = {}) => {
128
+ await overrideAll(record, WAIVER_REASONS.ACCEPT_NO_EXPOSURE, context, { note });
129
+ };
130
+
118
131
  module.exports = {
119
132
  waive,
120
133
  waiveAll,
134
+ acceptAll,
121
135
  retract,
122
136
  getWaiveModel,
123
137
  getRetractModel,
@@ -119,9 +119,26 @@ const getLastMessage = async (
119
119
  return newestResult;
120
120
  };
121
121
 
122
+ const waitForMail = async (emailModel, maxSecondToWait) => {
123
+ let isNotSend = true;
124
+ const oneSecondInMilliseconds = 1000;
125
+ let timeFromTheStart = 0;
126
+ const started = new Date();
127
+ let sendMails;
128
+
129
+ while (isNotSend && timeFromTheStart < maxSecondToWait) {
130
+ ({ data: sendMails } = await getAllMessages(emailModel));
131
+ isNotSend = sendMails.length === 0;
132
+ const now = new Date();
133
+ timeFromTheStart = (now - started) / oneSecondInMilliseconds;
134
+ }
135
+
136
+ return sendMails;
137
+ };
138
+
122
139
  module.exports = {
123
140
  util,
124
-
141
+ waitForMail,
125
142
  getAllMessages,
126
143
  getLastMessage,
127
144
  deleteMultipleMessages,
@@ -4,6 +4,7 @@ const EMAIL_TYPES = {
4
4
  COMPLIANT: 'compliant',
5
5
  NOT_COMPLIANT: 'notCompliant',
6
6
  SEND_GAPS: 'sendGaps',
7
+ SEND_GAPS_TENANT: 'sendGapsForTenant',
7
8
  REQUEST_NEW_COI_EXPIRED: 'requestNewCoiExpired',
8
9
  FIRST_REMINDER: 'firstReminder',
9
10
  SECOND_REMINDER: 'secondReminder',
@@ -20,14 +21,14 @@ const EMAIL_TYPES = {
20
21
 
21
22
  const EMAIL_SUBJECT = {
22
23
  compliant: ({ recordCompanyName }) => `Compliant COI - ${recordCompanyName}`,
24
+ sendGaps: ({ requesterName }) => `New Insurance Docs Required for ${requesterName} - `, //For this email type, guest is the same as vendor
25
+ sendGapsForTenant: ({ requesterName }) => `New Insurance Docs Required for leased space at ${requesterName} - `,
23
26
  notCompliant: ({ recordCompanyName, requesterName }) => `Please Review COI Gaps - ${recordCompanyName} (${requesterName})`,
24
27
  wrongCoi: ({ recordCompanyName, requesterName }) => `Incorrect File Submission - COI Still Required for ${recordCompanyName} - ${requesterName}`,
25
- sendGaps: ({ requesterName }) => `New Insurance Docs Required for ${requesterName}`, //doesn't includes text for guest or tenant
26
28
  sendGapsRecordFullName: ({ requesterName, recordFirstName, recordLastName }) => `New Insurance Docs Required for ${requesterName} - ${recordFirstName} ${recordLastName}`,
27
29
  requestNewCoiExpired: ({ recordCompanyName }) => `${recordCompanyName}'s COI is`,
28
30
  firstReminder: ({ requesterName }) => `We are still awaiting the Insurance Docs for ${requesterName}`,
29
- secondReminder: ({ requesterName }) => `We are still awaiting the Insurance Docs for ${requesterName}`,
30
- secondReminderAccountRequirement: ({ requesterName }) => `${requesterName} still needs your Insurance Docs`,
31
+ secondReminder: ({ requesterName }) => `${requesterName} still needs`,
31
32
  finalReminder: ({ recordCompanyName, requesterName }) => `Missing ${recordCompanyName}'s Insurance Docs for ${requesterName}`,
32
33
  aboutToExpirePM: ({ recordCompanyName }) => `Insurance Policy of ${recordCompanyName} expires Soon`,
33
34
  aboutToExpireMonthAutoRenewal: ({ requesterName }) => `Your COI for ${requesterName} expires in 30 days`,
@@ -37,6 +38,9 @@ const EMAIL_SUBJECT = {
37
38
  sameDayExpirationPMAutoRenewal: ({ recordCompanyName }) => `COI expired for ${recordCompanyName} at`,
38
39
  requirementsUpdatedNotification: ({ requesterName }) => `Updated Requirements - Your Insurance Docs are needed for ${requesterName}`,
39
40
  updatedRequirementsSubjectPrefix: () => 'Updated Requirements - ',
41
+ fraudAuditorReview: ({ recordCompanyName, requesterName }) => `Authentication check for ${recordCompanyName} at ${requesterName}`,
42
+ requestNewCoi: ({ recordCompanyName, requesterName, isExpired }) => `${recordCompanyName}'s COI is ${isExpired ? 'expired' : 'about to expire'} - ${requesterName}`,
43
+ malwareCoiFound: 'COI upload failed to pass security scan',
40
44
  thankYou: 'Thank you for submitting your COI'
41
45
  };
42
46
 
@@ -12,7 +12,8 @@ const Endpoints = {
12
12
  requestsGlobalSearch: (projectId, searchWord) =>
13
13
  `${backendUrl}/saas/requests/search?&projectId=${projectId}&searchWord=${searchWord}`,
14
14
  getAutocompleteAutoSelect: `${backendUrl}/saas/request/auto/selection`,
15
- getTabTenantRequestsInProject: projectId => `${backendUrl}/saas/project/${projectId}/tenants/companies`
15
+ getTabTenantRequestsInProject: projectId => `${backendUrl}/saas/project/${projectId}/tenants/companies`,
16
+ innerPageRequests: `${backendUrl}/saas/requests/chart-filter`
16
17
  };
17
18
 
18
19
  const createRequest = (createRequestModel, context) => {
@@ -58,6 +59,10 @@ const getTabTenantRequestsInProject = (projectId, context) => {
58
59
  return requests.getRequestHandler(Endpoints.getTabTenantRequestsInProject(projectId), {}, context);
59
60
  };
60
61
 
62
+ const getInnerPageRequests = (innerPageRequestCriteriaModel, context) => {
63
+ return requests.postRequestHandler(Endpoints.innerPageRequests, innerPageRequestCriteriaModel, context);
64
+ };
65
+
61
66
  module.exports = {
62
67
  createRequest,
63
68
  addRequestToRecord,
@@ -68,5 +73,6 @@ module.exports = {
68
73
  getRequestsByTabId,
69
74
  requestsGlobalSearch,
70
75
  getAutocompleteAutoSelect,
71
- getTabTenantRequestsInProject
76
+ getTabTenantRequestsInProject,
77
+ getInnerPageRequests
72
78
  };
@@ -1,5 +1,6 @@
1
1
  const requestsAPI = require('./requests.api');
2
2
  const { CreateRequestModel, ContractorInfo } = require('../models/create.request.model');
3
+ const { InnerPageRequestCriteriaModel } = require('../models/inner.page.request.criteria.model');
3
4
  const { RequestModel } = require('../models/edit.request.model');
4
5
  const { validateType } = require('../../../../common/validations/typeValidations');
5
6
  const httpResponseStatusCodes = require('../../../../common/httpResponseStatusCodes.json');
@@ -105,6 +106,17 @@ const getRequestFromTabByRecordId = async (recordId, tabId, context) => {
105
106
  return request;
106
107
  };
107
108
 
109
+ const getInnerPageRequests = async (innerPageRequestCriteriaModel, context) => {
110
+ validateType(innerPageRequestCriteriaModel, InnerPageRequestCriteriaModel);
111
+ const response = await requestsAPI.getInnerPageRequests(innerPageRequestCriteriaModel, context);
112
+
113
+ if (response.status !== httpResponseStatusCodes.OK) {
114
+ throw Error(`Get requests inner page has fail\n${response}`);
115
+ }
116
+
117
+ return response.data;
118
+ };
119
+
108
120
  module.exports = {
109
121
  createRequest,
110
122
  getAutocompleteAutoSelect,
@@ -118,5 +130,6 @@ module.exports = {
118
130
  getCreateRequestModel,
119
131
  requestsGlobalSearch,
120
132
  getTabTenantRequestsInProject,
121
- getRequestFromTabByRecordId
133
+ getRequestFromTabByRecordId,
134
+ getInnerPageRequests
122
135
  };
@@ -2,13 +2,15 @@ const services = require('./api/requests.service');
2
2
 
3
3
  const { TenantRequestModel, RequestModel, TabModel } = require('./models/edit.request.model');
4
4
  const { CreateRequestModel, ContractorInfo } = require('./models/create.request.model');
5
+ const { InnerPageRequestCriteriaModel } = require('./models/inner.page.request.criteria.model');
5
6
 
6
7
  const models = {
7
8
  TenantRequestModel,
8
9
  RequestModel,
9
10
  TabModel,
10
11
  CreateRequestModel,
11
- ContractorInfo
12
+ ContractorInfo,
13
+ InnerPageRequestCriteriaModel
12
14
  };
13
15
 
14
16
  module.exports = { services, models };
@@ -0,0 +1,17 @@
1
+ class InnerPageRequestCriteriaModel {
2
+ constructor({
3
+ projectIds = [],
4
+ recordTypes = [],
5
+ sortBy = '',
6
+ pageNo = 1
7
+ } = {}) {
8
+ this.projectIds = projectIds,
9
+ this.recordTypes = recordTypes,
10
+ this.sortBy = sortBy,
11
+ this.pageNo = pageNo;
12
+ }
13
+ }
14
+
15
+ module.exports = {
16
+ InnerPageRequestCriteriaModel
17
+ };
@@ -14,7 +14,8 @@ const Endpoints = {
14
14
  getUserEncryptedData: (email, userRole) => `${backendUrl}/saas/team-member/email/${email}/role/${userRole}/signup-data`,
15
15
  signupUser: `${backendUrl}/_saas/guests/signup`,
16
16
  removeAllUserTraceFromDb: userId => `${backendUrl}/saas/user/automation/${userId}`,
17
- userEmailNotificationsSettings: `${backendUrl}/saas/account/notification/set`
17
+ userEmailNotificationsSettings: `${backendUrl}/saas/account/notification/set`,
18
+ sendForgetPasswordMail: `${backendUrl}/_saas/forgotPassword`
18
19
  };
19
20
 
20
21
  const invite = (invitedUser, context, { disableSendMail = true } = {}) => {
@@ -68,6 +69,11 @@ const editUserEmailNotificationsSettings = (userId, notificationSettingsModel, c
68
69
  return requests.postRequestHandler(Endpoints.userEmailNotificationsSettings, notificationSettingsModel, context, {}, params);
69
70
  };
70
71
 
72
+ const sendForgetPasswordMail = userEmail => {
73
+ const body = { email: userEmail };
74
+ return requests.postRequestHandler(Endpoints.sendForgetPasswordMail, body);
75
+ };
76
+
71
77
  module.exports = {
72
78
  invite,
73
79
  signupUser,
@@ -80,5 +86,6 @@ module.exports = {
80
86
  editUserRole,
81
87
  editUserProjects,
82
88
  reinviteUser,
83
- editUserEmailNotificationsSettings
89
+ editUserEmailNotificationsSettings,
90
+ sendForgetPasswordMail
84
91
  };
@@ -91,6 +91,10 @@ const editUserEmailNotificationsSettings = (userId, notificationSettingsModel, c
91
91
  return userAPI.editUserEmailNotificationsSettings(userId, notificationSettingsModel, context);
92
92
  };
93
93
 
94
+ const sendForgetPasswordMail = userEmail => {
95
+ return userAPI.sendForgetPasswordMail(userEmail);
96
+ };
97
+
94
98
  module.exports = {
95
99
  inviteUser,
96
100
  signupUser,
@@ -104,5 +108,6 @@ module.exports = {
104
108
  editUserRole,
105
109
  editUserProjects,
106
110
  reinviteUser,
107
- editUserEmailNotificationsSettings
111
+ editUserEmailNotificationsSettings,
112
+ sendForgetPasswordMail
108
113
  };