@getjones/test-infra 2.12.6 → 2.13.0

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.12.6",
3
+ "version": "2.13.0",
4
4
  "description": "Providing internal and openapi interface",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -49,7 +49,9 @@ const attributeNames = {
49
49
  PrimaryNonContributoryEndorsement: 'Primary Non-Contributory Endorsement',
50
50
  indemnityPeriod: 'Indemnity Period',
51
51
  actualLossSustained: 'Actual Loss Sustained',
52
- extraExpense: 'Extra Expense'
52
+ extraExpense: 'Extra Expense',
53
+ combinedSingleLimit: 'Combined Single Limit'
54
+
53
55
  };
54
56
 
55
57
  module.exports = {
@@ -1,11 +1,14 @@
1
1
  const requests = require('../../../../../common/requests/cookieAuth/requests');
2
+ const internalRequests = require('../../../../../common/requests/internalAuth/requests');
3
+
2
4
  const { backendUrl } = require('../../../../../env').getEnv();
3
5
 
4
6
  const Endpoints = {
5
7
  getAccount: `${backendUrl}/saas/accounts`,
6
8
  create: `${backendUrl}/saas/createaccount`,
7
9
  delete: `${backendUrl}/saas/account`,
8
- edit: accountId => `${backendUrl}/saas/account/${accountId}/settings`
10
+ edit: accountId => `${backendUrl}/saas/account/${accountId}/settings`,
11
+ getFromCertificateHolder: certificateHolder => `${backendUrl}/jcsc/account/certificate-holder-name/${certificateHolder}`
9
12
  };
10
13
 
11
14
  const create = (account, context) => {
@@ -25,4 +28,8 @@ const getByName = (accountName, context) => {
25
28
  return requests.getRequestHandler(Endpoints.getAccount, params, context);
26
29
  };
27
30
 
28
- module.exports = { create, getByName, deleteAccount, updateAccountSettings };
31
+ const getFromCertificateHolder = certificateHolder => {
32
+ return internalRequests.getRequestHandler(Endpoints.getFromCertificateHolder(certificateHolder), {});
33
+ };
34
+
35
+ module.exports = { create, getByName, deleteAccount, updateAccountSettings, getFromCertificateHolder };
@@ -72,11 +72,22 @@ const deleteAccountById = async (accountId, context) => {
72
72
  return accountsAPI.deleteAccount(accountId, context);
73
73
  };
74
74
 
75
+ const getFromCertificateHolder = async certificateHolder => {
76
+ const response = await accountsAPI.getFromCertificateHolder(certificateHolder);
77
+
78
+ if (response.status !== httpResponseStatusCodes.OK) {
79
+ throw Error(`Failed to get account by certificate holder: ${certificateHolder} - Response: ${response.status}`);
80
+ }
81
+
82
+ return response.data;
83
+ };
84
+
75
85
  module.exports = {
76
86
  getAccount,
77
87
  getOrCreateAccount,
78
88
  getAccountId,
79
89
  createAccount,
80
90
  deleteAccountByName,
81
- deleteAccountById
91
+ deleteAccountById,
92
+ getFromCertificateHolder
82
93
  };
@@ -1,5 +1,6 @@
1
+ const api = require('./api/customer.rules.api');
1
2
  const services = require('./api/customer.rules.service');
2
3
  const models = require('./models/customer.rule.model');
3
4
  const consts = require('./consts/customer.rule');
4
5
 
5
- module.exports = { services, models, consts };
6
+ module.exports = { api, services, models, consts };
@@ -1,13 +1,12 @@
1
1
  const requests = require('../../../../../common/requests/cookieAuth/requests');
2
2
  const { backendUrl } = require('../../../../../env').getEnv();
3
3
 
4
- const { convertDateStringFormatToISOString } = require('../../../../../common/utils/timeUtils');
5
-
6
4
  const Endpoints = {
7
5
  auditorContractorList: `${backendUrl}/saas/auditor/contractors`,
8
6
  audit: `${backendUrl}/saas/auditor/contractors/submit/audits`,
9
7
  enterAudit: contractorId => `${backendUrl}/saas/auditor/contractors/${contractorId}/master-audit`,
10
8
  getAuditRecordModelByRecordId: recordId => `${backendUrl}/saas/auditor/record/${recordId}/audit-record`,
9
+ getComplianceJsonByRecordId: recordId => `${backendUrl}/saas/contractors/${recordId}/compliance-json`,
11
10
  requirementDetailsForAudit: contractorId => `${backendUrl}/saas/auditor/contractor/${contractorId}/requirement`,
12
11
  isReaudit: contractorId => `${backendUrl}/saas/auditor/contractors/${contractorId}/isreaudit`,
13
12
  revertCoi: contractorId => `${backendUrl}/saas/auditor/contractors/${contractorId}/coi/revert`,
@@ -78,6 +77,10 @@ const updateComplianceAuditActionsDate = (recordId, dateOffset, context) => {
78
77
  return requests.putRequestHandler(url, {}, context);
79
78
  };
80
79
 
80
+ const getComplianceJson = (recordId, context) => {
81
+ return requests.getRequestHandler(Endpoints.getComplianceJsonByRecordId(recordId), {}, context);
82
+ };
83
+
81
84
  module.exports = {
82
85
  audit,
83
86
  submitAudit,
@@ -88,6 +91,7 @@ module.exports = {
88
91
  enterAudit,
89
92
  getAuditRecordModel,
90
93
  getRequirementDetailsForAudit,
94
+ getComplianceJson,
91
95
  getAuditByRecordId,
92
96
  putAuditOnHold,
93
97
  resumeAudit,
@@ -197,6 +197,16 @@ const updateComplianceAuditActionsDate = (recordId, dateOffset, context) => {
197
197
  return auditApi.updateComplianceAuditActionsDate(recordId, dateOffset, context);
198
198
  };
199
199
 
200
+ const getComplianceJson = async function(recordId, context) {
201
+ const getComplianceJsonResponse = await auditApi.getComplianceJson(recordId, context);
202
+
203
+ if (getComplianceJsonResponse.status !== httpResponseStatusCodes.OK) {
204
+ throw Error(`Failed to get compliance audit json response\n${getComplianceJsonResponse}`);
205
+ }
206
+
207
+ return getComplianceJsonResponse.data;
208
+ };
209
+
200
210
  module.exports = {
201
211
  audit,
202
212
  submitAudit,
@@ -211,6 +221,7 @@ module.exports = {
211
221
  getAuditMetadata,
212
222
  getAuditByRecordId,
213
223
  getAuditRequestModel,
224
+ getComplianceJson,
214
225
  auditRecord,
215
226
  putAuditOnHold,
216
227
  resumeAudit,
@@ -61,7 +61,8 @@ const ATTRIBUTE_NAMES_MAP = {
61
61
  signature: 'signature',
62
62
  indemnityPeriod: 'Indemnity Period',
63
63
  actualLossSustained: 'Actual Loss Sustained',
64
- extraExpense: 'Extra Expense'
64
+ extraExpense: 'Extra Expense',
65
+ combinedSingleLimit: 'Combined Single Limit'
65
66
  };
66
67
 
67
68
  const auditTriggerType = {
@@ -27,7 +27,8 @@ const Endpoints = {
27
27
  assignRequirement: requestId => `${backendUrl}/saas/contractor/${requestId}/assign-requirement`,
28
28
  linkedProjectsCount: recordId => `${backendUrl}/saas/record/count/${recordId}/linked-projects`,
29
29
  verifyInviteLink: encryptedData => `${backendUrl}/vendor-app/verify-link?data=${encryptedData}`,
30
- getBasicDetailsById: recordId => `${backendUrl}/jcsc/record/${recordId}`
30
+ getBasicDetailsById: recordId => `${backendUrl}/jcsc/record/${recordId}`,
31
+ getRecordsFromInsuredName: (insuredName, accountIds) => `${backendUrl}/jcsc/record/insured-name/${insuredName}?accountIds=${accountIds}`
31
32
  };
32
33
 
33
34
  const getContractorsByAccountId = (params, context) => {
@@ -139,6 +140,16 @@ const getBasicDetailsById = recordId => {
139
140
  return internalRequests.getRequestHandler(Endpoints.getBasicDetailsById(recordId), {});
140
141
  };
141
142
 
143
+ const getRecordsFromInsuredName = (insuredName, accountIds) => {
144
+ let accountIdsStr = '';
145
+
146
+ if (accountIds && accountIds.length > 0) {
147
+ accountIdsStr = accountIds.join(',');
148
+ }
149
+
150
+ return internalRequests.getRequestHandler(Endpoints.getRecordsFromInsuredName(insuredName, accountIdsStr), {});
151
+ };
152
+
142
153
  module.exports = {
143
154
  changeRequirement,
144
155
  assignRequirement,
@@ -163,5 +174,6 @@ module.exports = {
163
174
  getLinkedProjectsCount,
164
175
  updateLastInviteActionDate,
165
176
  getInviteLinkStatus,
166
- getBasicDetailsById
177
+ getBasicDetailsById,
178
+ getRecordsFromInsuredName
167
179
  };
@@ -189,6 +189,16 @@ const getBasicDetailsById = async recordId => {
189
189
  return response.data;
190
190
  };
191
191
 
192
+ const getRecordsFromInsuredName = async (insuredName, accountIds) => {
193
+ const response = await contractorsAPI.getRecordsFromInsuredName(insuredName, accountIds);
194
+
195
+ if (response.status !== httpResponseStatusCodes.OK) {
196
+ throw Error(`Failed to get records from insured name: ${insuredName} and accountIds: ${accountIds} - Response: ${response.status}`);
197
+ }
198
+
199
+ return response.data;
200
+ };
201
+
192
202
  module.exports = {
193
203
  changeRequirement,
194
204
  getContractorsByAccountId,
@@ -219,5 +229,6 @@ module.exports = {
219
229
  updateLastInviteActionDate,
220
230
  getInviteLinkStatus,
221
231
  getContractorDetailsModel,
222
- getBasicDetailsById
232
+ getBasicDetailsById,
233
+ getRecordsFromInsuredName
223
234
  };
@@ -1,8 +1,8 @@
1
1
  const getMentionedNoteContent = (usersArray, noteContent = '', { multipleParagraphs } = {}) => {
2
2
  for (const user of usersArray) {
3
- const newContent = `<span class="mention" data-name="${user.fullName}" data-id="${user.id}" draggable="false"><span contenteditable="false">@${user.fullName}</span></span>`;
3
+ const newContent = `<span class="mention" data-full-name="${user.fullName}" data-id="${user.id}" draggable="false"><span contenteditable="false">@${user.fullName}</span></span>`;
4
4
  noteContent += multipleParagraphs ? `<p>${newContent}</p>` : newContent;
5
- };
5
+ }
6
6
  noteContent = multipleParagraphs ? noteContent : `<p>${noteContent}</p>`;
7
7
  return noteContent;
8
8
  };
@@ -53,9 +53,9 @@ const getRequestsByAccountId = (accountId, context, activationStatus) => {
53
53
  return requestsAPI.getRequestsByAccountId(accountId, context, params);
54
54
  };
55
55
 
56
- const getCreateRequestModel = (requirementId, contractor, { tabId, publicLink, sendMail, requirementDateModified } = {}) => {
56
+ const getCreateRequestModel = (requirementId, contractor, { tabId, publicLink, sendMail, requirementDateModified, isDraft } = {}) => {
57
57
  const { recordType, email, companyName, additionalEmails } = contractor;
58
- const contractorInfoModel = new ContractorInfo(recordType, email, companyName, additionalEmails);
58
+ const contractorInfoModel = new ContractorInfo(recordType, email, companyName, additionalEmails, isDraft);
59
59
 
60
60
  return new CreateRequestModel(
61
61
  requirementId,
@@ -70,7 +70,7 @@ const getCreateRequestModel = (requirementId, contractor, { tabId, publicLink, s
70
70
  );
71
71
  };
72
72
 
73
- const getOrCreateRequest = async (context, tabId, requirementId, contractor, activationStatus, { sendMail, requirementDateModified } = {}) => {
73
+ const getOrCreateRequest = async (context, tabId, requirementId, contractor, activationStatus, { sendMail, requirementDateModified, isDraft } = {}) => {
74
74
  const { data: existingRequests } = await getRequestsByTabId(tabId, context, activationStatus);
75
75
 
76
76
  const filteredRequests = Array.isArray(existingRequests) ? existingRequests.filter(({ record }) =>
@@ -80,7 +80,7 @@ const getOrCreateRequest = async (context, tabId, requirementId, contractor, act
80
80
  return filteredRequests[0];
81
81
  }
82
82
 
83
- const createContractorModel = getCreateRequestModel(requirementId, contractor, { tabId, sendMail, requirementDateModified });
83
+ const createContractorModel = getCreateRequestModel(requirementId, contractor, { tabId, sendMail, requirementDateModified, isDraft });
84
84
  const createContractorResponse = await createRequest(createContractorModel, context);
85
85
  return createContractorResponse.data;
86
86
  };
@@ -21,12 +21,13 @@ class CreateRequestModel {
21
21
  }
22
22
 
23
23
  class ContractorInfo {
24
- constructor(recordType, email, companyName, additionalEmails) {
24
+ constructor(recordType, email, companyName, additionalEmails, isDraft) {
25
25
  this.recordType = recordType;
26
26
  this.email = email;
27
27
  this.companyName = companyName;
28
28
  this.title = email;
29
29
  this.additionalEmails = additionalEmails;
30
+ this.isDraft = isDraft;
30
31
  }
31
32
  }
32
33
 
@@ -75,6 +75,8 @@ const deleteRequirementByName = async (requirementName, tabId, context) => {
75
75
 
76
76
  const deleteAllRequirementsInTabs = async (tabIds, context) => {
77
77
  const failedToDeleteRequirements = [];
78
+ const successfulDeleteRes = [];
79
+
78
80
  for (const tabId of tabIds) {
79
81
  const { data: existingRequirements } = await getRequirementsByTabId(tabId, context);
80
82
 
@@ -85,12 +87,18 @@ const deleteAllRequirementsInTabs = async (tabIds, context) => {
85
87
  console.error('Failed to delete requirement: ', requirement.id);
86
88
  failedToDeleteRequirements.push(response);
87
89
  }
90
+
91
+ if (response.status === httpResponseStatusCodes.OK) {
92
+ successfulDeleteRes.push(response.data.result);
93
+ }
88
94
  }
89
95
  }
90
96
 
91
97
  if (failedToDeleteRequirements.length) {
92
98
  throw Error(`Failed to delete ${failedToDeleteRequirements.length} of ${existingRequirements.length} requirements in account. Failed with status: ${ failedToDeleteRequirements[0].status }`);
93
99
  }
100
+
101
+ return successfulDeleteRes;
94
102
  };
95
103
 
96
104
  const getCreateRequirementModel = requirement => {
@@ -5,16 +5,17 @@ const { AttributeModel, PolicyModel, AttributeTypes } = require('../models/polic
5
5
  const { CreateRequirementModel } = require('../models/create.requirement.model');
6
6
 
7
7
  const customAttributes = {
8
- Including: 'multiple',
9
- indemnityPeriod: 'Indemnity Period'
8
+ Including: 'multiple' //because attributeTypes.multiple => 'Multiple' with capital M
10
9
  };
11
10
 
11
+ const numericAttributes = ['Indemnity Period', 'Notice of Cancellation', 'Notice of Cancellation Endorsement'];
12
+
12
13
  const convertNumericValuesToNumberType = function(value, attributeName) {
13
14
  if (dataTypeUtils.isString(value) && value.startsWith('$')) {
14
15
  return Number(value.replace(/[$,]/g, ''));
15
16
  }
16
17
 
17
- if (attributeName === customAttributes.indemnityPeriod) {
18
+ if (numericAttributes.includes(attributeName)) {
18
19
  return Number(value);
19
20
  }
20
21
 
@@ -25,7 +26,7 @@ const preparePolicyAttributesTypes = function(value, attributeName) {
25
26
  const attributesValue = convertNumericValuesToNumberType(value, attributeName);
26
27
 
27
28
  if (dataTypeUtils.isNumber(attributesValue)) {
28
- return attributeName === customAttributes.indemnityPeriod ?
29
+ return numericAttributes.includes(attributeName) ?
29
30
  AttributeTypes.get(attributeTypes.numeric) :
30
31
  AttributeTypes.get(attributeTypes.limit);
31
32
  }
@@ -1,3 +1,5 @@
1
+ const { expect } = require('chai');
2
+
1
3
  const { getEnv } = require('../../../../../env');
2
4
  const httpResponseStatusCodes = require('../../../../../common/httpResponseStatusCodes.json');
3
5
 
@@ -7,6 +9,7 @@ const { InviteTenantUserModel } = require('../../models/tenent.user.model');
7
9
  const { validateType } = require('../../../../../common/validations/typeValidations');
8
10
  const tenantAPI = require('./tenant.app.api');
9
11
  const util = require('../../utils/util');
12
+ const users = require('../users.service');
10
13
 
11
14
  const inviteTenantUser = (projectId, invitedTenantUser, context) => {
12
15
  validateType(invitedTenantUser, InviteTenantUserModel);
@@ -70,9 +73,21 @@ const getOrCreateTenantUser = async (projectId, email, company, requestId, conte
70
73
  return tenantUser;
71
74
  };
72
75
 
76
+ const removeAllTenantUsersFromProject = async (projectId, context) => {
77
+ const tenantsListInProjects = await getTenantUsersByProjectId(projectId, context);
78
+ for (const tenant of tenantsListInProjects) {
79
+ const deleteInviteResponse = await removeTenantUser(projectId, tenant.subuserId, context);
80
+ expect(deleteInviteResponse.status, 'Failed to delete user invite').to.equal(httpResponseStatusCodes.OK);
81
+
82
+ const deleteUserResponse = await users.removeAllUserTraceFromDb(tenant.subuserId, context);
83
+ expect(deleteUserResponse.status, 'Failed to completely delete user from DB').to.equal(httpResponseStatusCodes.NO_CONTENT);
84
+ }
85
+ };
86
+
73
87
  module.exports = {
74
88
  inviteTenantUser,
75
89
  getTenantUsersByProjectId,
76
90
  getOrCreateTenantUser,
77
- removeTenantUser
91
+ removeTenantUser,
92
+ removeAllTenantUsersFromProject
78
93
  };
@@ -62,6 +62,11 @@ const restoreRequest = (apiKey, requestId) => {
62
62
  return requests.putRequestHandler(endpoint, apiKey);
63
63
  };
64
64
 
65
+ const deleteRequest = (apiKey, requestId) => {
66
+ const endpoint = Endpoints.requestById(requestId);
67
+ return requests.deleteRequestHandler(endpoint, apiKey);
68
+ };
69
+
65
70
  module.exports = {
66
71
  inviteRequest,
67
72
  getAllRequests,
@@ -72,5 +77,6 @@ module.exports = {
72
77
  updateRequest,
73
78
  archiveRequest,
74
79
  restoreRequest,
80
+ deleteRequest,
75
81
  changeRequirement
76
82
  };
@@ -51,6 +51,10 @@ const restoreRequest = (apiKey, id) => {
51
51
  return requestsApi.restoreRequest(apiKey, id);
52
52
  };
53
53
 
54
+ const deleteRequest = (apiKey, id) => {
55
+ return requestsApi.deleteRequest(apiKey, id);
56
+ };
57
+
54
58
  module.exports = {
55
59
  inviteRequest,
56
60
  getAllAccountRequests,
@@ -60,6 +64,7 @@ module.exports = {
60
64
  getRequestPolicies,
61
65
  archiveRequest,
62
66
  restoreRequest,
67
+ deleteRequest,
63
68
  updateRequest,
64
69
  changeRequirement
65
70
  };