@getjones/test-infra 2.6.5 → 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.5",
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
+ };
@@ -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
+ };