@getjones/test-infra 4.4.14 → 4.4.16

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": "4.4.14",
3
+ "version": "4.4.16",
4
4
  "description": "Providing internal and openapi interface",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ COMPLAINCE_ISSUE: 'complianceIssue',
3
+ DRAFT: 'draft',
4
+ MUTED: 'muted'
5
+ };
@@ -17,7 +17,7 @@ const roles = {
17
17
  const inviteSaasUser = async (username, role, projectIds, context, { hasCompleteAccessPermission } = {}) => {
18
18
  const userResponse = await users.services.getUserByEmail(username, context);
19
19
 
20
- if (userResponse.data && userResponse.data.subuserId) {
20
+ if (userResponse.data && userResponse.data.id) {
21
21
  const { projectPermissions } = userResponse.data;
22
22
  const projectPermissionsIds = projectPermissions.map(projectPermission => projectPermission.projectId);
23
23
 
@@ -4,7 +4,10 @@ const { backendUrl } = require('../../../../env').getEnv();
4
4
  const Endpoints = {
5
5
  getPolicyFilesForVendorReport: requestId => `${backendUrl}/saas/request/${requestId}/policy-files`,
6
6
  getPreSignedUrlByPolicyId: policyFileId => `${backendUrl}/saas/policy-file/${policyFileId}`,
7
- getAuditPolicyFilesByAuditId: (recordId, auditId) => `${backendUrl}/saas/integration-tests/record/${recordId}/audit/${auditId}/policy-files`
7
+ getAuditPolicyFilesByAuditId: (recordId, auditId) => `${backendUrl}/saas/integration-tests/record/${recordId}/audit/${auditId}/policy-files`,
8
+ unpublishPolicyFile: `${backendUrl}/saas/policy-file/unpublish`,
9
+ publishPolicyFile: `${backendUrl}/saas/policy-file/publish`,
10
+ getPolicyFilesRequireAudit: recordId => `${backendUrl}/saas/integration-tests/record/${recordId}/policy-files-to-audit`
8
11
  };
9
12
  const getPolicyFilesForVendorReport = async (requestId, context) => {
10
13
  return requests.getRequestHandler(Endpoints.getPolicyFilesForVendorReport(requestId), {}, context);
@@ -18,8 +21,23 @@ const getAuditPolicyFiles = async (recordId, auditId, context) => {
18
21
  return requests.getRequestHandler(Endpoints.getAuditPolicyFilesByAuditId(recordId, auditId), {}, context);
19
22
  };
20
23
 
24
+ const unpublishPolicyFile = async (unpublishPolicyFileModel, context) => {
25
+ return requests.putRequestHandler(Endpoints.unpublishPolicyFile, unpublishPolicyFileModel, context);
26
+ };
27
+
28
+ const publishPolicyFile = async (publishPolicyFileModel, context) => {
29
+ return requests.putRequestHandler(Endpoints.publishPolicyFile, publishPolicyFileModel, context);
30
+ };
31
+
32
+ const getPolicyFilesRequireAudit = async (recordId, context) => {
33
+ return requests.getRequestHandler(Endpoints.getPolicyFilesRequireAudit(recordId), {}, context);
34
+ };
35
+
21
36
  module.exports = {
22
37
  getPolicyFilesForVendorReport,
23
38
  getPreSignedUrlByPolicyId,
24
- getAuditPolicyFiles
39
+ getAuditPolicyFiles,
40
+ unpublishPolicyFile,
41
+ publishPolicyFile,
42
+ getPolicyFilesRequireAudit
25
43
  };
@@ -1,4 +1,6 @@
1
1
  const policyFileApi = require('./policy.file.api');
2
+ const timeUtils = require('../../../../common/utils/timeUtils');
3
+ const { PolicyFileToSetPublishFlagRequestBodyModel } = require('../models/set.publish.flag.to.policy.model');
2
4
 
3
5
  const httpResponseStatusCodes = require('../../../../common/httpResponseStatusCodes.json');
4
6
 
@@ -32,8 +34,84 @@ const getAuditPolicyFiles = async (recordId, auditId, context) => {
32
34
  return getAuditPolicyFilesResponse;
33
35
  };
34
36
 
37
+ const unpublishPolicyFile = async (unpublishPolicyFileModel, context, { shouldExpectError } = {}) => {
38
+ const unpublishResponse = await policyFileApi.unpublishPolicyFile(unpublishPolicyFileModel, context);
39
+
40
+ if (unpublishResponse.status !== httpResponseStatusCodes.NO_CONTENT && !shouldExpectError) {
41
+ throw new Error(`Failed to unpublish policy file - ${unpublishPolicyFileModel.policyFileId}`);
42
+ }
43
+
44
+ return unpublishResponse;
45
+ };
46
+
47
+ const publishPolicyFile = async (publishPolicyFileModel, context, { shouldExpectError } = {}) => {
48
+ const publishResponse = await policyFileApi.publishPolicyFile(publishPolicyFileModel, context);
49
+
50
+ if (publishResponse.status !== httpResponseStatusCodes.NO_CONTENT && !shouldExpectError) {
51
+ throw new Error(`Failed to unpublish policy file - ${publishPolicyFileModel.policyFileId}`);
52
+ }
53
+
54
+ return publishResponse;
55
+ };
56
+
57
+ const getSetPublishFlagToPolicyFileModel = async (requestId, policyFileId, context) => {
58
+ const { isPublished, dateModified } = await getPolicyDetailsForPublishModel(requestId, policyFileId, context);
59
+
60
+ return new PolicyFileToSetPublishFlagRequestBodyModel(policyFileId, isPublished, dateModified);
61
+ };
62
+
63
+ const getPolicyDetailsForPublishModel = async (requestId, policyFileId, context) => {
64
+ const getPoliciesResponse = await getPolicyFilesForVendorReport(requestId, context);
65
+
66
+ for (const policy of getPoliciesResponse.data) {
67
+ if (policy.policyFileId === policyFileId) {
68
+ return {
69
+ isPublished: policy.isPublished,
70
+ dateModified: policy.dateModified
71
+ };
72
+ }
73
+ }
74
+ throw new Error(`No match found for policy file id: ${policyFileId}`);
75
+ };
76
+
77
+ const getPolicyFilesIfExist = async (recordId, context) => {
78
+ let retries = 10;
79
+ let policiesToReviewResponse;
80
+ let policyFiles = [];
81
+
82
+ while (policyFiles.length === 0 && retries > 0) {
83
+ //Busy wait for it takes time to get policy file to review
84
+ await timeUtils.waitFor(0.5).seconds;
85
+
86
+ policiesToReviewResponse = await policyFileApi.getPolicyFilesRequireAudit(recordId, context);
87
+ policyFiles = policiesToReviewResponse.data;
88
+
89
+ retries--;
90
+ }
91
+
92
+ if (policyFiles.length === 0) {
93
+ throw new Error(`No policy files to review where found for record ${recordId}`);
94
+ }
95
+
96
+ return policiesToReviewResponse;
97
+ };
98
+
99
+ const getPolicyFilesRequireAudit = async (recordId, context) => {
100
+ const getPolicyFilesResponse = await getPolicyFilesIfExist(recordId, context);
101
+
102
+ if (getPolicyFilesResponse.status !== httpResponseStatusCodes.OK) {
103
+ throw new Error('Failed to get policy files that require audit');
104
+ }
105
+
106
+ return getPolicyFilesResponse;
107
+ };
108
+
35
109
  module.exports = {
36
110
  getPolicyFilesForVendorReport,
37
111
  getPreSignedUrlByPolicyId,
38
- getAuditPolicyFiles
112
+ getAuditPolicyFiles,
113
+ getSetPublishFlagToPolicyFileModel,
114
+ unpublishPolicyFile,
115
+ publishPolicyFile,
116
+ getPolicyFilesRequireAudit
39
117
  };
@@ -0,0 +1,13 @@
1
+ class PolicyFileToSetPublishFlagRequestBodyModel {
2
+ constructor(
3
+ policyFileId,
4
+ isPublished,
5
+ policyFileDateModified
6
+ ) {
7
+ this.policyFileId = policyFileId;
8
+ this.isPublished = isPublished;
9
+ this.policyFileDateModified = policyFileDateModified;
10
+ }
11
+ }
12
+
13
+ module.exports = { PolicyFileToSetPublishFlagRequestBodyModel };
@@ -7,6 +7,7 @@ const { RequestModel } = require('../models/edit.request.model');
7
7
  const { validateType } = require('../../../../common/validations/typeValidations');
8
8
  const httpResponseStatusCodes = require('../../../../common/httpResponseStatusCodes.json');
9
9
  const activationStatuses = require('../../../../common/consts/activationStatuses');
10
+ const { HomepageRequestCriteriaModel } = require('../models/homepageRequestCriteriaModel');
10
11
 
11
12
  const createRequest = async (createRequestModel, context) => {
12
13
  validateType(createRequestModel, CreateRequestModel);
@@ -179,9 +180,18 @@ const getInnerPageRequests = async (requestListCriteriaModel, context) => {
179
180
  return response.data;
180
181
  };
181
182
 
182
- const getHomePageRequests = async (requestListCriteriaModel, context) => {
183
- validateType(requestListCriteriaModel, RequestListCriteriaModel);
184
- const response = await requestsAPI.getHomePageRequests(requestListCriteriaModel, context);
183
+ const getHomePageRequests = async (context, { sortBy, sortOrder, pageNumber, attentionTab, shouldExceptError } = {}) => {
184
+ const homepageRequestCriteriaModel = new HomepageRequestCriteriaModel({ sortBy, sortOrder, attentionTab, pageNumber });
185
+ return getHomePageRequestsByModel(homepageRequestCriteriaModel, context, shouldExceptError);
186
+ };
187
+
188
+ const getHomePageRequestsByModel = async (homepageRequestCriteriaModel, context, shouldExceptError) => {
189
+ validateType(homepageRequestCriteriaModel, HomepageRequestCriteriaModel);
190
+ const response = await requestsAPI.getHomePageRequests(homepageRequestCriteriaModel, context);
191
+
192
+ if (shouldExceptError) {
193
+ return response;
194
+ }
185
195
 
186
196
  if (response.status !== httpResponseStatusCodes.OK) {
187
197
  throw Error(`Get requests home page has fail\n${response}`);
@@ -190,6 +200,16 @@ const getHomePageRequests = async (requestListCriteriaModel, context) => {
190
200
  return response.data;
191
201
  };
192
202
 
203
+ const getHomePageRequestsCount = async context => {
204
+ const response = await requestsAPI.getHomePageRequestsCount(context);
205
+
206
+ if (response.status !== httpResponseStatusCodes.OK) {
207
+ throw Error(`Get requests count home page has fail\n${response}`);
208
+ }
209
+
210
+ return response.data;
211
+ };
212
+
193
213
  const getAllRequestsByName = async (recordName, accountId, context) => {
194
214
  const { data: requestsInAccount } = await requestsAPI.getRequestsByAccountId(accountId, context);
195
215
  const requests = requestsInAccount.filter(requests => requests.record.company === recordName);
@@ -265,6 +285,7 @@ module.exports = {
265
285
  getRequestFromTabByRecordId,
266
286
  getInnerPageRequests,
267
287
  getHomePageRequests,
288
+ getHomePageRequestsCount,
268
289
  getAllRequestsByName,
269
290
  getRequestByName,
270
291
  getDraftRequestList,
@@ -0,0 +1,19 @@
1
+ const AttentionTab = require('../../../../common/consts/homepage/AttentionTab');
2
+
3
+ class HomepageRequestCriteriaModel {
4
+ constructor({
5
+ sortBy,
6
+ sortOrder,
7
+ attentionTab = AttentionTab.COMPLAINCE_ISSUE,
8
+ pageNumber = 1
9
+ } = {}) {
10
+ this.sortBy = sortBy,
11
+ this.sortOrder = sortOrder,
12
+ this.attentionTab = attentionTab,
13
+ this.pageNo = pageNumber;
14
+ }
15
+ }
16
+
17
+ module.exports = {
18
+ HomepageRequestCriteriaModel
19
+ };
@@ -54,7 +54,7 @@ const getTenantUserByEmail = async (projectId, email, context) => {
54
54
  const getOrCreateTenantUser = async (projectId, email, company, requestId, context, { fullName = 'Tenant User', password = credentials.strongPassword, toSignUp = true, expectError } = {}) => {
55
55
  let tenantUser = await getTenantUserByEmail(projectId, email, context);
56
56
 
57
- if (tenantUser && tenantUser.subuserId && tenantUser.isVerified) {
57
+ if (tenantUser && tenantUser.id && tenantUser.isVerified) {
58
58
  return tenantUser;
59
59
  }
60
60
 
@@ -90,10 +90,10 @@ const getOrCreateTenantUser = async (projectId, email, company, requestId, conte
90
90
  const removeAllTenantUsersFromProject = async (projectId, context) => {
91
91
  const tenantsListInProjects = await getTenantUsersByProjectId(projectId, context);
92
92
  for (const tenant of tenantsListInProjects) {
93
- const deleteInviteResponse = await removeTenantUser(projectId, tenant.subuserId, context);
93
+ const deleteInviteResponse = await removeTenantUser(projectId, tenant.id, context);
94
94
  expect(deleteInviteResponse.status, 'Failed to delete user invite').to.equal(httpResponseStatusCodes.OK);
95
95
 
96
- const deleteUserResponse = await users.removeAllUserTraceFromDb(tenant.subuserId, context);
96
+ const deleteUserResponse = await users.removeAllUserTraceFromDb(tenant.id, context);
97
97
  expect(deleteUserResponse.status, 'Failed to completely delete user from DB').to.equal(httpResponseStatusCodes.NO_CONTENT);
98
98
  }
99
99
  };
@@ -24,11 +24,23 @@ const editUserRole = async (userId, data, context) => {
24
24
  return userAPI.editUserRole(userId, data, context);
25
25
  };
26
26
 
27
- const editUserProjects = async (editUserModel, context) => {
27
+ const editUserProjectsByModel = async (editUserModel, context) => {
28
28
  validateType(editUserModel, EditUserModel);
29
29
  return userAPI.editUserProjects([editUserModel], context);
30
30
  };
31
31
 
32
+ const editUserProjects = async (userId, userEmail, role, projectsIds, context, { hasCompleteAccessPermission } = {}) => {
33
+ const editUserModel = new EditUserModel(userId, userEmail, role, projectsIds, hasCompleteAccessPermission);
34
+
35
+ const response = await editUserProjectsByModel(editUserModel, context);
36
+
37
+ if (response.status !== httpResponseStatusCodes.NO_CONTENT) {
38
+ throw new Error('Failed to edit user projects');
39
+ }
40
+
41
+ return response;
42
+ };
43
+
32
44
  const getUsersByProjectId = async (projectId, context) => {
33
45
  return userAPI.getUsersByProjectId(projectId, context);
34
46
  };
@@ -57,7 +69,7 @@ const getEnabledAndDisabledByEmail = async (email, context) => {
57
69
  return response.data;
58
70
  };
59
71
 
60
- const getOrCreateUser = async (email, role, projectsIds, context, { fullName = role, password = credentials.strongPassword } = {}) => {
72
+ const getOrCreateUser = async (email, role, projectsIds, context, { fullName = role, password = credentials.strongPassword, expectError, hasCompleteAccessPermission } = {}) => {
61
73
  let userResponse = await getUserByEmail(email, context);
62
74
 
63
75
  if (userResponse.data !== '' && userResponse.status === httpResponseStatusCodes.OK) {
@@ -66,16 +78,18 @@ const getOrCreateUser = async (email, role, projectsIds, context, { fullName = r
66
78
 
67
79
  projectsIds = projectsIds.filter(projectId => !projectPermissionsIds.includes(projectId));
68
80
 
69
- if (userResponse.data && userResponse.data.subuserId && userResponse.data.isVerified && !projectsIds.length) {
81
+ if (userResponse.data && userResponse.data.id && userResponse.data.isVerified && !projectsIds.length) {
70
82
  return userResponse.data;
71
83
  }
72
84
  }
73
85
 
74
- const inviteUserModel = new InviteUserModel(email, role, projectsIds);
86
+ const inviteUserModel = new InviteUserModel(email, role, projectsIds, hasCompleteAccessPermission);
75
87
  const inviteResponse = await inviteUser([inviteUserModel], context);
76
88
 
77
- if (inviteResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
89
+ if (inviteResponse.status !== httpResponseStatusCodes.NO_CONTENT && !expectError) {
78
90
  throw new Error(`Failed to invite user with email: ${email}\n${inviteResponse}`);
91
+ } else if (expectError) {
92
+ return inviteResponse;
79
93
  }
80
94
 
81
95
  userResponse = await getUserByEmail(email, context);
@@ -126,7 +140,7 @@ const removeAllUserTraceFromDb = (userId, context) => {
126
140
 
127
141
  const deleteUserByEmail = async (userEmail, context) => {
128
142
  const { data: user } = await getUserByEmail(userEmail, context);
129
- return user ? deleteUser(user.subuserId, context) : null;
143
+ return user ? deleteUser(user.id, context) : null;
130
144
  };
131
145
 
132
146
  const reinviteUser = (userId, context) => {
@@ -232,6 +246,7 @@ module.exports = {
232
246
  removeAllUserTraceFromDb,
233
247
  editUserRole,
234
248
  editUserProjects,
249
+ editUserProjectsByModel,
235
250
  reinviteUser,
236
251
  editUserEmailNotificationsSettings,
237
252
  sendForgetPasswordMail,
@@ -17,11 +17,12 @@ class SignupUserModel {
17
17
  }
18
18
 
19
19
  class EditUserModel {
20
- constructor(subUserId, email, role, projects = []) {
20
+ constructor(subUserId, email, role, projects = [], hasCompleteAccessPermission) {
21
21
  this.subUserId = subUserId;
22
22
  this.email = email;
23
23
  this.role = role;
24
24
  this.projects = projects;
25
+ this.hasCompleteAccessPermission = hasCompleteAccessPermission;
25
26
  }
26
27
  }
27
28