@getjones/test-infra 2.9.3 → 2.9.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.9.3",
3
+ "version": "2.9.6",
4
4
  "description": "Providing internal and openapi interface",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -4,15 +4,14 @@ const threadScheduler = require('../../../saas/internal-api/thread-scheduler/run
4
4
  const timeUtils = require('../../utils/timeUtils');
5
5
  const httpResponseStatusCodes = require('../../../common/httpResponseStatusCodes.json');
6
6
  const contractors = require('../../../saas/internal-api/contractors');
7
- const compliance = require('../../../saas/internal-api/compliance');
8
7
 
9
8
  const makeRecordNotResponsive = async function(recordId, context, { isTenant } = {}) {
10
- const offsetInDaysList = isTenant ?
11
- timeUtils.getInviteActionOffsetInDaysForNotResponsiveTenant() :
12
- timeUtils.getInviteActionOffsetInDaysForNotResponsiveVendor();
9
+ const dates = isTenant ?
10
+ timeUtils.getInvitationDatesForNotResponsiveTenant() :
11
+ timeUtils.getInvitationDatesForNotResponsiveVendor();
13
12
 
14
- for (const offsetInDays of offsetInDaysList) {
15
- await updateLastInviteActionDate(recordId, offsetInDays, context);
13
+ for (const date of dates) {
14
+ await updateInviteDate(recordId, date, context);
16
15
  }
17
16
  };
18
17
 
@@ -33,34 +32,6 @@ const updateInviteDate = async function(recordId, inviteDate, context) {
33
32
  await timeUtils.waitFor(2.5).seconds; // calls for the same records can override each other
34
33
  };
35
34
 
36
- const updateLastInviteActionDate = async function(recordId, offsetInDays, context) {
37
- await timeUtils.waitFor(1).seconds;
38
- /*
39
- To run the reminders mails successfully we must first update the compliance audit actions date,
40
- Since the thread scheduler will trigger the logic of the reminders mails
41
- only if last invite action date will be equal or after compliance audit actions date
42
- */
43
- const updateComplianceAuditResponse = await compliance.services.audit.updateComplianceAuditActionsDate(recordId, offsetInDays, context);
44
-
45
- if (updateComplianceAuditResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
46
- throw new Error(`Compliance audit date could not be updated\n${updateComplianceAuditResponse}`);
47
- }
48
-
49
- const updateLastInviteActionResponse = await contractors.services.updateLastInviteActionDate(recordId, offsetInDays, context);
50
-
51
- if (updateLastInviteActionResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
52
- throw new Error(`Record invite date could not be updated\n${updateLastInviteActionResponse}`);
53
- }
54
-
55
- const threadSchedulerResponse = await threadScheduler.runForRecords([recordId]);
56
-
57
- if (threadSchedulerResponse.status !== httpResponseStatusCodes.OK) {
58
- throw new Error(`Thread scheduler has failed to run\n${threadSchedulerResponse}`);
59
- }
60
-
61
- await timeUtils.waitFor(2.5).seconds; // calls for the same records can override each other
62
- };
63
-
64
35
  const runOverAllRenewalDatesForRecord = async function(recordId, policyName) {
65
36
  const dates = timeUtils.getAutomaticRenewalsExpirationDates();
66
37
 
@@ -97,6 +68,5 @@ module.exports = {
97
68
  runOverAllRenewalDatesForRecord,
98
69
  updateInviteDate,
99
70
  updatePolicyExpiryDateForRecord,
100
- getHistoryEvents,
101
- updateLastInviteActionDate
71
+ getHistoryEvents
102
72
  };
@@ -2,6 +2,26 @@ const cloneObject = object => {
2
2
  return JSON.parse(JSON.stringify(object));
3
3
  };
4
4
 
5
+ const isUIConfig = (config, attributesConvertor) => {
6
+ const convectorKeys = Object.keys(attributesConvertor);
7
+ const configKeys = Object.keys(config);
8
+
9
+ return convectorKeys.some(key => configKeys.includes(key));
10
+ };
11
+
12
+ const objectConvertor = (config, attributesConvertor) => {
13
+ const covertConfig = {};
14
+
15
+ for (const field in config) {
16
+ const attributes = attributesConvertor[field];
17
+ covertConfig[attributes] = JSON.parse(config[field]);
18
+ }
19
+
20
+ return covertConfig;
21
+ };
22
+
5
23
  module.exports = {
6
- cloneObject
24
+ cloneObject,
25
+ isUIConfig,
26
+ objectConvertor
7
27
  };
@@ -24,14 +24,6 @@ const peroids = {
24
24
  years: 'years'
25
25
  };
26
26
 
27
- const inviteActionDateOffset = {
28
- twoDays: 2,
29
- fiveDays: 5,
30
- eightDays: 8,
31
- tenDays: 10,
32
- fifteenDays: 15
33
- };
34
-
35
27
  const getOneYearAgoDate = format => moment().utc().subtract(1, peroids.years).format(format || formats.threadScheduler);
36
28
  const getTwoHundredDaysAgoDate = format => moment().utc().subtract(200, peroids.days).format(format || formats.threadScheduler);
37
29
  const getSixMonthAgoDate = format => moment().utc().subtract(6, peroids.months).format(format || formats.threadScheduler);
@@ -94,10 +86,6 @@ const getInvitationDatesForNotResponsiveVendor = function() {
94
86
  return [twoDaysAgoUtc, fiveDaysAgoUtc, eightDaysAgoUtc];
95
87
  };
96
88
 
97
- const getInviteActionOffsetInDaysForNotResponsiveVendor = function() {
98
- return [inviteActionDateOffset.twoDays, inviteActionDateOffset.fiveDays, inviteActionDateOffset.eightDays];
99
- };
100
-
101
89
  const getInvitationDatesForNotResponsiveTenant = function() {
102
90
  const fiveDaysAgoUtc = getFiveDaysAgoDate();
103
91
  const tenDaysAgoUtc = getTenDaysAgoDate();
@@ -106,10 +94,6 @@ const getInvitationDatesForNotResponsiveTenant = function() {
106
94
  return [fiveDaysAgoUtc, tenDaysAgoUtc, fifteenDaysAgoUtc];
107
95
  };
108
96
 
109
- const getInviteActionOffsetInDaysForNotResponsiveTenant = function() {
110
- return [inviteActionDateOffset.fiveDays, inviteActionDateOffset.tenDays, inviteActionDateOffset.fifteenDays];
111
- };
112
-
113
97
  const isDateAfterOther = (date, other) => {
114
98
  return moment(date).isAfter(other);
115
99
  };
@@ -131,10 +115,6 @@ const convertDateToLongInt = value => {
131
115
  return Date.parse(value);
132
116
  };
133
117
 
134
- const convertDateStringFormatToISOString = dateStringFormat => {
135
- return new Date(dateStringFormat).toISOString();
136
- };
137
-
138
118
  module.exports = {
139
119
  formats,
140
120
  getOneYearAgoDate,
@@ -156,9 +136,7 @@ module.exports = {
156
136
  getDateinTwentyNineDays,
157
137
  getDateInTwoMonths,
158
138
  getInvitationDatesForNotResponsiveVendor,
159
- getInviteActionOffsetInDaysForNotResponsiveVendor,
160
139
  getInvitationDatesForNotResponsiveTenant,
161
- getInviteActionOffsetInDaysForNotResponsiveTenant,
162
140
  getAutomaticRenewalsExpirationDates,
163
141
  getLogTimestamp,
164
142
  getDayInMilliseconds,
@@ -169,6 +147,5 @@ module.exports = {
169
147
  convertDateToNewFormat,
170
148
  getOneWeekAgoDate,
171
149
  getOneWeekAheadDate,
172
- convertDateToLongInt,
173
- convertDateStringFormatToISOString
150
+ convertDateToLongInt
174
151
  };
@@ -1,8 +1,6 @@
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`,
@@ -12,12 +10,11 @@ const Endpoints = {
12
10
  isReaudit: contractorId => `${backendUrl}/saas/auditor/contractors/${contractorId}/isreaudit`,
13
11
  revertCoi: contractorId => `${backendUrl}/saas/auditor/contractors/${contractorId}/coi/revert`,
14
12
  wrongCoi: `${backendUrl}/saas/coi/wrong-coi`,
15
- getAudit: recordId => `${backendUrl}/saas/audit/${recordId}`,
16
- updateComplianceAuditActionsDate: recordId => `${backendUrl}/saas/automation/record/${recordId}/update-audit-actions-date`
13
+ getAudit: recordId => `${backendUrl}/saas/audit/${recordId}`
17
14
  };
18
15
 
19
16
  const audit = async (contractorId, auditRequestModel, context) => {
20
- await enterAudit(contractorId, {}, context);
17
+ await enterAudit(contractorId, context);
21
18
  return submitAudit(auditRequestModel, context);
22
19
  };
23
20
 
@@ -58,11 +55,6 @@ const wrongCoi = (recordId, context) => {
58
55
  return requests.getRequestHandler(Endpoints.wrongCoi, params, context);
59
56
  };
60
57
 
61
- const updateComplianceAuditActionsDate = (recordId, dateOffset, context) => {
62
- const url = `${Endpoints.updateComplianceAuditActionsDate(recordId)}?offsetInDays=${dateOffset}`;
63
- return requests.putRequestHandler(url, {}, context);
64
- };
65
-
66
58
  module.exports = {
67
59
  audit,
68
60
  submitAudit,
@@ -73,6 +65,5 @@ module.exports = {
73
65
  enterAudit,
74
66
  getAuditRecordModel,
75
67
  getRequirementDetailsForAudit,
76
- getAuditByRecordId,
77
- updateComplianceAuditActionsDate
68
+ getAuditByRecordId
78
69
  };
@@ -1,6 +1,6 @@
1
1
  const auditApi = require('./audit.api');
2
2
  const { AuditRequestModel, AuditListParametersModel, AuditDatesModel } = require('../../models/audit/audit.model');
3
- const { validateType, validateDateString } = require('../../../../../common/validations/typeValidations');
3
+ const { validateType } = require('../../../../../common/validations/typeValidations');
4
4
  const auditUtil = require('../../utils/auditUtil');
5
5
  const dataTypeUtils = require('../../../../../common/utils/dataTypeUtils');
6
6
  const { cloneObject } = require('../../../../../common/utils/objectUtils');
@@ -150,10 +150,6 @@ const auditRecord = async function(
150
150
  return auditResponse;
151
151
  };
152
152
 
153
- const updateComplianceAuditActionsDate = (recordId, dateOffset, context) => {
154
- return auditApi.updateComplianceAuditActionsDate(recordId, dateOffset, context);
155
- };
156
-
157
153
  module.exports = {
158
154
  audit,
159
155
  submitAudit,
@@ -168,6 +164,5 @@ module.exports = {
168
164
  getAuditMetadata,
169
165
  getAuditByRecordId,
170
166
  getAuditRequestModel,
171
- auditRecord,
172
- updateComplianceAuditActionsDate
167
+ auditRecord
173
168
  };
@@ -1,6 +1,5 @@
1
1
  const requests = require('../../../../common/requests/cookieAuth/requests');
2
2
  const { backendUrl } = require('../../../../env').getEnv();
3
- const { convertDateStringFormatToISOString } = require('../../../../common/utils/timeUtils');
4
3
 
5
4
  const Endpoints = {
6
5
  create: `${backendUrl}/saas/contractors/invite`,
@@ -20,7 +19,6 @@ const Endpoints = {
20
19
  changeRequirement: `${backendUrl}/saas/contractor/requirement`,
21
20
  updateVendorExpiryDate: contractorId => `${backendUrl}/_saas/automation/contractor/${contractorId}/expiry-date`,
22
21
  updateContractorInviteDate: contractorId => `${backendUrl}/_saas/automation/contractor/${contractorId}/invite-date`,
23
- updateLastInviteActionDate: recordId => `${backendUrl}/saas/automation/record/${recordId}/update-emails-date`,
24
22
  searchInAutocomplete: ({ tabId, searchWord }) =>
25
23
  `${backendUrl}/saas/requests/search/audited?&tabId=${tabId}&searchWord=${searchWord}`,
26
24
  automationUpdateContractorUploadDate: contractorId => `${backendUrl}/saas/automation/contractor/${contractorId}/upload-date`,
@@ -128,11 +126,6 @@ const getLinkedProjectsCount = async (recordId, context) => {
128
126
  return await requests.getRequestHandler(Endpoints.linkedProjectsCount(recordId), {}, context);
129
127
  };
130
128
 
131
- const updateLastInviteActionDate = (recordId, offsetInDays, context) => {
132
- const url = `${Endpoints.updateLastInviteActionDate(recordId)}?offsetInDays=${offsetInDays}`;
133
- return requests.putRequestHandler(url, {}, context);
134
- };
135
-
136
129
  module.exports = {
137
130
  createContractor,
138
131
  changeRequirement,
@@ -155,6 +148,5 @@ module.exports = {
155
148
  resendInvitation,
156
149
  muteNotifications,
157
150
  unmuteNotifications,
158
- getLinkedProjectsCount,
159
- updateLastInviteActionDate
151
+ getLinkedProjectsCount
160
152
  };
@@ -1,7 +1,7 @@
1
1
  const contractorsAPI = require('./contractors.api');
2
2
  const { CreateContractorModel } = require('../models/create.contractor.model');
3
3
  const { RequestModel } = require('../../requests/models/edit.request.model');
4
- const { validateType, validateDateString } = require('../../../../common/validations/typeValidations');
4
+ const { validateType } = require('../../../../common/validations/typeValidations');
5
5
  const { RecordModifyDateVerificationModel } = require('../models/verification.contractor.model');
6
6
  const { AssignRequirementModel } = require('../models/assign.requirement.model');
7
7
  const httpResponseStatusCodes = require('../../../../common/httpResponseStatusCodes.json');
@@ -54,10 +54,6 @@ const updateInviteDate = (contractorId, inviteDate, context) => {
54
54
  return contractorsAPI.updateInviteDate(contractorId, inviteDate, context);
55
55
  };
56
56
 
57
- const updateLastInviteActionDate = (recordId, dateOffset, context) => {
58
- return contractorsAPI.updateLastInviteActionDate(recordId, dateOffset, context);
59
- };
60
-
61
57
  const getContractorsByTabId = (tabId, context, activityStatus = 'Active') => {
62
58
  return contractorsAPI.getContractorsByTabId(tabId, context, activityStatus);
63
59
  };
@@ -188,6 +184,5 @@ module.exports = {
188
184
  assignRequirement,
189
185
  getAssignRequirementModel,
190
186
  getLinkedProjectsCount,
191
- restoreByRecordId,
192
- updateLastInviteActionDate
187
+ restoreByRecordId
193
188
  };
@@ -5,6 +5,7 @@ const Endpoints = {
5
5
  invite: `${backendUrl}/saas/project/team-member`,
6
6
  editUserProjects: `${backendUrl}/saas/project/team-member`,
7
7
  editUserRole: userId => `${backendUrl}/secured/users/${userId}/change-role`,
8
+ editUserProfile: `${backendUrl}/saas/user/update`,
8
9
  getByProjectId: projectId =>
9
10
  `${backendUrl}/saas/project/${projectId}/team-members`,
10
11
  getByEmail: email => `${backendUrl}/saas/team-member/by-email/${email}`,
@@ -84,6 +85,9 @@ const sendForgetPasswordMail = userEmail => {
84
85
  const body = { email: userEmail };
85
86
  return requests.postRequestHandler(Endpoints.sendForgetPasswordMail, body);
86
87
  };
88
+ const editUserProfile = (editUserProfileModel, context) => {
89
+ return requests.postRequestHandler(Endpoints.editUserProfile, editUserProfileModel, context);
90
+ };
87
91
 
88
92
  module.exports = {
89
93
  invite,
@@ -100,5 +104,6 @@ module.exports = {
100
104
  editUserEmailNotificationsSettings,
101
105
  sendForgetPasswordMail,
102
106
  createInnerSystemUser,
103
- getInnerSystemUsersPerRole
107
+ getInnerSystemUsersPerRole,
108
+ editUserProfile
104
109
  };
@@ -1,4 +1,4 @@
1
- const { InviteUserModel, SignupUserModel, EditUserModel } = require('../models/users.model');
1
+ const { InviteUserModel, SignupUserModel, EditUserModel, EditUserProfileModel } = require('../models/users.model');
2
2
  const { validateType } = require('../../../../common/validations/typeValidations');
3
3
  const { getEnv } = require('../../../../env');
4
4
  const { credentials } = getEnv();
@@ -147,6 +147,33 @@ const sendForgetPasswordMail = userEmail => {
147
147
  return userAPI.sendForgetPasswordMail(userEmail);
148
148
  };
149
149
 
150
+ const editUserProfile = async (email, fullName, context) => {
151
+ const { data: user } = await getUserByEmail(email, context);
152
+
153
+ const editUserProfileModel = new EditUserProfileModel(user.id, email, user.role, fullName);
154
+
155
+ const response = await userAPI.editUserProfile(editUserProfileModel, context);
156
+
157
+ if (response.status !== httpResponseStatusCodes.OK) {
158
+ throw Error(`Failed to edit user id: [${user.id}] profile\n${response}`);
159
+ }
160
+
161
+ return getUserByEmail(email, context);
162
+ };
163
+
164
+ const editUserSettings = async (email, config, context) => {
165
+ const { data: user } = await getUserByEmail(email, context);
166
+ const settingModel = util.getSettingsModel(config);
167
+
168
+ const response = await userAPI.editUserEmailNotificationsSettings(user.id, settingModel, context);
169
+
170
+ if (response.status !== httpResponseStatusCodes.OK) {
171
+ throw Error(`Failed to edit user id: [${user.id}] settings\n${response}`);
172
+ }
173
+
174
+ return getUserByEmail(email, context);
175
+ };
176
+
150
177
  module.exports = {
151
178
  inviteUser,
152
179
  signupUser,
@@ -162,5 +189,7 @@ module.exports = {
162
189
  reinviteUser,
163
190
  editUserEmailNotificationsSettings,
164
191
  sendForgetPasswordMail,
165
- getOrCreateInnerSystemUser
192
+ getOrCreateInnerSystemUser,
193
+ editUserProfile,
194
+ editUserSettings
166
195
  };
@@ -24,8 +24,18 @@ class EditUserModel {
24
24
  }
25
25
  }
26
26
 
27
+ class EditUserProfileModel {
28
+ constructor(subUserId, email, role, fullName) {
29
+ this.subUserId = subUserId;
30
+ this.email = email;
31
+ this.role = role;
32
+ this.fullName = fullName;
33
+ }
34
+ }
35
+
27
36
  module.exports = {
28
37
  InviteUserModel,
29
38
  SignupUserModel,
30
- EditUserModel
39
+ EditUserModel,
40
+ EditUserProfileModel
31
41
  };
@@ -1,6 +1,15 @@
1
1
  const { SignupUserModel } = require('../models/users.model');
2
+ const { NotificationSettingsModel } = require('../models/notification.settings.model');
2
3
  const usersApi = require('../api/users.api');
3
4
  const httpResponseStatusCodes = require('../../../../common/httpResponseStatusCodes.json');
5
+ const objectUtils = require('../../../../common/utils/objectUtils');
6
+
7
+ const attributesConvertor = {
8
+ 'COI is not compliant.': 'auditNotCompliant',
9
+ 'Policy is about to expire.': 'aboutToExpire',
10
+ 'COI is compliant.': 'auditCompliant',
11
+ 'Unresponsive contact.': 'missingCoi'
12
+ };
4
13
 
5
14
  const getUserEncryptedData = async (email, role, context) => {
6
15
  const response = await usersApi.getUserEncryptedData(email, role, context);
@@ -17,4 +26,14 @@ const getSignupUserModel = async (email, role, fullName, password, context) => {
17
26
  return new SignupUserModel(fullName, role, password, userEncryptedData);
18
27
  };
19
28
 
20
- module.exports = { getSignupUserModel };
29
+ const getSettingsModel = settings => {
30
+ const isUIConfig = objectUtils.isUIConfig(settings, attributesConvertor);
31
+
32
+ const settingConfig = isUIConfig ?
33
+ objectUtils.objectConvertor(settings, attributesConvertor) :
34
+ settings;
35
+
36
+ return new NotificationSettingsModel(settingConfig);
37
+ };
38
+
39
+ module.exports = { getSignupUserModel, getSettingsModel };