@getjones/test-infra 1.7.3 → 1.8.1

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": "1.7.3",
3
+ "version": "1.8.1",
4
4
  "description": "Providing internal and openapi interface",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -46,7 +46,6 @@ const getInternalAPI = () => {
46
46
  globalRecord,
47
47
  vendorProfile,
48
48
  serviceArea,
49
-
50
49
  threadScheduler
51
50
  };
52
51
 
@@ -38,7 +38,13 @@ const getOrCreateAccount = async (createAccountModel, context) => {
38
38
  return existingAccount;
39
39
  }
40
40
 
41
- return createAccount(createAccountModel, context);
41
+ const response = await accountsAPI.create(createAccountModel, context);
42
+
43
+ if (!response.data) {
44
+ throw new Error(`Account by the name ${createAccountModel.companyName} did not crate`);
45
+ }
46
+
47
+ return response.data;
42
48
  };
43
49
 
44
50
  const getAccountId = async (accountName, context) => {
@@ -9,11 +9,15 @@ const Endpoints = {
9
9
  archive: contractorId => `${backendUrl}/saas/contractor/${contractorId}/archive`,
10
10
  restore: contractorId => `${backendUrl}/saas/contractor/${contractorId}/restore`,
11
11
  edit: contractorId => `${backendUrl}/saas/contractors/${contractorId}/update`,
12
+ muteNotifications: `${backendUrl}/saas/record/notifications/mute`,
13
+ unmuteNotifications: `${backendUrl}/saas/record/notifications/unmute`,
14
+ changeRequirement: `${backendUrl}/saas/contractor/requirement`,
12
15
  updateVendorExpiryDate: contractorId => `${backendUrl}/_saas/automation/contractor/${contractorId}/expiry-date`,
13
16
  assignMptToProperties: (accountId, tenantId) => `${backendUrl}/saas/account/${accountId}/multi-properties/${tenantId}`,
14
17
  searchInAutocomplete: ({ tabId, searchWord }) =>
15
18
  `${backendUrl}/saas/contractors/search/audited?&tabId=${tabId}&searchWord=${searchWord}`,
16
- automationUpdateContractorUploadDate: contractorId => `${backendUrl}/saas/automation/contractor/${contractorId}/upload-date`
19
+ automationUpdateContractorUploadDate: contractorId => `${backendUrl}/saas/automation/contractor/${contractorId}/upload-date`,
20
+ publicLinkInvite: `${backendUrl}/_saas/contractors/publicinvite`
17
21
  };
18
22
 
19
23
  const createContractor = (createContractorModel, context) => {
@@ -45,6 +49,18 @@ const editContractor = (editContractorModel, context) => {
45
49
  return requests.postRequestHandler(Endpoints.edit(editContractorModel.contractorId), editContractorModel, context, {}, params);
46
50
  };
47
51
 
52
+ const muteNotifications = (recordModifyDateVerificationModel, context) => {
53
+ return requests.postRequestHandler(Endpoints.muteNotifications, recordModifyDateVerificationModel, context);
54
+ };
55
+
56
+ const unmuteNotifications = (recordModifyDateVerificationModel, context) => {
57
+ return requests.postRequestHandler(Endpoints.unmuteNotifications, recordModifyDateVerificationModel, context);
58
+ };
59
+
60
+ const changeRequirement = (recordModifyDateVerificationModel, context) => {
61
+ return requests.putRequestHandler(Endpoints.changeRequirement, recordModifyDateVerificationModel, context);
62
+ };
63
+
48
64
  const updateExpiryDate = (contractorId, expiryDate, policyName) => {
49
65
  const data = { [policyName]: expiryDate };
50
66
  return requests.postRequestHandler(Endpoints.updateVendorExpiryDate(contractorId), data);
@@ -81,8 +97,13 @@ const updateContractorUploadDate = (contractorId, uploadDate, context) => {
81
97
  return requests.patchRequestHandler(url, context);
82
98
  };
83
99
 
100
+ const inviteContractorViaPublicLink = (createContractorModel, context) => {
101
+ return requests.postRequestHandler(Endpoints.publicLinkInvite, createContractorModel, context);
102
+ };
103
+
84
104
  module.exports = {
85
105
  createContractor,
106
+ changeRequirement,
86
107
  getContractorsByAccountId,
87
108
  getContractorById,
88
109
  deleteByContractorId,
@@ -93,5 +114,8 @@ module.exports = {
93
114
  assignMptToProperties,
94
115
  getContractorsByTabId,
95
116
  searchInAutocomplete,
96
- updateContractorUploadDate
117
+ updateContractorUploadDate,
118
+ inviteContractorViaPublicLink,
119
+ muteNotifications,
120
+ unmuteNotifications
97
121
  };
@@ -61,8 +61,29 @@ const updateContractorUploadDate = (contractorId, uploadDate, context) => {
61
61
  return contractorsAPI.updateContractorUploadDate(contractorId, uploadDate, context);
62
62
  };
63
63
 
64
+ const inviteContractorViaPublicLink = async (createContractorModel, context) => {
65
+ validateType(createContractorModel, CreateContractorModel);
66
+ return contractorsAPI.inviteContractorViaPublicLink(createContractorModel, context);
67
+ };
68
+
69
+ const changeRequirement = (recordModifyDateVerificationModel, context) => {
70
+ validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
71
+ return contractorsAPI.changeRequirement(recordModifyDateVerificationModel, context);
72
+ };
73
+
74
+ const muteNotifications = (recordModifyDateVerificationModel, context) => {
75
+ validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
76
+ return contractorsAPI.muteNotifications(recordModifyDateVerificationModel, context);
77
+ };
78
+
79
+ const unmuteNotifications = (recordModifyDateVerificationModel, context) => {
80
+ validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
81
+ return contractorsAPI.unmuteNotifications(recordModifyDateVerificationModel, context);
82
+ };
83
+
64
84
  module.exports = {
65
85
  createContractor,
86
+ changeRequirement,
66
87
  getContractorsByAccountId,
67
88
  getContractorById,
68
89
  deleteByContractorId,
@@ -73,5 +94,8 @@ module.exports = {
73
94
  getContractorsByTabId,
74
95
  assignMptToProperties,
75
96
  searchInAutoComplete,
76
- updateContractorUploadDate
97
+ updateContractorUploadDate,
98
+ inviteContractorViaPublicLink,
99
+ muteNotifications,
100
+ unmuteNotifications
77
101
  };
@@ -1,12 +1,12 @@
1
1
  const { validateType } = require('../../../../common/validations/typeValidations');
2
2
 
3
- function CreateContractorModel(requirementId, inviterEmail, vendorInfo, { tabId = null, disableMail = true, sendCovid19Form = false } = {}) {
3
+ function CreateContractorModel(requirementId, inviterEmail, vendorInfo, { tabId = null, disableMail = true, publicLink } = {}) {
4
4
  this.reqId = requirementId;
5
5
  this.inviterEmail = inviterEmail;
6
6
  this.vendorInfo = vendorInfo;
7
7
  this.disableMail = disableMail;
8
- this.sendCovid19Form = sendCovid19Form;
9
8
  this.tabId = tabId;
9
+ this.publicLink = publicLink;
10
10
 
11
11
  vendorInfo && validateType(vendorInfo, ContractorInfo);
12
12
  }
@@ -6,6 +6,10 @@ const REPORT_COMPLIANCE_STATUSES = {
6
6
  EXPIRED: 'EXPIRED'
7
7
  };
8
8
 
9
+ const EXPIRING_RECORDS_REPORT_COMPLIANCE_STATUSES = {
10
+ EXPIRING_SOON: 'EXPIRING_SOON'
11
+ };
12
+
9
13
  const REPORT_CONTRACTOR_TYPES = {
10
14
  VENDORS: 'Vendors',
11
15
  TENANTS: 'Tenants',
@@ -30,7 +34,9 @@ const XlsxReportTypes = {
30
34
  HIGH_LEVEL_PROPERTY_METRICS: 'HighLevelPropertyMetrics',
31
35
  MASTER_COMPLIANCE_REPORT: 'MasterComplianceReport',
32
36
  WAIVERS_REPORT: 'WaiversReport',
33
- USER_MANAGEMENT_REPORT: 'UserManagementReport'
37
+ USER_MANAGEMENT_REPORT: 'UserManagementReport',
38
+ COVERAGE_GAPS_REPORT: 'CoverageGapsReport',
39
+ EXPIRING_RECORDS_REPORT: 'ExpiringRecordsReport'
34
40
  };
35
41
 
36
42
  const ScheduledReportFrequency = {
@@ -49,6 +55,7 @@ module.exports = {
49
55
  REPORT_COMPLIANCE_STATUSES,
50
56
  REPORT_CONTRACTOR_TYPES,
51
57
  ALL_REPORT_COMPLIANCE_STATUSES,
58
+ EXPIRING_RECORDS_REPORT_COMPLIANCE_STATUSES,
52
59
  ALL_REPORT_CONTRACTOR_TYPES,
53
60
  XlsxReportTypes,
54
61
  ScheduledReportFrequency,
@@ -10,7 +10,10 @@ const Endpoints = {
10
10
  getByEmail: email => `${backendUrl}/saas/team-member/by-email/${email}`,
11
11
  delete: userId => `${backendUrl}/saas/users/${userId}`,
12
12
  deleteSingleProject: (userId, projectId) => `${backendUrl}/saas/project/${projectId}/sub-account/${userId}`,
13
- reinvite: `${backendUrl}/saas/project/team-member/reinvite`
13
+ reinvite: `${backendUrl}/saas/project/team-member/reinvite`,
14
+ getUserEncryptedData: (email, userRole) => `${backendUrl}/saas/team-member/email/${email}/role/${userRole}/signup-data`,
15
+ signupUser: `${backendUrl}/_saas/guests/signup`,
16
+ removeAllUserTraceFromDb: userId => `${backendUrl}/saas/user/automation/${userId}`
14
17
  };
15
18
 
16
19
  const invite = (invitedUser, context) => {
@@ -18,6 +21,10 @@ const invite = (invitedUser, context) => {
18
21
  return requests.putRequestHandler(Endpoints.invite, invitedUser, context, {}, params);
19
22
  };
20
23
 
24
+ const signupUser = (signupUserModel, context) => {
25
+ return requests.postRequestHandler(Endpoints.signupUser, signupUserModel, context, {}, {});
26
+ };
27
+
21
28
  const editUserRole = (userId, data, context) => {
22
29
  return requests.patchRequestHandler(Endpoints.editUserRole(userId), context, data);
23
30
  };
@@ -35,6 +42,10 @@ const getUserByEmail = (email, context) => {
35
42
  return requests.getRequestHandler(Endpoints.getByEmail(email), null, context);
36
43
  };
37
44
 
45
+ const getUserEncryptedData = (email, role, context) => {
46
+ return requests.getRequestHandler(Endpoints.getUserEncryptedData(email, role), null, context);
47
+ };
48
+
38
49
  const deleteUser = (userId, context) => {
39
50
  return requests.deleteRequestHandler(Endpoints.delete(userId), context);
40
51
  };
@@ -43,9 +54,25 @@ const deleteUserFromSingleProject = (userId, projectId, context) => {
43
54
  return requests.deleteRequestHandler(Endpoints.deleteSingleProject(userId, projectId), context);
44
55
  };
45
56
 
57
+ const removeAllUserTraceFromDb = (userId, context) => {
58
+ return requests.deleteRequestHandler(Endpoints.removeAllUserTraceFromDb(userId), context);
59
+ };
60
+
46
61
  const reinviteUser = (userId, context) => {
47
62
  const params = { id: userId };
48
63
  return requests.postRequestHandler(Endpoints.reinvite, {}, context, {}, params);
49
64
  };
50
65
 
51
- module.exports = { invite, getUsersByProjectId, getUserByEmail, deleteUser, deleteUserFromSingleProject, editUserRole, editUserProjects, reinviteUser };
66
+ module.exports = {
67
+ invite,
68
+ signupUser,
69
+ getUsersByProjectId,
70
+ getUserByEmail,
71
+ getUserEncryptedData,
72
+ deleteUser,
73
+ deleteUserFromSingleProject,
74
+ removeAllUserTraceFromDb,
75
+ editUserRole,
76
+ editUserProjects,
77
+ reinviteUser
78
+ };
@@ -1,11 +1,20 @@
1
- const EditUserModel = require('../models/edit.user.model');
2
- const userAPI = require('./users.api');
1
+ const { InviteUserModel, SignupUserModel, EditUserModel } = require('../models/users.model');
3
2
  const { validateType } = require('../../../../common/validations/typeValidations');
3
+ const { getEnv } = require('../../../../env');
4
+ const { credentials } = getEnv();
5
+ const userAPI = require('./users.api');
6
+ const util = require('../utils/util');
7
+ const httpResponseStatusCodes = require('../../../../common/httpResponseStatusCodes.json');
4
8
 
5
9
  const inviteUser = async (invitedUser, context) => {
6
10
  return userAPI.invite(invitedUser, context);
7
11
  };
8
12
 
13
+ const signupUser = (signupUserModel, context) => {
14
+ validateType(signupUserModel, SignupUserModel);
15
+ return userAPI.signupUser(signupUserModel, context);
16
+ };
17
+
9
18
  const editUserRole = async (userId, data, context) => {
10
19
  return userAPI.editUserRole(userId, data, context);
11
20
  };
@@ -23,6 +32,38 @@ const getUserByEmail = async (email, context) => {
23
32
  return userAPI.getUserByEmail(email, context);
24
33
  };
25
34
 
35
+ const getOrCreateUser = async (email, role, projectsIds, context, { fullName = role, password = credentials.strongPassword } = {}) => {
36
+ let userResponse = await getUserByEmail(email, context);
37
+
38
+ if (userResponse.data && userResponse.data.subuserId && userResponse.data.isVerified) {
39
+ return userResponse.data;
40
+ }
41
+
42
+ const inviteUserModel = new InviteUserModel(email, role, projectsIds, context);
43
+ const inviteResponse = await inviteUser([inviteUserModel], context);
44
+
45
+ if (inviteResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
46
+ throw new Error(`Failed to invite user with email: ${email}`, inviteResponse);
47
+ }
48
+
49
+ userResponse = await getUserByEmail(email, context);
50
+
51
+ //Already signup user
52
+ if (userResponse.data.isVerified) {
53
+ return userResponse.data;
54
+ }
55
+
56
+ const signupUserModel = await util.getSignupUserModel(email, role, fullName, password, context);
57
+ const signupResponse = await signupUser(signupUserModel, context);
58
+
59
+ if (signupResponse.status !== httpResponseStatusCodes.OK) {
60
+ throw new Error(`Failed to signup user with email: ${email}`, signupResponse);
61
+ }
62
+
63
+ userResponse = await getUserByEmail(email, context);
64
+ return userResponse.data;
65
+ };
66
+
26
67
  const deleteUser = (userId, context) => {
27
68
  return userAPI.deleteUser(userId, context);
28
69
  };
@@ -31,8 +72,30 @@ const deleteUserFromSingleProject = (userId, projectId, context) => {
31
72
  return userAPI.deleteUserFromSingleProject(userId, projectId, context);
32
73
  };
33
74
 
75
+ const removeAllUserTraceFromDb = (userId, context) => {
76
+ return userAPI.removeAllUserTraceFromDb(userId, context);
77
+ };
78
+
79
+ const deleteUserByEmail = async (userEmail, context) => {
80
+ const { data: user } = await getUserByEmail(userEmail, context);
81
+ return deleteUser(user.subuserId, context);
82
+ };
83
+
34
84
  const reinviteUser = (userId, context) => {
35
85
  return userAPI.reinviteUser(userId, context);
36
86
  };
37
87
 
38
- module.exports = { inviteUser, getUsersByProjectId, getUserByEmail, deleteUser, deleteUserFromSingleProject, editUserRole, editUserProjects, reinviteUser };
88
+ module.exports = {
89
+ inviteUser,
90
+ signupUser,
91
+ getUsersByProjectId,
92
+ getUserByEmail,
93
+ getOrCreateUser,
94
+ deleteUser,
95
+ deleteUserFromSingleProject,
96
+ deleteUserByEmail,
97
+ removeAllUserTraceFromDb,
98
+ editUserRole,
99
+ editUserProjects,
100
+ reinviteUser
101
+ };
@@ -1,8 +1,4 @@
1
- const EditUserModel = require('./models/edit.user.model');
2
- const coreModels = { EditUserModel };
3
-
4
- const models = { core: coreModels };
5
-
1
+ const models = require('./models/users.model');
6
2
  const services = require('./api/users.service');
7
3
 
8
4
  module.exports = { services, models };
@@ -0,0 +1,31 @@
1
+ class InviteUserModel {
2
+ constructor(email, role, projects = []) {
3
+ this.email = email;
4
+ this.role = role;
5
+ this.projects = projects;
6
+ }
7
+ }
8
+
9
+ class SignupUserModel {
10
+ constructor(fullName, role, password, encryptedData) {
11
+ this.fullName = fullName;
12
+ this.role = role;
13
+ this.password = password;
14
+ this.encryptedData = encryptedData;
15
+ }
16
+ }
17
+
18
+ class EditUserModel {
19
+ constructor(subUserId, email, role, projects = []) {
20
+ this.subUserId = subUserId;
21
+ this.email = email;
22
+ this.role = role;
23
+ this.projects = projects;
24
+ }
25
+ }
26
+
27
+ module.exports = {
28
+ InviteUserModel,
29
+ SignupUserModel,
30
+ EditUserModel
31
+ };
@@ -0,0 +1,14 @@
1
+ const { SignupUserModel } = require('../models/users.model');
2
+ const usersApi = require('../api/users.api');
3
+
4
+ const getUserEncryptedData = async (email, role, context) => {
5
+ const response = await usersApi.getUserEncryptedData(email, role, context);
6
+ return response.data;
7
+ };
8
+
9
+ const getSignupUserModel = async (email, role, fullName, password, context) => {
10
+ const userEncryptedData = await getUserEncryptedData(email, role, context);
11
+ return new SignupUserModel(fullName, role, password, userEncryptedData);
12
+ };
13
+
14
+ module.exports = { getSignupUserModel };
@@ -8,7 +8,8 @@ const Endpoints = {
8
8
  createProject: `${openapiUrl}/properties`,
9
9
  updateProject: projectId => `${openapiUrl}/properties/${projectId}`,
10
10
  getProjectSettings: projectId => `${openapiUrl}/properties/${projectId}/settings`,
11
- updateProjectSettings: projectId => `${openapiUrl}/properties/${projectId}/settings`
11
+ updateProjectSettings: projectId => `${openapiUrl}/properties/${projectId}/settings`,
12
+ getProjectServiceArea: (city, state) => `${openapiUrl}/properties/service-area?city=${city}&state=${state}`
12
13
  };
13
14
 
14
15
  const getProjectsByName = async (apiKey, params) => {
@@ -42,6 +43,10 @@ const getProjectSettings = async (apiKey, projectId) => {
42
43
  apiKey).then(res => res.data);
43
44
  };
44
45
 
46
+ const getProjectServiceArea = async (apiKey, city, state) => {
47
+ return requests.getRequestHandler(Endpoints.getProjectServiceArea(city, state), apiKey);
48
+ };
49
+
45
50
  module.exports = {
46
51
  getProjectsByName,
47
52
  getAllProjects,
@@ -49,5 +54,6 @@ module.exports = {
49
54
  createProject,
50
55
  updateProject,
51
56
  updateProjectSettings,
52
- getProjectSettings
57
+ getProjectSettings,
58
+ getProjectServiceArea
53
59
  };
@@ -28,6 +28,10 @@ const getProjectSettings = async (apiKey, projectId) => {
28
28
  return projectsApi.getProjectSettings(apiKey, projectId);
29
29
  };
30
30
 
31
+ const getProjectServiceArea = async (apiKey, city, state) => {
32
+ return projectsApi.getProjectServiceArea(apiKey, city, state);
33
+ };
34
+
31
35
  module.exports = {
32
36
  getProjectsByName,
33
37
  createProject,
@@ -35,5 +39,6 @@ module.exports = {
35
39
  getAllProjects,
36
40
  getModifiedProjects,
37
41
  updateProjectSettings,
38
- getProjectSettings
42
+ getProjectSettings,
43
+ getProjectServiceArea
39
44
  };
@@ -1,10 +0,0 @@
1
- class EditUserModel {
2
- constructor(subUserId, email, role, projects = []) {
3
- this.subUserId = subUserId;
4
- this.email = email;
5
- this.role = role;
6
- this.projects = projects;
7
- }
8
- }
9
-
10
- module.exports = EditUserModel;