@getjones/test-infra 2.6.4 → 2.6.6

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.6.4",
3
+ "version": "2.6.6",
4
4
  "description": "Providing internal and openapi interface",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ ICS: 'ICS',
3
+ PM: 'PM',
4
+ AUDITOR: 'AUDITOR'
5
+ };
@@ -3,6 +3,7 @@ const { credentials } = require('../../../src/env');
3
3
  const coi = require('../../saas/internal-api/coi');
4
4
  const compliance = require('../../saas/internal-api/compliance');
5
5
  const auth = require('../../saas/internal-api/auth');
6
+ const contractors = require('../../saas/internal-api/contractors');
6
7
  const auditConfigs = require('../../defaults/configs/auditConfigs');
7
8
  const httpResponseStatusCodes = require('../../common/httpResponseStatusCodes.json');
8
9
  const timeUtils = require('../../common/utils/timeUtils');
@@ -12,7 +13,8 @@ const complianceStatuses = {
12
13
  complaint: 'complaint',
13
14
  notCompliant: 'notCompliant',
14
15
  expired: 'expired',
15
- aboutToExpired: 'aboutToExpired'
16
+ aboutToExpired: 'aboutToExpired',
17
+ awaitingNewCoi: 'awaitingNewCoi'
16
18
  };
17
19
 
18
20
  const prepareRecord = async (recordCompany, recordEmail, status, tabId, requirementId, context) => {
@@ -50,6 +52,7 @@ const prepareRecord = async (recordCompany, recordEmail, status, tabId, requirem
50
52
  let auditConfig;
51
53
  switch (status) {
52
54
  case complianceStatuses.notCompliant:
55
+ case complianceStatuses.awaitingNewCoi:
53
56
  auditConfig = auditConfigs.getNotCompliantConfig();
54
57
  break;
55
58
  case complianceStatuses.expired:
@@ -79,6 +82,8 @@ const prepareRecord = async (recordCompany, recordEmail, status, tabId, requirem
79
82
  if (auditResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
80
83
  throw Error(`Failed to audit record ${record.company}\n`, auditResponse);
81
84
  }
85
+
86
+ return requestData.id;
82
87
  };
83
88
 
84
89
  const prepareCompliantRecord = (recordCompany, recordEmail, tabId, requirementId, context) => {
@@ -97,9 +102,23 @@ const prepareAboutToExpiredRecord = (recordCompany, recordEmail, tabId, requirem
97
102
  return prepareRecord(recordCompany, recordEmail, complianceStatuses.aboutToExpired, tabId, requirementId, context);
98
103
  };
99
104
 
105
+ const prepareAwaitingNewCoiRecord = async (recordCompany, recordEmail, tabId, requirementId, context) => {
106
+ const prepareRecordId = await prepareRecord(recordCompany, recordEmail, complianceStatuses.awaitingNewCoi, tabId, requirementId, context);
107
+
108
+ const recordVerificationModel = await contractors.services.getRecordVerificationModel(prepareRecordId, context);
109
+ const sendGapsResponse = await contractors.services.sendGaps(recordVerificationModel, context);
110
+
111
+ if (sendGapsResponse.status !== httpResponseStatusCodes.OK) {
112
+ throw Error(`Failed to send gaps to ${recordCompany}\n`, sendGapsResponse);
113
+ }
114
+
115
+ return prepareRecordId;
116
+ };
117
+
100
118
  module.exports = {
101
119
  prepareCompliantRecord,
102
120
  prepareNotCompliantRecord,
103
121
  prepareExpiredRecord,
104
- prepareAboutToExpiredRecord
122
+ prepareAboutToExpiredRecord,
123
+ prepareAwaitingNewCoiRecord
105
124
  };
@@ -1,7 +1,5 @@
1
- const UPLOADER_TYPES = {
2
- ICS: 'ICS',
3
- PM: 'PM',
4
- AUDITOR: 'AUDITOR'
5
- };
1
+ const { ICS, PM, AUDITOR } = require('../../../../common/consts/userTypes');
2
+
3
+ const UPLOADER_TYPES = { ICS, PM, AUDITOR };
6
4
 
7
5
  module.exports = UPLOADER_TYPES;
@@ -1,6 +1,12 @@
1
+ const env = require('../../../../../env');
2
+
1
3
  const waiveApi = require('./waive.api');
2
4
  const { WaiveRequestModel, RetractRequestModel } = require('../../models/waive/waive.model');
3
5
  const { validateType } = require('../../../../../common/validations/typeValidations');
6
+ const util = require('../../utils/util');
7
+
8
+ const { credentials } = env.getEnv();
9
+ const userTypes = require('../../../../../common/consts/userTypes');
4
10
 
5
11
  const waive = (waiveRequestModel, context) => {
6
12
  validateType(waiveRequestModel, WaiveRequestModel);
@@ -12,39 +18,63 @@ const retract = (retractRequestModel, context) => {
12
18
  return waiveApi.retract(retractRequestModel.contractorId, retractRequestModel, context);
13
19
  };
14
20
 
15
- const getWaiveModel = async (
21
+ const getWaiveModel = (
16
22
  record,
17
23
  policyName,
18
24
  attributeName,
19
25
  waiverReason,
20
- remarks
21
- ) => {
22
- const auditId = await getPolicyAuditIdFromRecord(record, policyName, attributeName);
26
+ remarks,
27
+ {
28
+ userId,
29
+ userRole
30
+ } = {}) => {
31
+ const auditId = getPolicyAuditIdFromRecord(record, policyName, util.getAttributeKey(attributeName));
32
+ userId = userId || env.getSystemUserIdentity(credentials.superUser).id;
33
+ userRole = userRole || userTypes.ICS;
23
34
 
24
35
  const waiveModel = new WaiveRequestModel({
25
- userId: record.userId,
26
36
  contractorId: record.id,
27
37
  auditId,
28
38
  waiverReason,
29
- remarks
39
+ remarks,
40
+ userId,
41
+ userRole
30
42
  });
31
43
 
32
44
  return waiveModel;
33
45
  };
34
46
 
35
- const getRetractModel = async (record, policyName, attributeName) => {
36
- const auditId = await getPolicyAuditIdFromRecord(record, policyName, attributeName);
47
+ const getWaiveModelByGap = (
48
+ record,
49
+ policyName,
50
+ gap,
51
+ reason,
52
+ note,
53
+ {
54
+ userId,
55
+ userRole
56
+ } = {}) => {
57
+ const attributeName = util.getAttributeNameByGap(record, policyName, gap);
58
+
59
+ return getWaiveModel(record, policyName, attributeName, reason, note, { userId, userRole });
60
+ };
61
+
62
+ const getRetractModel = (record, policyName, attributeName) => {
63
+ const auditId = getPolicyAuditIdFromRecord(record, policyName, util.getAttributeKey(attributeName));
64
+ const userId = env.getSystemUserIdentity(credentials.superUser).id;
65
+ const userRole = userTypes.ICS;
37
66
 
38
67
  const retractModel = new RetractRequestModel({
39
- userId: record.userId,
40
68
  contractorId: record.id,
41
- auditId
69
+ auditId,
70
+ userId,
71
+ userRole
42
72
  });
43
73
 
44
74
  return retractModel;
45
75
  };
46
76
 
47
- const getPolicyAuditIdFromRecord = async (record, policyName, attributeName) => {
77
+ const getPolicyAuditIdFromRecord = (record, policyName, attributeName) => {
48
78
  const policy = record.reviewbyAuditor.find(contractorCoverage =>
49
79
  contractorCoverage.insuranceName === policyName);
50
80
 
@@ -61,4 +91,10 @@ const getPolicyAuditIdFromRecord = async (record, policyName, attributeName) =>
61
91
  return attribute.auditId;
62
92
  };
63
93
 
64
- module.exports = { waive, retract, getWaiveModel, getRetractModel };
94
+ module.exports = {
95
+ waive,
96
+ retract,
97
+ getWaiveModel,
98
+ getRetractModel,
99
+ getWaiveModelByGap
100
+ };
@@ -11,14 +11,6 @@ const AUDIT_ENTITY_STATUSES = {
11
11
  CLAIMS: 'Claims'
12
12
  };
13
13
 
14
- const AUDIT_ATTRIBUTE_NAMES = {
15
- CERTIFICATE_ISSUE_DATE: 'certIssueDate'
16
- };
17
-
18
- const AUDIT_POLICY_NAMES = {
19
- GENERAL_LIABILITY: ''
20
- };
21
-
22
14
  const VALID_SCORES = ['A+', 'A'];
23
15
 
24
16
  const AUDITOR_ROLE = 'Auditor';
@@ -74,8 +66,6 @@ module.exports = {
74
66
  ATTRIBUTE_NAMES_MAP,
75
67
  COI_AUDIT_STATUSES,
76
68
  AUDITOR_ROLE,
77
- AUDIT_POLICY_NAMES,
78
- AUDIT_ATTRIBUTE_NAMES,
79
69
  AUDIT_ENTITY_STATUSES,
80
70
  VALID_SCORES
81
71
  };
@@ -1,5 +1,3 @@
1
- const DEFAULT_USER_ROLE = 'ICS';
2
-
3
1
  const WAIVE_ACTIONS = {
4
2
  WAIVE: 'ignored',
5
3
  RETRACT: 'notIgnored'
@@ -12,24 +10,29 @@ const WAIVER_REASONS = {
12
10
  };
13
11
 
14
12
  function WaiveRequestModel({
15
- userId,
16
13
  contractorId,
17
14
  auditId,
18
15
  waiverReason,
19
- remarks = '',
20
- userRole = DEFAULT_USER_ROLE
16
+ remarks,
17
+ userId,
18
+ userRole
21
19
  }) {
22
20
  this.auditorContractorId = auditId;
23
21
  this.contractorId = contractorId;
24
- this.userId = userId;
25
22
  this.waiverReason = waiverReason;
26
- this.remarks = remarks;
23
+ this.remarks = remarks || '';
27
24
 
28
- this.userRole = userRole;
25
+ this.userId = userId,
26
+ this.userRole = userRole,
29
27
  this.status = WAIVE_ACTIONS.WAIVE;
30
28
  }
31
29
 
32
- function RetractRequestModel({ userId, contractorId, auditId, userRole = DEFAULT_USER_ROLE }) {
30
+ function RetractRequestModel({
31
+ contractorId,
32
+ auditId,
33
+ userId,
34
+ userRole
35
+ }) {
33
36
  this.auditorContractorId = auditId;
34
37
  this.contractorId = contractorId;
35
38
  this.userId = userId;
@@ -2,6 +2,8 @@ const { AUDIT_ENTITY_STATUSES, DEFAULT_POLICY_ID, VALID_SCORES } = require('../c
2
2
  const { isObject, isArray } = require('../../../../common/utils/dataTypeUtils');
3
3
  const timeUtils = require('../../../../common/utils/timeUtils');
4
4
  const auditModels = require('../models/audit/audit.model');
5
+ const waiveModels = require('../models/waive/waive.model');
6
+
5
7
  const { getEnv, getSystemUserIdentity } = require('../../../../env');
6
8
  const { credentials } = getEnv();
7
9
 
@@ -23,6 +25,27 @@ const getAttributeKey = attribute => {
23
25
  return specialAttributes[attribute] || attribute;
24
26
  };
25
27
 
28
+ const getWaiveReason = reason => {
29
+ return waiveReasons[reason] || reason;
30
+ };
31
+
32
+ const getAttributeNameByGap = function(record, policyName, gap) {
33
+ const policy = record.reviewbyAuditor.find(contractorCoverage =>
34
+ contractorCoverage.insuranceName === policyName);
35
+
36
+ if (!policy) {
37
+ throw new Error(`Policy name ${policyName} don't exist in record`);
38
+ }
39
+
40
+ const attribute = policy.errorList.find(error => error.errorHeadline === gap);
41
+
42
+ if (!attribute) {
43
+ throw new Error(`Gap ${gap} don't exist in record`);
44
+ }
45
+
46
+ return attribute.limitname;
47
+ };
48
+
26
49
  const getPolicyId = (policyName, requirement) => {
27
50
  if (!policyName || policyName === 'Certificate of Insurance') {
28
51
  return DEFAULT_POLICY_ID;
@@ -68,7 +91,7 @@ const parseAuditConfig = function(config) {
68
91
  }
69
92
 
70
93
  if (isArray(attributes[attributeName])) {
71
- selection.status = AUDIT_ENTITY_STATUSES[ (attributes[attributeName][0]).toUpperCase() ];
94
+ selection.status = AUDIT_ENTITY_STATUSES[(attributes[attributeName][0]).toUpperCase()];
72
95
  selection.value = attributes[attributeName][1].replace('$', emptyValue);
73
96
  } else {
74
97
  // Special statuses switch
@@ -80,7 +103,7 @@ const parseAuditConfig = function(config) {
80
103
  selection.status = AUDIT_ENTITY_STATUSES.YES;
81
104
  break;
82
105
  default:
83
- selection.status = AUDIT_ENTITY_STATUSES[ (attributes[attributeName]).toUpperCase() ];
106
+ selection.status = AUDIT_ENTITY_STATUSES[(attributes[attributeName]).toUpperCase()];
84
107
  break;
85
108
  }
86
109
 
@@ -98,10 +121,10 @@ const parseAuditConfig = function(config) {
98
121
  certificateEndorsmentsList.includes(field) && (selection.policyName = field);
99
122
 
100
123
  if (isArray(config[field])) {
101
- selection.status = AUDIT_ENTITY_STATUSES[ (config[field][0]).toUpperCase() ];
124
+ selection.status = AUDIT_ENTITY_STATUSES[(config[field][0]).toUpperCase()];
102
125
  selection.value = config[field][1]; // Ok to be undefined
103
126
  } else {
104
- selection.status = AUDIT_ENTITY_STATUSES[ (config[field]).toUpperCase() ] || AUDIT_ENTITY_STATUSES.YES;
127
+ selection.status = AUDIT_ENTITY_STATUSES[(config[field]).toUpperCase()] || AUDIT_ENTITY_STATUSES.YES;
105
128
  selection.value = getValueBySelection(config[field]);
106
129
  }
107
130
 
@@ -136,7 +159,10 @@ module.exports = {
136
159
  parseAuditConfig,
137
160
  getPolicyId,
138
161
  createAuditEntity,
139
- getAuditorId
162
+ getAuditorId,
163
+ getAttributeKey,
164
+ getAttributeNameByGap,
165
+ getWaiveReason
140
166
  };
141
167
 
142
168
  const certificateEndorsmentsList = [
@@ -173,3 +199,9 @@ const specialAttributes = {
173
199
  'Umbrella': 'UMoccur'
174
200
  }
175
201
  };
202
+
203
+ const waiveReasons = {
204
+ 'No Exposure': waiveModels.WAIVER_REASONS.NO_EXPOSURE,
205
+ 'Business Decision': waiveModels.WAIVER_REASONS.BUSINESS_DECISION,
206
+ 'Executive Approval': waiveModels.WAIVER_REASONS.EXECUTIVE_APPROVAL
207
+ };
@@ -122,6 +122,11 @@ const deleteAllRecordsInAccount = async (accountId, context, { activationStatus
122
122
  }
123
123
  };
124
124
 
125
+ const getRecordVerificationModel = async (recordId, context) => {
126
+ const { data: recordData } = await getContractorById(recordId, context);
127
+ return new RecordModifyDateVerificationModel(recordData.id, { contractorDateModified: recordData.dateModified });
128
+ };
129
+
125
130
  module.exports = {
126
131
  createContractor,
127
132
  changeRequirement,
@@ -143,5 +148,6 @@ module.exports = {
143
148
  muteNotifications,
144
149
  unmuteNotifications,
145
150
  deleteByContractorId,
146
- deleteAllRecordsInAccount
151
+ deleteAllRecordsInAccount,
152
+ getRecordVerificationModel
147
153
  };
@@ -26,7 +26,7 @@ const editRequestAndRecordDetails = (editRequestModel, context) => {
26
26
  return requests.postRequestHandler(Endpoints.edit(contractorId), editRequestModel, context, {}, params);
27
27
  };
28
28
 
29
- const getReqeustById = (requestId, context) => {
29
+ const getRequestById = (requestId, context) => {
30
30
  return requests.getRequestHandler(Endpoints.getById(requestId), {}, context);
31
31
  };
32
32
 
@@ -47,7 +47,7 @@ module.exports = {
47
47
  createRequest,
48
48
  inviteRequestViaPublicLink,
49
49
  editRequestAndRecordDetails,
50
- getReqeustById,
50
+ getRequestById,
51
51
  getRequestsByAccountId,
52
52
  getRequestsByTabId,
53
53
  requestsGlobalSearch
@@ -22,8 +22,8 @@ const getRequestsByTabId = (tabId, context, activityStatus = 'Active') => {
22
22
  return requestsAPI.getRequestsByTabId(tabId, context, activityStatus);
23
23
  };
24
24
 
25
- const getReqeustById = (requestId, context) => {
26
- return requestsAPI.getReqeustById(requestId, context);
25
+ const getRequestById = (requestId, context) => {
26
+ return requestsAPI.getRequestById(requestId, context);
27
27
  };
28
28
 
29
29
  const getRequestsByAccountId = (accountId, context, activationStatus) => {
@@ -76,7 +76,7 @@ module.exports = {
76
76
  inviteRequestViaPublicLink,
77
77
  editRequestAndRecordDetails,
78
78
  getRequestsByTabId,
79
- getReqeustById,
79
+ getRequestById,
80
80
  getRequestsByAccountId,
81
81
  getOrCreateRequest,
82
82
  getCreateRequestModel,
@@ -71,11 +71,12 @@ const getCreateRequirementModel = requirement => {
71
71
  return requirementUtils.getCreateRequirementModel(requirement);
72
72
  };
73
73
 
74
- const getUpdatedRequirementModel = async (requirementId, requirementPolicies, requirementName, accountId, projectId, tabId, context) => {
75
- const getRequirementData = await getRequirementByName(tabId, requirementName, context);
76
- const dateModified = getRequirementData.dateModified;
74
+ const getUpdatedRequirementModel = async (updatedRequirement, tabId, context) => {
75
+ const { name: requirementName } = updatedRequirement;
76
+ const existingRequirement = await getRequirementByName(tabId, requirementName, context);
77
+ updatedRequirement.dateModified = existingRequirement.dateModified;
77
78
 
78
- return requirementUtils.getUpdateRequirementModel(requirementId, requirementPolicies, requirementName, accountId, projectId, tabId, dateModified);
79
+ return requirementUtils.getUpdateRequirementModel(updatedRequirement);
79
80
  };
80
81
 
81
82
  module.exports = {
@@ -3,15 +3,12 @@ const { REQUIREMENT_SHARING_LEVELS } = require('../consts/consts');
3
3
  const { PolicyModel } = require('./policy.model');
4
4
 
5
5
  class UpdateRequirementModel {
6
- constructor(id, accountId, projectId, tabId, name, policies, dateModified) {
6
+ constructor({ id, name, policies, dateModified, sharingLevel = REQUIREMENT_SHARING_LEVELS.TAB }) {
7
7
  this.id = id;
8
- this.userId = accountId;
9
- this.projectId = projectId;
10
- this.tabId = tabId;
11
8
  this.name = name;
12
9
  this.policies = policies;
13
- this.sharingLevel = REQUIREMENT_SHARING_LEVELS.TAB;
14
10
  this.dateModified = dateModified;
11
+ this.sharingLevel = sharingLevel;
15
12
 
16
13
  validateType(policies, Array);
17
14
  policies && validateType(policies[0], PolicyModel);
@@ -3,7 +3,6 @@ const dataTypeUtils = require('../../../../common/utils/dataTypeUtils');
3
3
  const { UpdateRequirementModel } = require('../models/update.requirement.model');
4
4
  const { AttributeModel, PolicyModel, AttributeTypes } = require('../models/policy.model');
5
5
  const { CreateRequirementModel } = require('../models/create.requirement.model');
6
- const { REQUIREMENT_SHARING_LEVELS } = require('../consts/consts');
7
6
 
8
7
  const convertNumericValuesToNumberType = function(value) {
9
8
  if (dataTypeUtils.isString(value) && value.startsWith('$')) {
@@ -88,11 +87,13 @@ const getCreateRequirementModel = function(requirement) {
88
87
  return new CreateRequirementModel(name, policyModels, sharingLevel);
89
88
  };
90
89
 
91
- const getUpdateRequirementModel = function(requirementId, requirementPolicies, requirementName, accountId, projectId, tabId, dateModified) {
92
- const policies = parseRequirementConfig(requirementPolicies);
93
- const policyModels = policies.map(policy => getPolicyModel(policy));
90
+ const getUpdateRequirementModel = function(updatedRequirement) {
91
+ const { id, policies, name, sharingLevel, dateModified } = updatedRequirement;
94
92
 
95
- return new UpdateRequirementModel(requirementId, accountId, projectId, tabId, requirementName, policyModels, dateModified);
93
+ const parsedPolicies = parseRequirementConfig(policies);
94
+ const policyModels = parsedPolicies.map(policy => getPolicyModel(policy));
95
+
96
+ return new UpdateRequirementModel({ id, name, policies: policyModels, dateModified, sharingLevel });
96
97
  };
97
98
 
98
99
  module.exports = {