@getjones/test-infra 2.6.3 → 2.6.5

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.3",
3
+ "version": "2.6.5",
4
4
  "description": "Providing internal and openapi interface",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,8 +1,9 @@
1
1
  const requests = require('../../saas/internal-api/requests');
2
- const { credentials } = require('../../../../../src/env');
2
+ 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,5 +1,7 @@
1
- const { ICS, PM, AUDITOR } = require('../../../../common/consts/userTypes');
2
-
3
- const UPLOADER_TYPES = { ICS, PM, AUDITOR };
1
+ const UPLOADER_TYPES = {
2
+ ICS: 'ICS',
3
+ PM: 'PM',
4
+ AUDITOR: 'AUDITOR'
5
+ };
4
6
 
5
7
  module.exports = UPLOADER_TYPES;
@@ -1,12 +1,6 @@
1
- const env = require('../../../../../env');
2
-
3
1
  const waiveApi = require('./waive.api');
4
2
  const { WaiveRequestModel, RetractRequestModel } = require('../../models/waive/waive.model');
5
3
  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');
10
4
 
11
5
  const waive = (waiveRequestModel, context) => {
12
6
  validateType(waiveRequestModel, WaiveRequestModel);
@@ -18,63 +12,39 @@ const retract = (retractRequestModel, context) => {
18
12
  return waiveApi.retract(retractRequestModel.contractorId, retractRequestModel, context);
19
13
  };
20
14
 
21
- const getWaiveModel = (
15
+ const getWaiveModel = async (
22
16
  record,
23
17
  policyName,
24
18
  attributeName,
25
19
  waiverReason,
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;
20
+ remarks
21
+ ) => {
22
+ const auditId = await getPolicyAuditIdFromRecord(record, policyName, attributeName);
34
23
 
35
24
  const waiveModel = new WaiveRequestModel({
25
+ userId: record.userId,
36
26
  contractorId: record.id,
37
27
  auditId,
38
28
  waiverReason,
39
- remarks,
40
- userId,
41
- userRole
29
+ remarks
42
30
  });
43
31
 
44
32
  return waiveModel;
45
33
  };
46
34
 
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;
35
+ const getRetractModel = async (record, policyName, attributeName) => {
36
+ const auditId = await getPolicyAuditIdFromRecord(record, policyName, attributeName);
66
37
 
67
38
  const retractModel = new RetractRequestModel({
39
+ userId: record.userId,
68
40
  contractorId: record.id,
69
- auditId,
70
- userId,
71
- userRole
41
+ auditId
72
42
  });
73
43
 
74
44
  return retractModel;
75
45
  };
76
46
 
77
- const getPolicyAuditIdFromRecord = (record, policyName, attributeName) => {
47
+ const getPolicyAuditIdFromRecord = async (record, policyName, attributeName) => {
78
48
  const policy = record.reviewbyAuditor.find(contractorCoverage =>
79
49
  contractorCoverage.insuranceName === policyName);
80
50
 
@@ -91,10 +61,4 @@ const getPolicyAuditIdFromRecord = (record, policyName, attributeName) => {
91
61
  return attribute.auditId;
92
62
  };
93
63
 
94
- module.exports = {
95
- waive,
96
- retract,
97
- getWaiveModel,
98
- getRetractModel,
99
- getWaiveModelByGap
100
- };
64
+ module.exports = { waive, retract, getWaiveModel, getRetractModel };
@@ -11,6 +11,14 @@ 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
+
14
22
  const VALID_SCORES = ['A+', 'A'];
15
23
 
16
24
  const AUDITOR_ROLE = 'Auditor';
@@ -66,6 +74,8 @@ module.exports = {
66
74
  ATTRIBUTE_NAMES_MAP,
67
75
  COI_AUDIT_STATUSES,
68
76
  AUDITOR_ROLE,
77
+ AUDIT_POLICY_NAMES,
78
+ AUDIT_ATTRIBUTE_NAMES,
69
79
  AUDIT_ENTITY_STATUSES,
70
80
  VALID_SCORES
71
81
  };
@@ -1,3 +1,5 @@
1
+ const DEFAULT_USER_ROLE = 'ICS';
2
+
1
3
  const WAIVE_ACTIONS = {
2
4
  WAIVE: 'ignored',
3
5
  RETRACT: 'notIgnored'
@@ -10,29 +12,24 @@ const WAIVER_REASONS = {
10
12
  };
11
13
 
12
14
  function WaiveRequestModel({
15
+ userId,
13
16
  contractorId,
14
17
  auditId,
15
18
  waiverReason,
16
- remarks,
17
- userId,
18
- userRole
19
+ remarks = '',
20
+ userRole = DEFAULT_USER_ROLE
19
21
  }) {
20
22
  this.auditorContractorId = auditId;
21
23
  this.contractorId = contractorId;
24
+ this.userId = userId;
22
25
  this.waiverReason = waiverReason;
23
- this.remarks = remarks || '';
26
+ this.remarks = remarks;
24
27
 
25
- this.userId = userId,
26
- this.userRole = userRole,
28
+ this.userRole = userRole;
27
29
  this.status = WAIVE_ACTIONS.WAIVE;
28
30
  }
29
31
 
30
- function RetractRequestModel({
31
- contractorId,
32
- auditId,
33
- userId,
34
- userRole
35
- }) {
32
+ function RetractRequestModel({ userId, contractorId, auditId, userRole = DEFAULT_USER_ROLE }) {
36
33
  this.auditorContractorId = auditId;
37
34
  this.contractorId = contractorId;
38
35
  this.userId = userId;
@@ -2,8 +2,6 @@ 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
-
7
5
  const { getEnv, getSystemUserIdentity } = require('../../../../env');
8
6
  const { credentials } = getEnv();
9
7
 
@@ -25,27 +23,6 @@ const getAttributeKey = attribute => {
25
23
  return specialAttributes[attribute] || attribute;
26
24
  };
27
25
 
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
-
49
26
  const getPolicyId = (policyName, requirement) => {
50
27
  if (!policyName || policyName === 'Certificate of Insurance') {
51
28
  return DEFAULT_POLICY_ID;
@@ -91,7 +68,7 @@ const parseAuditConfig = function(config) {
91
68
  }
92
69
 
93
70
  if (isArray(attributes[attributeName])) {
94
- selection.status = AUDIT_ENTITY_STATUSES[(attributes[attributeName][0]).toUpperCase()];
71
+ selection.status = AUDIT_ENTITY_STATUSES[ (attributes[attributeName][0]).toUpperCase() ];
95
72
  selection.value = attributes[attributeName][1].replace('$', emptyValue);
96
73
  } else {
97
74
  // Special statuses switch
@@ -103,7 +80,7 @@ const parseAuditConfig = function(config) {
103
80
  selection.status = AUDIT_ENTITY_STATUSES.YES;
104
81
  break;
105
82
  default:
106
- selection.status = AUDIT_ENTITY_STATUSES[(attributes[attributeName]).toUpperCase()];
83
+ selection.status = AUDIT_ENTITY_STATUSES[ (attributes[attributeName]).toUpperCase() ];
107
84
  break;
108
85
  }
109
86
 
@@ -121,10 +98,10 @@ const parseAuditConfig = function(config) {
121
98
  certificateEndorsmentsList.includes(field) && (selection.policyName = field);
122
99
 
123
100
  if (isArray(config[field])) {
124
- selection.status = AUDIT_ENTITY_STATUSES[(config[field][0]).toUpperCase()];
101
+ selection.status = AUDIT_ENTITY_STATUSES[ (config[field][0]).toUpperCase() ];
125
102
  selection.value = config[field][1]; // Ok to be undefined
126
103
  } else {
127
- selection.status = AUDIT_ENTITY_STATUSES[(config[field]).toUpperCase()] || AUDIT_ENTITY_STATUSES.YES;
104
+ selection.status = AUDIT_ENTITY_STATUSES[ (config[field]).toUpperCase() ] || AUDIT_ENTITY_STATUSES.YES;
128
105
  selection.value = getValueBySelection(config[field]);
129
106
  }
130
107
 
@@ -159,10 +136,7 @@ module.exports = {
159
136
  parseAuditConfig,
160
137
  getPolicyId,
161
138
  createAuditEntity,
162
- getAuditorId,
163
- getAttributeKey,
164
- getAttributeNameByGap,
165
- getWaiveReason
139
+ getAuditorId
166
140
  };
167
141
 
168
142
  const certificateEndorsmentsList = [
@@ -199,9 +173,3 @@ const specialAttributes = {
199
173
  'Umbrella': 'UMoccur'
200
174
  }
201
175
  };
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 = {
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- ICS: 'ICS',
3
- PM: 'PM',
4
- AUDITOR: 'AUDITOR'
5
- };