@getjones/test-infra 4.4.13 → 4.4.14

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.
Files changed (231) hide show
  1. package/package.json +30 -30
  2. package/src/common/commonFlows/auth/auth.js +40 -40
  3. package/src/common/commonFlows/index.js +4 -4
  4. package/src/common/commonFlows/records/records.js +243 -243
  5. package/src/common/consts/accountSettings.js +14 -14
  6. package/src/common/consts/activationStatuses.js +6 -6
  7. package/src/common/consts/autocomplete.js +10 -10
  8. package/src/common/consts/constantsForRecordsSortingAndFilters.js +40 -40
  9. package/src/common/consts/dashboardCharts.js +18 -18
  10. package/src/common/consts/ocrStatuses.js +6 -6
  11. package/src/common/consts/projectSettings.js +21 -21
  12. package/src/common/consts/recordTypes.js +5 -5
  13. package/src/common/consts/s3FileTypes.js +13 -13
  14. package/src/common/consts/userRoles.js +6 -6
  15. package/src/common/consts/userTypes.js +8 -8
  16. package/src/common/errorCodes.js +3 -3
  17. package/src/common/httpResponseStatusCodes.json +11 -11
  18. package/src/common/httpResponseTypes.json +2 -2
  19. package/src/common/requests/apiKeyAuth/requests.js +44 -44
  20. package/src/common/requests/cookieAuth/requests.js +40 -40
  21. package/src/common/requests/internalAuth/requests.js +48 -48
  22. package/src/common/requests/requestHandlers.js +80 -80
  23. package/src/common/utils/complianceUtil.js +114 -114
  24. package/src/common/utils/configsUtil.js +22 -22
  25. package/src/common/utils/dataTypeUtils.js +41 -41
  26. package/src/common/utils/numberUtils.js +22 -22
  27. package/src/common/utils/objectUtils.js +7 -7
  28. package/src/common/utils/timeUtils.js +177 -177
  29. package/src/common/validations/errorValidation.js +16 -16
  30. package/src/common/validations/typeValidations.js +36 -36
  31. package/src/defaults/configs/auditConfigs.js +125 -125
  32. package/src/defaults/configs/coverage.js +227 -227
  33. package/src/defaults/configs/polices.js +75 -75
  34. package/src/defaults/configs/requirement.js +32 -32
  35. package/src/defaults/index.js +6 -6
  36. package/src/env.js +57 -57
  37. package/src/factory/globalRecord/globalRecord.js +43 -43
  38. package/src/factory/index.js +8 -8
  39. package/src/factory/records/records.js +229 -229
  40. package/src/factory/users/users.js +86 -86
  41. package/src/index.js +97 -97
  42. package/src/saas/internal-api/accountDirectory/api/accountDirectory.api.js +50 -50
  43. package/src/saas/internal-api/accountDirectory/api/accountDirectory.service.js +182 -182
  44. package/src/saas/internal-api/accountDirectory/index.js +4 -4
  45. package/src/saas/internal-api/accountDirectory/models/accountDirectory.model.js +40 -40
  46. package/src/saas/internal-api/accounts/api/core/accounts.core.api.js +35 -35
  47. package/src/saas/internal-api/accounts/api/core/accounts.core.service.js +93 -93
  48. package/src/saas/internal-api/accounts/api/emailCustomization/accounts.email.customizations.api.js +29 -29
  49. package/src/saas/internal-api/accounts/api/emailCustomization/accounts.email.customizations.service.js +61 -61
  50. package/src/saas/internal-api/accounts/api/openapi/accounts.openapi.api.js +48 -48
  51. package/src/saas/internal-api/accounts/api/openapi/accounts.openapi.service.js +74 -74
  52. package/src/saas/internal-api/accounts/api/settings/settings.api.js +21 -21
  53. package/src/saas/internal-api/accounts/api/settings/settings.service.js +41 -41
  54. package/src/saas/internal-api/accounts/consts/consts.js +8 -8
  55. package/src/saas/internal-api/accounts/index.js +22 -22
  56. package/src/saas/internal-api/accounts/models/core/create.account.model.js +16 -16
  57. package/src/saas/internal-api/accounts/models/settings/update.settings.model.js +42 -42
  58. package/src/saas/internal-api/accounts/utils/utils.js +60 -60
  59. package/src/saas/internal-api/agreement/api/agreement.api.js +39 -39
  60. package/src/saas/internal-api/agreement/api/agreement.service.js +121 -121
  61. package/src/saas/internal-api/agreement/consts/consts.js +10 -10
  62. package/src/saas/internal-api/agreement/index.js +12 -12
  63. package/src/saas/internal-api/agreement/models/create.agreement.model.js +12 -12
  64. package/src/saas/internal-api/agreement/models/createAgreementByAuditorModel.js +11 -11
  65. package/src/saas/internal-api/agreement/models/createAgreementByPMModel.js +13 -13
  66. package/src/saas/internal-api/auditCustomerRules/api/customer.rules.api.js +43 -43
  67. package/src/saas/internal-api/auditCustomerRules/api/customer.rules.service.js +105 -105
  68. package/src/saas/internal-api/auditCustomerRules/consts/customer.rule.js +11 -11
  69. package/src/saas/internal-api/auditCustomerRules/index.js +6 -6
  70. package/src/saas/internal-api/auditCustomerRules/models/customer.rule.model.js +46 -46
  71. package/src/saas/internal-api/auditCustomerRules/utils/customer.rule.util.js +19 -19
  72. package/src/saas/internal-api/auditNotes/api/audit.notes.api.js +40 -40
  73. package/src/saas/internal-api/auditNotes/api/audit.notes.service.js +115 -115
  74. package/src/saas/internal-api/auditNotes/index.js +4 -4
  75. package/src/saas/internal-api/auditNotes/models/audit.note.model.js +30 -30
  76. package/src/saas/internal-api/auth/api/auth.api.js +27 -27
  77. package/src/saas/internal-api/auth/api/auth.service.js +90 -90
  78. package/src/saas/internal-api/auth/index.js +3 -3
  79. package/src/saas/internal-api/coi/api/coi.api.js +45 -45
  80. package/src/saas/internal-api/coi/api/coi.service.js +39 -39
  81. package/src/saas/internal-api/coi/consts/hashes.js +4 -4
  82. package/src/saas/internal-api/coi/consts/uploaderTypes.js +5 -5
  83. package/src/saas/internal-api/coi/index.js +14 -14
  84. package/src/saas/internal-api/coi/models/Combine.last.two.cois.model.js +25 -25
  85. package/src/saas/internal-api/coi/models/submit.coi.model.js +19 -19
  86. package/src/saas/internal-api/coi/utils/utils.js +117 -117
  87. package/src/saas/internal-api/compliance/api/audit/audit.api.js +115 -115
  88. package/src/saas/internal-api/compliance/api/audit/audit.service.js +300 -300
  89. package/src/saas/internal-api/compliance/api/convert/convert.api.js +17 -17
  90. package/src/saas/internal-api/compliance/api/convert/convert.service.js +11 -11
  91. package/src/saas/internal-api/compliance/api/coverage/coverage.api.js +33 -33
  92. package/src/saas/internal-api/compliance/api/coverage/coverage.service.js +48 -48
  93. package/src/saas/internal-api/compliance/api/overrideGap/override.gap.api.js +38 -38
  94. package/src/saas/internal-api/compliance/api/overrideGap/override.gap.service.js +182 -182
  95. package/src/saas/internal-api/compliance/consts/audit.js +111 -111
  96. package/src/saas/internal-api/compliance/index.js +33 -33
  97. package/src/saas/internal-api/compliance/models/audit/audit.model.js +96 -96
  98. package/src/saas/internal-api/compliance/models/waive/waive.model.js +49 -49
  99. package/src/saas/internal-api/compliance/utils/auditUtil.js +254 -254
  100. package/src/saas/internal-api/compliance/utils/coverageUtil.js +40 -40
  101. package/src/saas/internal-api/contractors/api/contractors.api.js +209 -209
  102. package/src/saas/internal-api/contractors/api/contractors.service.js +361 -361
  103. package/src/saas/internal-api/contractors/consts/consts.js +6 -6
  104. package/src/saas/internal-api/contractors/index.js +8 -8
  105. package/src/saas/internal-api/contractors/models/assign.requirement.model.js +10 -10
  106. package/src/saas/internal-api/contractors/models/edit.contractor.model.js +62 -62
  107. package/src/saas/internal-api/contractors/models/link.request.model.js +10 -10
  108. package/src/saas/internal-api/contractors/models/subscription.contractor.model.js +13 -13
  109. package/src/saas/internal-api/contractors/models/verification.contractor.model.js +27 -27
  110. package/src/saas/internal-api/contractors/utils.js +25 -25
  111. package/src/saas/internal-api/dashboard/api/recordList.api.js +38 -38
  112. package/src/saas/internal-api/dashboard/api/recordList.service.js +60 -60
  113. package/src/saas/internal-api/dashboard/index.js +5 -5
  114. package/src/saas/internal-api/dashboard/models/dashboard.filter.criteria.model.js +38 -38
  115. package/src/saas/internal-api/dbEmails/api/db.emails.api.js +25 -25
  116. package/src/saas/internal-api/dbEmails/api/db.emails.service.js +156 -156
  117. package/src/saas/internal-api/dbEmails/consts/consts.js +55 -55
  118. package/src/saas/internal-api/dbEmails/index.js +6 -6
  119. package/src/saas/internal-api/dbEmails/models/db.emails.model.js +22 -22
  120. package/src/saas/internal-api/dbEmails/utils/util.js +87 -87
  121. package/src/saas/internal-api/emailCustomization/api/email.customization.api.js +26 -26
  122. package/src/saas/internal-api/emailCustomization/api/email.customization.service.js +50 -50
  123. package/src/saas/internal-api/emailCustomization/index.js +3 -3
  124. package/src/saas/internal-api/globalRecord/api/global.record.api.js +95 -101
  125. package/src/saas/internal-api/globalRecord/api/global.record.service.js +112 -117
  126. package/src/saas/internal-api/globalRecord/consts.js +20 -20
  127. package/src/saas/internal-api/globalRecord/index.js +6 -6
  128. package/src/saas/internal-api/globalRecord/models/global.record.model.js +60 -60
  129. package/src/saas/internal-api/globalRecord/utils/util.js +161 -161
  130. package/src/saas/internal-api/homepageCharts/api/charts.api.js +12 -12
  131. package/src/saas/internal-api/homepageCharts/api/charts.service.js +7 -7
  132. package/src/saas/internal-api/homepageCharts/index.js +3 -3
  133. package/src/saas/internal-api/policyFile/api/policy.file.api.js +25 -25
  134. package/src/saas/internal-api/policyFile/api/policy.file.service.js +39 -39
  135. package/src/saas/internal-api/policyFile/consts.js +21 -21
  136. package/src/saas/internal-api/policyFile/index.js +11 -11
  137. package/src/saas/internal-api/policyFile/models/create.policy.file.model.js +11 -11
  138. package/src/saas/internal-api/projects/api/core/projects.api.js +39 -39
  139. package/src/saas/internal-api/projects/api/core/projects.service.js +77 -77
  140. package/src/saas/internal-api/projects/api/settings/project.settings.api.js +18 -18
  141. package/src/saas/internal-api/projects/api/settings/project.settings.service.js +35 -35
  142. package/src/saas/internal-api/projects/consts/defaultProject.js +3 -3
  143. package/src/saas/internal-api/projects/index.js +24 -24
  144. package/src/saas/internal-api/projects/models/core/create.project.model.js +41 -41
  145. package/src/saas/internal-api/projects/models/core/update.project.model.js +47 -47
  146. package/src/saas/internal-api/projects/models/settings/update.project.settings.model.js +40 -40
  147. package/src/saas/internal-api/projects/utils/utils.js +155 -155
  148. package/src/saas/internal-api/recordHub/api/record.hub.api.js +14 -14
  149. package/src/saas/internal-api/recordHub/api/record.hub.service.js +21 -21
  150. package/src/saas/internal-api/recordHub/index.js +3 -3
  151. package/src/saas/internal-api/recordNotes/api/record.notes.api.js +38 -38
  152. package/src/saas/internal-api/recordNotes/api/record.notes.service.js +47 -47
  153. package/src/saas/internal-api/recordNotes/api/record.notes.utils.js +12 -12
  154. package/src/saas/internal-api/recordNotes/index.js +3 -3
  155. package/src/saas/internal-api/reports/api/reports.api.js +62 -62
  156. package/src/saas/internal-api/reports/api/reports.service.js +79 -79
  157. package/src/saas/internal-api/reports/consts/consts.js +74 -74
  158. package/src/saas/internal-api/reports/index.js +15 -15
  159. package/src/saas/internal-api/reports/models/report.model.js +27 -27
  160. package/src/saas/internal-api/requests/api/requests.api.js +120 -120
  161. package/src/saas/internal-api/requests/api/requests.service.js +274 -274
  162. package/src/saas/internal-api/requests/index.js +21 -20
  163. package/src/saas/internal-api/requests/models/create.request.model.js +36 -35
  164. package/src/saas/internal-api/requests/models/draft.request.criteria.model.js +18 -18
  165. package/src/saas/internal-api/requests/models/draft.request.report.model.js +14 -14
  166. package/src/saas/internal-api/requests/models/edit.request.model.js +31 -31
  167. package/src/saas/internal-api/requests/models/requestListCriteriaModel.js +17 -17
  168. package/src/saas/internal-api/requests/models/tenant.request.model.js +9 -9
  169. package/src/saas/internal-api/requests/utils.js +16 -8
  170. package/src/saas/internal-api/requestsTable/api/requests.table.api.js +20 -20
  171. package/src/saas/internal-api/requestsTable/api/requests.table.service.js +14 -14
  172. package/src/saas/internal-api/requestsTable/index.js +3 -3
  173. package/src/saas/internal-api/requirements/api/requirements.api.js +57 -57
  174. package/src/saas/internal-api/requirements/api/requirements.service.js +177 -177
  175. package/src/saas/internal-api/requirements/consts/attributeTypes.json +8 -8
  176. package/src/saas/internal-api/requirements/consts/consts.js +6 -6
  177. package/src/saas/internal-api/requirements/index.js +10 -10
  178. package/src/saas/internal-api/requirements/models/create.requirement.model.js +17 -17
  179. package/src/saas/internal-api/requirements/models/policy.model.js +35 -35
  180. package/src/saas/internal-api/requirements/models/update.requirement.model.js +19 -19
  181. package/src/saas/internal-api/requirements/utils/utils.js +129 -129
  182. package/src/saas/internal-api/serviceArea/api/coordinates.api.js +12 -12
  183. package/src/saas/internal-api/serviceArea/api/coordinates.service.js +7 -7
  184. package/src/saas/internal-api/serviceArea/index.js +4 -4
  185. package/src/saas/internal-api/serviceArea/utils/utils.js +8 -8
  186. package/src/saas/internal-api/tabs/api/tabs.api.js +32 -32
  187. package/src/saas/internal-api/tabs/api/tabs.service.js +54 -54
  188. package/src/saas/internal-api/tabs/index.js +3 -3
  189. package/src/saas/internal-api/tabs/models/tabs.model.js +19 -19
  190. package/src/saas/internal-api/thread-scheduler/runner.js +55 -55
  191. package/src/saas/internal-api/uploadFiles/api/upload.file.api.js +43 -43
  192. package/src/saas/internal-api/uploadFiles/api/upload.file.service.js +106 -106
  193. package/src/saas/internal-api/uploadFiles/consts.js +12 -12
  194. package/src/saas/internal-api/uploadFiles/index.js +5 -5
  195. package/src/saas/internal-api/users/api/tenantApp/tenant.app.api.js +38 -38
  196. package/src/saas/internal-api/users/api/tenantApp/tenant.app.service.js +108 -108
  197. package/src/saas/internal-api/users/api/users.api.js +127 -127
  198. package/src/saas/internal-api/users/api/users.service.js +243 -243
  199. package/src/saas/internal-api/users/index.js +16 -16
  200. package/src/saas/internal-api/users/models/create.inner.system.user.model.js +18 -18
  201. package/src/saas/internal-api/users/models/notification.settings.model.js +12 -12
  202. package/src/saas/internal-api/users/models/tenent.user.model.js +11 -11
  203. package/src/saas/internal-api/users/models/users.model.js +42 -42
  204. package/src/saas/internal-api/users/utils/util.js +39 -39
  205. package/src/saas/internal-api/vendorProfile/api/vendor.profile.api.js +26 -20
  206. package/src/saas/internal-api/vendorProfile/api/vendor.profile.service.js +19 -14
  207. package/src/saas/internal-api/vendorProfile/index.js +3 -3
  208. package/src/saas/openapi/accounts/accounts.api.js +17 -17
  209. package/src/saas/openapi/accounts/accounts.service.js +11 -11
  210. package/src/saas/openapi/coi/coi.api.js +30 -30
  211. package/src/saas/openapi/coi/coi.service.js +43 -43
  212. package/src/saas/openapi/projects/projects.api.js +83 -83
  213. package/src/saas/openapi/projects/projects.service.js +64 -64
  214. package/src/saas/openapi/requests/index.js +7 -7
  215. package/src/saas/openapi/requests/models/invite.request.model.js +40 -40
  216. package/src/saas/openapi/requests/models/update.request.model.js +35 -35
  217. package/src/saas/openapi/requests/requests.api.js +87 -87
  218. package/src/saas/openapi/requests/requests.service.js +81 -81
  219. package/src/saas/openapi/requirements/index.js +6 -6
  220. package/src/saas/openapi/requirements/models/copy.requirement.model.js +10 -10
  221. package/src/saas/openapi/requirements/requirements.api.js +41 -41
  222. package/src/saas/openapi/requirements/requirements.service.js +49 -49
  223. package/src/saas/openapi/tabs/index.js +6 -6
  224. package/src/saas/openapi/tabs/models/create.tab.model.js +6 -6
  225. package/src/saas/openapi/tabs/tabs.api.js +27 -27
  226. package/src/saas/openapi/tabs/tabs.service.js +19 -19
  227. package/src/saas/openapi/users/user.model.js +10 -10
  228. package/src/saas/openapi/users/users.api.js +33 -33
  229. package/src/saas/openapi/users/users.service.js +41 -41
  230. package/tests/env.test.js +40 -40
  231. package/tests/validation.test.js +83 -83
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "name": "@getjones/test-infra",
3
- "version": "4.4.13",
4
- "description": "Providing internal and openapi interface",
5
- "main": "src/index.js",
6
- "scripts": {
7
- "test": "mocha \"./tests/**/*.test.js\" --slow 3000 --timeout 10000 --exit --inlineDiffs --bail",
8
- "eslint-fix": "eslint \"./src/**/*.js\" --fix"
9
- },
10
- "author": "",
11
- "license": "ISC",
12
- "dependencies": {
13
- "axios": "^0.21.1",
14
- "axios-file": "^1.0.17",
15
- "chai": "^4.3.4",
16
- "dotenv": "^8.2.0",
17
- "enum": "^3.0.4",
18
- "form-data": "^4.0.0",
19
- "mocha": "^8.3.2"
20
- },
21
- "devDependencies": {
22
- "babel-eslint": "^10.0.3",
23
- "eslint": "^6.8.0",
24
- "eslint-plugin-import": "^2.19.1",
25
- "mocha-spec-json-output-reporter": "^1.1.7"
26
- },
27
- "directories": {
28
- "test": "tests"
29
- }
30
- }
1
+ {
2
+ "name": "@getjones/test-infra",
3
+ "version": "4.4.14",
4
+ "description": "Providing internal and openapi interface",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "mocha \"./tests/**/*.test.js\" --slow 3000 --timeout 10000 --exit --inlineDiffs --bail",
8
+ "eslint-fix": "eslint \"./src/**/*.js\" --fix"
9
+ },
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "axios": "^0.21.1",
14
+ "axios-file": "^1.0.17",
15
+ "chai": "^4.3.4",
16
+ "dotenv": "^8.2.0",
17
+ "enum": "^3.0.4",
18
+ "form-data": "^4.0.0",
19
+ "mocha": "^8.3.2"
20
+ },
21
+ "devDependencies": {
22
+ "babel-eslint": "^10.0.3",
23
+ "eslint": "^6.8.0",
24
+ "eslint-plugin-import": "^2.19.1",
25
+ "mocha-spec-json-output-reporter": "^1.1.7"
26
+ },
27
+ "directories": {
28
+ "test": "tests"
29
+ }
30
+ }
@@ -1,40 +1,40 @@
1
- const { expect } = require('chai');
2
-
3
- const env = require('../../../../../../src/env');
4
-
5
- const { internalAPI } = require('../../../../src')(env);
6
- const { dbEmails, auth } = internalAPI;
7
-
8
- const httpResponseStatusCodes = require('../../../common/httpResponseStatusCodes.json');
9
-
10
- const textInSubject = 'One-Time Security Code';
11
- const textInBody = 'Please use the one-time code below to confirm your identity';
12
- const codeLength = 6;
13
-
14
- const getVendorHubAuthCookie = async email => {
15
- const createOneTimeSessionResponse = await auth.services.createOneTimeSession(email);
16
- expect(createOneTimeSessionResponse.status, `Create one-time session for email ${email} has failed`).to.equal(httpResponseStatusCodes.OK);
17
-
18
- const recipients = {
19
- from: env.credentials.superUser,
20
- to: [email]
21
- };
22
-
23
- const userEmailBody = await dbEmails.services.getLastMessage({ recipients, textInSubject });
24
- expect(userEmailBody, 'Fetching user one-time security code email has failed').to.be.a('string').that.includes(textInBody);
25
-
26
- const oneTimeCode = await extractOneTimeCode(userEmailBody);
27
- expect(oneTimeCode.length, 'One-time security code extraction from email body has failed').to.equal(codeLength);
28
-
29
- return auth.services.getHubUserCookie(email, oneTimeCode);
30
- };
31
-
32
- async function extractOneTimeCode(inputString) {
33
- const regex = '\s*(\\d{6})\n\s*';
34
- const match = inputString.match(regex);
35
-
36
- return match ? match[1] : null;
37
- }
38
- module.exports = {
39
- getVendorHubAuthCookie
40
- };
1
+ const { expect } = require('chai');
2
+
3
+ const env = require('../../../../../../src/env');
4
+
5
+ const { internalAPI } = require('../../../../src')(env);
6
+ const { dbEmails, auth } = internalAPI;
7
+
8
+ const httpResponseStatusCodes = require('../../../common/httpResponseStatusCodes.json');
9
+
10
+ const textInSubject = 'One-Time Security Code';
11
+ const textInBody = 'Please use the one-time code below to confirm your identity';
12
+ const codeLength = 6;
13
+
14
+ const getVendorHubAuthCookie = async email => {
15
+ const createOneTimeSessionResponse = await auth.services.createOneTimeSession(email);
16
+ expect(createOneTimeSessionResponse.status, `Create one-time session for email ${email} has failed`).to.equal(httpResponseStatusCodes.OK);
17
+
18
+ const recipients = {
19
+ from: env.credentials.superUser,
20
+ to: [email]
21
+ };
22
+
23
+ const userEmailBody = await dbEmails.services.getLastMessage({ recipients, textInSubject });
24
+ expect(userEmailBody, 'Fetching user one-time security code email has failed').to.be.a('string').that.includes(textInBody);
25
+
26
+ const oneTimeCode = await extractOneTimeCode(userEmailBody);
27
+ expect(oneTimeCode.length, 'One-time security code extraction from email body has failed').to.equal(codeLength);
28
+
29
+ return auth.services.getHubUserCookie(email, oneTimeCode);
30
+ };
31
+
32
+ async function extractOneTimeCode(inputString) {
33
+ const regex = '\s*(\\d{6})\n\s*';
34
+ const match = inputString.match(regex);
35
+
36
+ return match ? match[1] : null;
37
+ }
38
+ module.exports = {
39
+ getVendorHubAuthCookie
40
+ };
@@ -1,4 +1,4 @@
1
- const records = require('./records/records');
2
- const auth = require('./auth/auth');
3
-
4
- module.exports = { records, auth };
1
+ const records = require('./records/records');
2
+ const auth = require('./auth/auth');
3
+
4
+ module.exports = { records, auth };
@@ -1,243 +1,243 @@
1
- const { expect } = require('chai');
2
-
3
- const threadScheduler = require('../../../saas/internal-api/thread-scheduler/runner');
4
- const timeUtils = require('../../utils/timeUtils');
5
- const httpResponseStatusCodes = require('../../../common/httpResponseStatusCodes.json');
6
- const ocrStatuses = require('../../consts/ocrStatuses');
7
- const contractors = require('../../../saas/internal-api/contractors');
8
- const compliance = require('../../../saas/internal-api/compliance');
9
- const requests = require('../../../saas/internal-api/requests');
10
- const dbEmails = require('../../../saas/internal-api/dbEmails');
11
- const activationStatuses = require('../../../common/consts/activationStatuses');
12
- const recordTypes = require('../../../common/consts/recordTypes');
13
-
14
- const makeRecordNotResponsive = async function(recordId, context) {
15
- const { data: record } = await contractors.services.getContractorById(recordId, context);
16
- const isTenant = record.recordType === recordTypes.TENANTS;
17
-
18
- const offsetInDaysList = isTenant ?
19
- timeUtils.getInviteActionOffsetInDaysForNotResponsiveTenant() :
20
- timeUtils.getInviteActionOffsetInDaysForNotResponsiveVendor();
21
-
22
- for (const offsetInDays of offsetInDaysList) {
23
- await updateLastInviteActionDate(recordId, offsetInDays, context);
24
- }
25
- };
26
-
27
- const resendInvitationByRecordId = async (recordId, tabId, context) => {
28
- const { id: requestId } = await requests.services.getRequestFromTabByRecordId(recordId, tabId, context);
29
- const recordModifyDateVerificationModel = await contractors.services.getRecordVerificationModel(recordId, context);
30
-
31
- const resendInvitationResponse = await contractors.services.resendInvitation(requestId, recordModifyDateVerificationModel, context);
32
-
33
- if (resendInvitationResponse.status !== httpResponseStatusCodes.OK) {
34
- throw new Error(`Failed to resend invitation for record: ${resendInvitationResponse.statusText}`);
35
- }
36
-
37
- return resendInvitationResponse;
38
- };
39
-
40
- const editRequestAndRecordDetails = async function(request, recordConfig, context) {
41
- const tabModel = new requests.models.TabModel(request.tab.type);
42
- const recordDetailsModel = contractors.services.getContractorDetailsModel(recordConfig);
43
- const record = new contractors.models.edit.ContractorModel(
44
- request.record.contractorId,
45
- request.record.recordType,
46
- recordConfig.company,
47
- recordConfig.emailAddress,
48
- recordDetailsModel
49
- );
50
- const requestEditModel = new requests.models.RequestModel(request.id, record, tabModel, {});
51
-
52
- const editRequestResponse = await requests.services.editRequestAndRecordDetails(requestEditModel, context);
53
-
54
- if (editRequestResponse.status !== httpResponseStatusCodes.OK) {
55
- throw Error(`Failed to edit record \n${editRequestResponse.data.message}`);
56
- }
57
- };
58
-
59
- const updateInviteDate = async function(recordId, inviteDate, context) {
60
- await timeUtils.waitFor(1).seconds;
61
- const updateResponse = await contractors.services.updateInviteDate(recordId, inviteDate, context);
62
-
63
- if (updateResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
64
- throw new Error(`Failed to update record invite date\n${updateResponse}`);
65
- }
66
-
67
- const threadSchedulerResponse = await threadScheduler.runForRecords([recordId]);
68
-
69
- if (threadSchedulerResponse.status !== httpResponseStatusCodes.OK) {
70
- throw new Error(`Failed to run thread scheduler\n${threadSchedulerResponse}`);
71
- }
72
-
73
- await timeUtils.waitFor(2.5).seconds; // calls for the same records can override each other
74
- };
75
-
76
- const updateLastInviteActionDate = async function(recordId, offsetInDays, context) {
77
- await timeUtils.waitFor(1).seconds;
78
- /*
79
- To run the reminders mails successfully we must first update the compliance audit actions date,
80
- Since the thread scheduler will trigger the logic of the reminders mails
81
- only if last invite action date will be equal or after compliance audit actions date
82
- */
83
- const updateComplianceAuditResponse = await compliance.services.audit.updateComplianceAuditActionsDate(recordId, offsetInDays, context);
84
-
85
- if (updateComplianceAuditResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
86
- throw new Error(`Failed to update compliance audit date\n${updateComplianceAuditResponse}`);
87
- }
88
-
89
- const updateLastInviteActionResponse = await contractors.services.updateLastInviteActionDate(recordId, offsetInDays, context);
90
-
91
- if (updateLastInviteActionResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
92
- throw new Error(`Failed to update record invite date\n${updateLastInviteActionResponse}`);
93
- }
94
-
95
- const threadSchedulerResponse = await threadScheduler.runForRecords([recordId]);
96
-
97
- if (threadSchedulerResponse.status !== httpResponseStatusCodes.OK) {
98
- throw new Error(`Failed to run thread scheduler\n${threadSchedulerResponse}`);
99
- }
100
-
101
- await timeUtils.waitFor(2.5).seconds; // calls for the same records can override each other
102
- };
103
-
104
- const runOverAllRenewalDatesForRecord = async function(recordId, policyName) {
105
- const dates = timeUtils.getAutomaticRenewalsExpirationDates();
106
-
107
- for (const date of dates) {
108
- await updatePolicyExpiryDateForRecord(recordId, date, policyName);
109
- }
110
- };
111
-
112
- const updatePolicyExpiryDateForRecord = async function(recordId, expiryDate, policyName) {
113
- const updateResponse = await contractors.services.updateExpiryDate(recordId, expiryDate, policyName);
114
-
115
- if (updateResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
116
- throw new Error(`Record expiry date could not be updated\n${updateResponse}`);
117
- }
118
-
119
- const threadSchedulerResponse = await threadScheduler.runForRecords([recordId]);
120
-
121
- if (threadSchedulerResponse.status !== httpResponseStatusCodes.OK) {
122
- throw new Error(`Thread scheduler has failed to run\n${threadSchedulerResponse}`);
123
- }
124
-
125
- await timeUtils.waitFor(2.5).seconds; // calls for the same records can override each other
126
- };
127
-
128
- const getHistoryEvents = async function(recordId, context) {
129
- const recordHistory = await contractors.services.getRecordHistory(recordId, context);
130
- expect(recordHistory.status, 'Expected record history response status to equal 200.').to.equal(httpResponseStatusCodes.OK);
131
-
132
- return recordHistory.data.map(item => item.itemTitle).reverse();
133
- };
134
-
135
- const getFirstHistoryEventId = async function(recordId, context) {
136
- const recordHistory = await contractors.services.getRecordHistory(recordId, context);
137
- expect(recordHistory.status, 'Expected record history response status to equal 200.').to.equal(httpResponseStatusCodes.OK);
138
- return recordHistory.data[recordHistory.data.length - 1].itemId;
139
- };
140
-
141
- const getLatestHistoryEventId = async function(recordId, context) {
142
- const recordHistory = await contractors.services.getRecordHistory(recordId, context);
143
- expect(recordHistory.status, 'Expected record history response status to equal 200.').to.equal(httpResponseStatusCodes.OK);
144
- return recordHistory.data[0].itemId;
145
- };
146
-
147
- const getLatestRecordHistoryEventByItemTitle = async function(recordId, itemTitle, context) {
148
- const recordHistory = await contractors.services.getRecordHistory(recordId, context);
149
- expect(recordHistory.status, 'Expected record history response status to equal 200.').to.equal(httpResponseStatusCodes.OK);
150
-
151
- const latestHistoryByTitle = recordHistory.data.find(historyItem => historyItem.itemTitle === itemTitle);
152
-
153
- if (!latestHistoryByTitle) {
154
- throw new Error(`History event with title ${itemTitle} not found`);
155
- }
156
-
157
- return latestHistoryByTitle;
158
- };
159
-
160
- const getLatestRecordHistoryEventIdByItemTitle = async function(recordId, itemTitle, context) {
161
- const latestHistoryByTitle = await getLatestRecordHistoryEventByItemTitle(recordId, itemTitle, context);
162
-
163
- return latestHistoryByTitle.itemId;
164
- };
165
-
166
- const getRecordHistoryItemById = async (recordId, itemId, context) => {
167
- const recordHistory = await contractors.services.getRecordHistory(recordId, context);
168
-
169
- return recordHistory.data.find(item => item.itemId === itemId);
170
- };
171
-
172
- const waitForOcrStatus = async function(recordId, context, { expectedStatus = ocrStatuses.SUCCESS } = {}) {
173
- let { data: recordOcrStatus } = await contractors.services.getRecordOcrStatus(recordId, context);
174
- let maxRetries = 25;
175
- while (recordOcrStatus !== expectedStatus && recordOcrStatus !== ocrStatuses.FAILED && maxRetries > 0) {
176
- await timeUtils.waitFor(5).seconds;
177
- recordOcrStatus = (await contractors.services.getRecordOcrStatus(recordId, context)).data;
178
- maxRetries--;
179
- }
180
-
181
- if (recordOcrStatus !== expectedStatus) {
182
- throw new Error(`Record OCR status not is as expected. Expected: ${expectedStatus}, Actual: ${recordOcrStatus}`);
183
- }
184
- };
185
-
186
- const deleteAllRequestsInProject = async function(accountId, projectId, context) {
187
- const activationStatus = [activationStatuses.ACTIVE, activationStatuses.ARCHIVED, activationStatuses.DRAFT];
188
- const { data: requestsInAccount } = await requests.services.getRequestsByAccountId(accountId, context, activationStatus);
189
-
190
- for (const request of requestsInAccount) {
191
- if (request.projectInfo.projectId === projectId) {
192
- const response = await contractors.services.deleteByContractorId(request.record.contractorId, context);
193
-
194
- if (response.status !== httpResponseStatusCodes.NO_CONTENT) {
195
- throw new Error(`Failed to delete request ${request.id}\n${response}`);
196
- }
197
- }
198
- }
199
- };
200
-
201
- const generateSubscriptionModelFromMail = async function(recipients) {
202
- const data = await dbEmails.services.getSubscriptionData(recipients);
203
- return contractors.services.getSubscriptionModel(data);
204
- };
205
-
206
- const overrideGap = async (recordId, reason, note, policyName, attributeName, context) => {
207
- const { data: record } = await contractors.services.getContractorById(recordId, context);
208
- const overrideModel = compliance.services.overrideGap.getWaiveModel(record, policyName, attributeName, reason, note);
209
- return compliance.services.overrideGap.overrideGap({ waiveRequestModel: overrideModel, context });
210
- };
211
-
212
- const retractOverriddenGap = async (recordId, policyName, attributeName, context) => {
213
- const { data: record } = await contractors.services.getContractorById(recordId, context);
214
- const retractModel = compliance.services.overrideGap.getRetractModel(record, policyName, attributeName);
215
- return compliance.services.overrideGap.retractOverride(retractModel, context);
216
- };
217
-
218
- const waiveAllGaps = async (recordId, context) => {
219
- const { data: record } = await contractors.services.getContractorById(recordId, context);
220
- await compliance.services.overrideGap.waiveAll(record, context);
221
- };
222
-
223
- module.exports = {
224
- makeRecordNotResponsive,
225
- resendInvitationByRecordId,
226
- runOverAllRenewalDatesForRecord,
227
- editRequestAndRecordDetails,
228
- updateInviteDate,
229
- updatePolicyExpiryDateForRecord,
230
- getHistoryEvents,
231
- getFirstHistoryEventId,
232
- getLatestHistoryEventId,
233
- updateLastInviteActionDate,
234
- waitForOcrStatus,
235
- generateSubscriptionModelFromMail,
236
- deleteAllRequestsInProject,
237
- getLatestRecordHistoryEventIdByItemTitle,
238
- getRecordHistoryItemById,
239
- getLatestRecordHistoryEventByItemTitle,
240
- waiveAllGaps,
241
- overrideGap,
242
- retractOverriddenGap
243
- };
1
+ const { expect } = require('chai');
2
+
3
+ const threadScheduler = require('../../../saas/internal-api/thread-scheduler/runner');
4
+ const timeUtils = require('../../utils/timeUtils');
5
+ const httpResponseStatusCodes = require('../../../common/httpResponseStatusCodes.json');
6
+ const ocrStatuses = require('../../consts/ocrStatuses');
7
+ const contractors = require('../../../saas/internal-api/contractors');
8
+ const compliance = require('../../../saas/internal-api/compliance');
9
+ const requests = require('../../../saas/internal-api/requests');
10
+ const dbEmails = require('../../../saas/internal-api/dbEmails');
11
+ const activationStatuses = require('../../../common/consts/activationStatuses');
12
+ const recordTypes = require('../../../common/consts/recordTypes');
13
+
14
+ const makeRecordNotResponsive = async function(recordId, context) {
15
+ const { data: record } = await contractors.services.getContractorById(recordId, context);
16
+ const isTenant = record.recordType === recordTypes.TENANTS;
17
+
18
+ const offsetInDaysList = isTenant ?
19
+ timeUtils.getInviteActionOffsetInDaysForNotResponsiveTenant() :
20
+ timeUtils.getInviteActionOffsetInDaysForNotResponsiveVendor();
21
+
22
+ for (const offsetInDays of offsetInDaysList) {
23
+ await updateLastInviteActionDate(recordId, offsetInDays, context);
24
+ }
25
+ };
26
+
27
+ const resendInvitationByRecordId = async (recordId, tabId, context) => {
28
+ const { id: requestId } = await requests.services.getRequestFromTabByRecordId(recordId, tabId, context);
29
+ const recordModifyDateVerificationModel = await contractors.services.getRecordVerificationModel(recordId, context);
30
+
31
+ const resendInvitationResponse = await contractors.services.resendInvitation(requestId, recordModifyDateVerificationModel, context);
32
+
33
+ if (resendInvitationResponse.status !== httpResponseStatusCodes.OK) {
34
+ throw new Error(`Failed to resend invitation for record: ${resendInvitationResponse.statusText}`);
35
+ }
36
+
37
+ return resendInvitationResponse;
38
+ };
39
+
40
+ const editRequestAndRecordDetails = async function(request, recordConfig, context) {
41
+ const tabModel = new requests.models.TabModel(request.tab.type);
42
+ const recordDetailsModel = contractors.services.getContractorDetailsModel(recordConfig);
43
+ const record = new contractors.models.edit.ContractorModel(
44
+ request.record.contractorId,
45
+ request.record.recordType,
46
+ recordConfig.company,
47
+ recordConfig.emailAddress,
48
+ recordDetailsModel
49
+ );
50
+ const requestEditModel = new requests.models.RequestModel(request.id, record, tabModel, {});
51
+
52
+ const editRequestResponse = await requests.services.editRequestAndRecordDetails(requestEditModel, context);
53
+
54
+ if (editRequestResponse.status !== httpResponseStatusCodes.OK) {
55
+ throw Error(`Failed to edit record \n${editRequestResponse.data.message}`);
56
+ }
57
+ };
58
+
59
+ const updateInviteDate = async function(recordId, inviteDate, context) {
60
+ await timeUtils.waitFor(1).seconds;
61
+ const updateResponse = await contractors.services.updateInviteDate(recordId, inviteDate, context);
62
+
63
+ if (updateResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
64
+ throw new Error(`Failed to update record invite date\n${updateResponse}`);
65
+ }
66
+
67
+ const threadSchedulerResponse = await threadScheduler.runForRecords([recordId]);
68
+
69
+ if (threadSchedulerResponse.status !== httpResponseStatusCodes.OK) {
70
+ throw new Error(`Failed to run thread scheduler\n${threadSchedulerResponse}`);
71
+ }
72
+
73
+ await timeUtils.waitFor(2.5).seconds; // calls for the same records can override each other
74
+ };
75
+
76
+ const updateLastInviteActionDate = async function(recordId, offsetInDays, context) {
77
+ await timeUtils.waitFor(1).seconds;
78
+ /*
79
+ To run the reminders mails successfully we must first update the compliance audit actions date,
80
+ Since the thread scheduler will trigger the logic of the reminders mails
81
+ only if last invite action date will be equal or after compliance audit actions date
82
+ */
83
+ const updateComplianceAuditResponse = await compliance.services.audit.updateComplianceAuditActionsDate(recordId, offsetInDays, context);
84
+
85
+ if (updateComplianceAuditResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
86
+ throw new Error(`Failed to update compliance audit date\n${updateComplianceAuditResponse}`);
87
+ }
88
+
89
+ const updateLastInviteActionResponse = await contractors.services.updateLastInviteActionDate(recordId, offsetInDays, context);
90
+
91
+ if (updateLastInviteActionResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
92
+ throw new Error(`Failed to update record invite date\n${updateLastInviteActionResponse}`);
93
+ }
94
+
95
+ const threadSchedulerResponse = await threadScheduler.runForRecords([recordId]);
96
+
97
+ if (threadSchedulerResponse.status !== httpResponseStatusCodes.OK) {
98
+ throw new Error(`Failed to run thread scheduler\n${threadSchedulerResponse}`);
99
+ }
100
+
101
+ await timeUtils.waitFor(2.5).seconds; // calls for the same records can override each other
102
+ };
103
+
104
+ const runOverAllRenewalDatesForRecord = async function(recordId, policyName) {
105
+ const dates = timeUtils.getAutomaticRenewalsExpirationDates();
106
+
107
+ for (const date of dates) {
108
+ await updatePolicyExpiryDateForRecord(recordId, date, policyName);
109
+ }
110
+ };
111
+
112
+ const updatePolicyExpiryDateForRecord = async function(recordId, expiryDate, policyName) {
113
+ const updateResponse = await contractors.services.updateExpiryDate(recordId, expiryDate, policyName);
114
+
115
+ if (updateResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
116
+ throw new Error(`Record expiry date could not be updated\n${updateResponse}`);
117
+ }
118
+
119
+ const threadSchedulerResponse = await threadScheduler.runForRecords([recordId]);
120
+
121
+ if (threadSchedulerResponse.status !== httpResponseStatusCodes.OK) {
122
+ throw new Error(`Thread scheduler has failed to run\n${threadSchedulerResponse}`);
123
+ }
124
+
125
+ await timeUtils.waitFor(2.5).seconds; // calls for the same records can override each other
126
+ };
127
+
128
+ const getHistoryEvents = async function(recordId, context) {
129
+ const recordHistory = await contractors.services.getRecordHistory(recordId, context);
130
+ expect(recordHistory.status, 'Expected record history response status to equal 200.').to.equal(httpResponseStatusCodes.OK);
131
+
132
+ return recordHistory.data.map(item => item.itemTitle).reverse();
133
+ };
134
+
135
+ const getFirstHistoryEventId = async function(recordId, context) {
136
+ const recordHistory = await contractors.services.getRecordHistory(recordId, context);
137
+ expect(recordHistory.status, 'Expected record history response status to equal 200.').to.equal(httpResponseStatusCodes.OK);
138
+ return recordHistory.data[recordHistory.data.length - 1].itemId;
139
+ };
140
+
141
+ const getLatestHistoryEventId = async function(recordId, context) {
142
+ const recordHistory = await contractors.services.getRecordHistory(recordId, context);
143
+ expect(recordHistory.status, 'Expected record history response status to equal 200.').to.equal(httpResponseStatusCodes.OK);
144
+ return recordHistory.data[0].itemId;
145
+ };
146
+
147
+ const getLatestRecordHistoryEventByItemTitle = async function(recordId, itemTitle, context) {
148
+ const recordHistory = await contractors.services.getRecordHistory(recordId, context);
149
+ expect(recordHistory.status, 'Expected record history response status to equal 200.').to.equal(httpResponseStatusCodes.OK);
150
+
151
+ const latestHistoryByTitle = recordHistory.data.find(historyItem => historyItem.itemTitle === itemTitle);
152
+
153
+ if (!latestHistoryByTitle) {
154
+ throw new Error(`History event with title ${itemTitle} not found`);
155
+ }
156
+
157
+ return latestHistoryByTitle;
158
+ };
159
+
160
+ const getLatestRecordHistoryEventIdByItemTitle = async function(recordId, itemTitle, context) {
161
+ const latestHistoryByTitle = await getLatestRecordHistoryEventByItemTitle(recordId, itemTitle, context);
162
+
163
+ return latestHistoryByTitle.itemId;
164
+ };
165
+
166
+ const getRecordHistoryItemById = async (recordId, itemId, context) => {
167
+ const recordHistory = await contractors.services.getRecordHistory(recordId, context);
168
+
169
+ return recordHistory.data.find(item => item.itemId === itemId);
170
+ };
171
+
172
+ const waitForOcrStatus = async function(recordId, context, { expectedStatus = ocrStatuses.SUCCESS } = {}) {
173
+ let { data: recordOcrStatus } = await contractors.services.getRecordOcrStatus(recordId, context);
174
+ let maxRetries = 25;
175
+ while (recordOcrStatus !== expectedStatus && recordOcrStatus !== ocrStatuses.FAILED && maxRetries > 0) {
176
+ await timeUtils.waitFor(5).seconds;
177
+ recordOcrStatus = (await contractors.services.getRecordOcrStatus(recordId, context)).data;
178
+ maxRetries--;
179
+ }
180
+
181
+ if (recordOcrStatus !== expectedStatus) {
182
+ throw new Error(`Record OCR status not is as expected. Expected: ${expectedStatus}, Actual: ${recordOcrStatus}`);
183
+ }
184
+ };
185
+
186
+ const deleteAllRequestsInProject = async function(accountId, projectId, context) {
187
+ const activationStatus = [activationStatuses.ACTIVE, activationStatuses.ARCHIVED, activationStatuses.DRAFT];
188
+ const { data: requestsInAccount } = await requests.services.getRequestsByAccountId(accountId, context, activationStatus);
189
+
190
+ for (const request of requestsInAccount) {
191
+ if (request.projectInfo.projectId === projectId) {
192
+ const response = await contractors.services.deleteByContractorId(request.record.contractorId, context);
193
+
194
+ if (response.status !== httpResponseStatusCodes.NO_CONTENT) {
195
+ throw new Error(`Failed to delete request ${request.id}\n${response}`);
196
+ }
197
+ }
198
+ }
199
+ };
200
+
201
+ const generateSubscriptionModelFromMail = async function(recipients) {
202
+ const data = await dbEmails.services.getSubscriptionData(recipients);
203
+ return contractors.services.getSubscriptionModel(data);
204
+ };
205
+
206
+ const overrideGap = async (recordId, reason, note, policyName, attributeName, context) => {
207
+ const { data: record } = await contractors.services.getContractorById(recordId, context);
208
+ const overrideModel = compliance.services.overrideGap.getWaiveModel(record, policyName, attributeName, reason, note);
209
+ return compliance.services.overrideGap.overrideGap({ waiveRequestModel: overrideModel, context });
210
+ };
211
+
212
+ const retractOverriddenGap = async (recordId, policyName, attributeName, context) => {
213
+ const { data: record } = await contractors.services.getContractorById(recordId, context);
214
+ const retractModel = compliance.services.overrideGap.getRetractModel(record, policyName, attributeName);
215
+ return compliance.services.overrideGap.retractOverride(retractModel, context);
216
+ };
217
+
218
+ const waiveAllGaps = async (recordId, context) => {
219
+ const { data: record } = await contractors.services.getContractorById(recordId, context);
220
+ await compliance.services.overrideGap.waiveAll(record, context);
221
+ };
222
+
223
+ module.exports = {
224
+ makeRecordNotResponsive,
225
+ resendInvitationByRecordId,
226
+ runOverAllRenewalDatesForRecord,
227
+ editRequestAndRecordDetails,
228
+ updateInviteDate,
229
+ updatePolicyExpiryDateForRecord,
230
+ getHistoryEvents,
231
+ getFirstHistoryEventId,
232
+ getLatestHistoryEventId,
233
+ updateLastInviteActionDate,
234
+ waitForOcrStatus,
235
+ generateSubscriptionModelFromMail,
236
+ deleteAllRequestsInProject,
237
+ getLatestRecordHistoryEventIdByItemTitle,
238
+ getRecordHistoryItemById,
239
+ getLatestRecordHistoryEventByItemTitle,
240
+ waiveAllGaps,
241
+ overrideGap,
242
+ retractOverriddenGap
243
+ };