@getjones/test-infra 1.3.8 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getjones/test-infra",
3
- "version": "1.3.8",
3
+ "version": "1.4.0",
4
4
  "description": "Providing internal and openapi interface",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -4,4 +4,10 @@ const validateType = (input, expectedType) => {
4
4
  }
5
5
  };
6
6
 
7
- module.exports = { validateType };
7
+ const validateDateString = dateString => {
8
+ if (isNaN(Date.parse(dateString))) {
9
+ throw TypeError(`Invalid date string '${dateString}'`);
10
+ }
11
+ };
12
+
13
+ module.exports = { validateType, validateDateString };
@@ -35,8 +35,8 @@ const archiveByContractorId = (contractorId, context) => {
35
35
  return requests.deleteRequestHandler(Endpoints.archive(contractorId), context);
36
36
  };
37
37
 
38
- const restoreByContractorId = (contractorId, context) => {
39
- return requests.postRequestHandler(Endpoints.restore(contractorId), {}, context);
38
+ const restoreByContractorId = (recordVerificationModel, context) => {
39
+ return requests.postRequestHandler(Endpoints.restore(recordVerificationModel.contractorId), recordVerificationModel, context);
40
40
  };
41
41
 
42
42
  const editContractor = (editContractorModel, context) => {
@@ -2,6 +2,7 @@ const contractorsAPI = require('./contractors.api');
2
2
  const { CreateContractorModel } = require('../models/create.contractor.model');
3
3
  const { ContractorModel, MptModel } = require('../models/edit.contractor.model');
4
4
  const { validateType } = require('../../../../common/validations/typeValidations');
5
+ const { RecordModifyDateVerificationModel } = require('../models/verification.contractor.model');
5
6
 
6
7
  const createContractor = async (createContractorModel, context) => {
7
8
  validateType(createContractorModel, CreateContractorModel);
@@ -28,8 +29,9 @@ const archiveByContractorId = (contractorId, context) => {
28
29
  return contractorsAPI.archiveByContractorId(contractorId, context);
29
30
  };
30
31
 
31
- const restoreByContractorId = (contractorId, context) => {
32
- return contractorsAPI.restoreByContractorId(contractorId, context);
32
+ const restoreByContractorId = (recordVerificationModel, context) => {
33
+ validateType(recordVerificationModel, RecordModifyDateVerificationModel);
34
+ return contractorsAPI.restoreByContractorId(recordVerificationModel, context);
33
35
  };
34
36
 
35
37
  const editContractor = (editContractorModel, context) => {
@@ -0,0 +1,33 @@
1
+ const { validateDateString } = require('../../../../common/validations/typeValidations');
2
+
3
+ class RecordModifyDateVerificationModel {
4
+ constructor(
5
+ contractorId,
6
+ contractorDateModified,
7
+ {
8
+ contractorOverrideDateModified,
9
+ requirementId,
10
+ requirementDateModified
11
+ } = {}
12
+ ) {
13
+ validateDateString(contractorDateModified);
14
+
15
+ if (contractorOverrideDateModified) {
16
+ validateDateString(contractorOverrideDateModified);
17
+ }
18
+
19
+ if (requirementId) {
20
+ validateDateString(requirementDateModified);
21
+ }
22
+
23
+ this.contractorId = contractorId;
24
+ this.contractorDateModified = contractorDateModified;
25
+ this.contractorOverrideDateModified = contractorOverrideDateModified;
26
+ this.requirementId = requirementId;
27
+ this.requirementDateModified = requirementDateModified;
28
+ }
29
+ }
30
+
31
+ module.exports = {
32
+ RecordModifyDateVerificationModel
33
+ };
@@ -28,8 +28,8 @@ const getAllGlobalRecords = async (data, pageNumber, itemsInPage, context) => {
28
28
  return cookieAuthRequests.postRequestHandler(Endpoints.getAllGlobalRecords(pageNumber, itemsInPage), data, context);
29
29
  };
30
30
 
31
- const deleteGlobalRecord = async (id, nodeBackendSecret) => {
32
- return apiKeyAuthRequests.deleteRequestHandler(Endpoints.deleteGlobalRecord(id), nodeBackendSecret);
31
+ const deleteGlobalRecord = async (id, nodeBackendSecret, globalRecordModel) => {
32
+ return apiKeyAuthRequests.deleteRequestHandler(Endpoints.deleteGlobalRecord(id), nodeBackendSecret, {}, {}, globalRecordModel);
33
33
  };
34
34
 
35
35
  const updateGlobalRecord = async (id, nodeBackendSecret, updatedGlobalRecord) => {
@@ -40,8 +40,8 @@ const getGlobalRecordServiceAreas = async context => {
40
40
  return globalRecordAPI.getGlobalRecordServiceAreas(context);
41
41
  };
42
42
 
43
- const deleteGlobalRecord = async id => {
44
- return globalRecordAPI.deleteGlobalRecord(id, nodeBackendSecret);
43
+ const deleteGlobalRecord = async (id, globalRecordModel) => {
44
+ return globalRecordAPI.deleteGlobalRecord(id, nodeBackendSecret, globalRecordModel);
45
45
  };
46
46
 
47
47
  const updateGlobalRecord = async (id, updatedGlobalRecordModel) => {
@@ -14,7 +14,8 @@ class CreateGlobalRecordModel {
14
14
  serviceAreas,
15
15
  primaryEmail,
16
16
  dba,
17
- lastPublishUserName
17
+ lastPublishUserName,
18
+ __v
18
19
  } = {}
19
20
  ) {
20
21
  this.id = id;
@@ -31,6 +32,7 @@ class CreateGlobalRecordModel {
31
32
  this.primaryEmail = primaryEmail;
32
33
  this.dba = dba;
33
34
  this.lastPublishUserName = lastPublishUserName;
35
+ this.__v = __v;
34
36
  }
35
37
  }
36
38
 
@@ -4,48 +4,58 @@ const globalRecordModels = require('../models/global.record.model');
4
4
  const { CreateGlobalRecordModel } = globalRecordModels;
5
5
  const { createGlobalRecord, getAllGlobalRecordsInPage } = globalRecordServices;
6
6
 
7
- const { getCapitalLetterUnicodeValueList, getUniqueNumber } = require('../../../../common/utils/numberUtils');
7
+ const {
8
+ getCapitalLetterUnicodeValueList,
9
+ getUniqueNumber
10
+ } = require('../../../../common/utils/numberUtils');
8
11
 
9
12
  const { SERVICE_AREAS } = require('../consts');
10
13
 
11
- const createGlobalRecordConfig = (name, { stateIndex, glPolicyNumbers } = {}) => {
14
+ const createGlobalRecordConfig = (
15
+ name,
16
+ { stateIndex, glPolicyNumbers } = {}
17
+ ) => {
12
18
  const serviceArea = getServiceAreaByIndex(stateIndex || 0);
13
19
  const uniqueNumbers = glPolicyNumbers || getUniqueNumber();
14
20
  const emailBase = name.replace(/\s+/g, '').toLowerCase();
15
21
  return {
16
- 'header': `${name}Header`,
17
- 'recordName': `${name}Name`,
18
- 'additionalContacts': [`${emailBase}@additional1.jon`, `${emailBase}@additional2.jon`],
19
- 'brokerEmails': [`${emailBase}@broker1.jon`, `${emailBase}@broker2.jon`],
20
- 'expirationDate': '2030-12-09',
21
- 'publishDate': '',
22
- 'lastPublishUserName': '',
23
- 'glPolicyNumbers': [uniqueNumbers.toString()],
24
- 'numberOfAssociatedRequests': 0,
25
- 'numberOfFilledMandatory': 0,
26
- 'dba': '',
27
- 'primaryEmail': '',
28
- 'serviceAreas': [
29
- getServiceArea(serviceArea)
30
- ]
22
+ header: `${name}Header`,
23
+ recordName: `${name}Name`,
24
+ additionalContacts: [
25
+ `${emailBase}@additional1.jon`,
26
+ `${emailBase}@additional2.jon`
27
+ ],
28
+ brokerEmails: [`${emailBase}@broker1.jon`, `${emailBase}@broker2.jon`],
29
+ expirationDate: '2030-12-09',
30
+ publishDate: '',
31
+ lastPublishUserName: '',
32
+ glPolicyNumbers: [uniqueNumbers.toString()],
33
+ numberOfAssociatedRequests: 0,
34
+ numberOfFilledMandatory: 0,
35
+ dba: '',
36
+ primaryEmail: '',
37
+ serviceAreas: [getServiceArea(serviceArea)],
38
+ __v: 0
31
39
  };
32
40
  };
33
41
 
34
42
  const getServiceArea = state => {
35
43
  return {
36
- 'city': `${state}TestCity`,
37
- 'state': state
44
+ city: `${state}TestCity`,
45
+ state: state
38
46
  };
39
47
  };
40
48
 
41
- const createGlobalRecordConfigs = (nameList, { stateIndexes, glPolicyNumbers } = {}) => {
42
- return nameList.map((name, index) => createGlobalRecordConfig(
43
- name,
44
- {
49
+ const createGlobalRecordConfigs = (
50
+ nameList,
51
+ { stateIndexes, glPolicyNumbers } = {}
52
+ ) => {
53
+ return nameList.map((name, index) =>
54
+ createGlobalRecordConfig(name, {
45
55
  stateIndex: stateIndexes ? stateIndexes[index] : index,
46
56
  glPolicyNumbers: glPolicyNumbers ? glPolicyNumbers[index] : null
47
- }
48
- ));
57
+ })
58
+ );
49
59
  };
50
60
 
51
61
  const createGlobalRecordModel = config => {
@@ -64,7 +74,8 @@ const createGlobalRecordModel = config => {
64
74
  serviceAreas: config.serviceAreas,
65
75
  primaryEmail: config.primaryEmail,
66
76
  dba: config.dba,
67
- lastPublishUserName: config.lastPublishUserName
77
+ lastPublishUserName: config.lastPublishUserName,
78
+ __v: config.__v
68
79
  }
69
80
  );
70
81
  };
@@ -81,7 +92,10 @@ const getCreateRandomGlobalRecordModels = nameList => {
81
92
  const createGlobalRecords = async (globalRecordModelList, context) => {
82
93
  const newGlobalRecodDetailsList = new Array();
83
94
  for (globalRecordModel of globalRecordModelList) {
84
- const newGlobalRecordDetails = await createGlobalRecord(globalRecordModel, context);
95
+ const newGlobalRecordDetails = await createGlobalRecord(
96
+ globalRecordModel,
97
+ context
98
+ );
85
99
  newGlobalRecodDetailsList.push(newGlobalRecordDetails);
86
100
  }
87
101
 
@@ -92,7 +106,10 @@ const getGlobalRecordsByNumberOfPages = async (numberOfPages, context) => {
92
106
  const allGlobalRecords = new Array();
93
107
 
94
108
  for (let pageNumber = 1; pageNumber <= numberOfPages; pageNumber++) {
95
- const allGlobalRecordsInPage = await getAllGlobalRecordsInPage(pageNumber, context);
109
+ const allGlobalRecordsInPage = await getAllGlobalRecordsInPage(
110
+ pageNumber,
111
+ context
112
+ );
96
113
  allGlobalRecords.push(allGlobalRecordsInPage);
97
114
  }
98
115
 
@@ -104,11 +121,16 @@ const getServiceAreaByIndex = stateIndex => {
104
121
  };
105
122
 
106
123
  const getGlobalRecordsDefaultNameList = (nameBase, listLength) => {
107
- const letterUnicodeValueList = getCapitalLetterUnicodeValueList({ listLength });
124
+ const letterUnicodeValueList = getCapitalLetterUnicodeValueList({
125
+ listLength
126
+ });
108
127
 
109
128
  //How much times same letter will appear in one index on the array
110
129
  const repeatTimes = 4;
111
- return letterUnicodeValueList.map(unicode => `${nameBase} ${String.fromCharCode(unicode).repeat(repeatTimes)}`);
130
+ return letterUnicodeValueList.map(
131
+ unicode =>
132
+ `${nameBase} ${String.fromCharCode(unicode).repeat(repeatTimes)}`
133
+ );
112
134
  };
113
135
 
114
136
  module.exports = {
@@ -1,14 +1,8 @@
1
1
  const projectsApi = require('./projects.api');
2
- const { core: accounts } = require('../../../accounts');
3
2
  const { validateType } = require('../../../../../common/validations/typeValidations');
4
3
  const CreateProjectModel = require('../../models/core/create.project.model');
5
4
  const UpdateProjectModel = require('../../models/core/update.project.model');
6
5
 
7
- const getProjectsByAccountName = async (accountName, context) => {
8
- const accountId = await accounts.getAccountId(accountName, context);
9
- return getProjectsByAccountId(accountId, context);
10
- };
11
-
12
6
  const getProjectsByAccountId = (accountId, context) => {
13
7
  return projectsApi.getProjectsByAccountId(accountId, context);
14
8
  };
@@ -17,15 +11,21 @@ const getProjectByProjectId = (projectId, context) => {
17
11
  return projectsApi.getProjectByProjectId(projectId, context);
18
12
  };
19
13
 
20
- const getProjectsByName = async (accountId, projectName, context) => {
14
+ const getProjectByName = async (accountId, projectName, context) => {
21
15
  const { data: projects } = await getProjectsByAccountId(accountId, context);
22
- const filteredProjects = projects.filter(project => project.projectName === projectName);
23
- return filteredProjects;
16
+ const requestedProject = projects.find(project => project.projectName === projectName);
17
+ return requestedProject ? requestedProject : null;
24
18
  };
25
19
 
26
20
  const deleteProjectByName = async (accountId, projectName, context) => {
27
- const projects = await getProjectsByName(accountId, projectName, context);
28
- projects.map(async project => await projectsApi.deleteProjectById(project.projectId, context));
21
+ const { data: projects } = await getProjectsByAccountId(accountId, context);
22
+ const filteredProjects = projects.filter(project => project.projectName === projectName);
23
+
24
+ await Promise.all(
25
+ filteredProjects.map(
26
+ async project => await projectsApi.deleteProjectById(project.projectId, context)
27
+ )
28
+ );
29
29
  };
30
30
 
31
31
  const createProject = (createProjectModel, context) => {
@@ -34,14 +34,14 @@ const createProject = (createProjectModel, context) => {
34
34
  };
35
35
 
36
36
  const getOrCreateProject = async (createProjectModel, context) => {
37
- let existingProjects = await getProjectsByName(createProjectModel.userId, createProjectModel.projectName, context);
37
+ let project = await getProjectByName(createProjectModel.userId, createProjectModel.projectName, context);
38
38
 
39
- if (!existingProjects.length) {
39
+ if (!project) {
40
40
  await createProject(createProjectModel, context);
41
- existingProjects = await getProjectsByName(createProjectModel.userId, createProjectModel.projectName, context);
41
+ project = await getProjectByName(createProjectModel.userId, createProjectModel.projectName, context);
42
42
  }
43
43
 
44
- return existingProjects[0] || null;
44
+ return project;
45
45
  };
46
46
 
47
47
  const updateProject = (updateProjectModel, context) => {
@@ -50,12 +50,11 @@ const updateProject = (updateProjectModel, context) => {
50
50
  };
51
51
 
52
52
  module.exports = {
53
- getProjectsByAccountName,
53
+ getOrCreateProject,
54
54
  getProjectsByAccountId,
55
+ getProjectByProjectId,
56
+ getProjectByName,
55
57
  createProject,
56
58
  deleteProjectByName,
57
- getOrCreateProject,
58
- updateProject,
59
- getProjectsByName,
60
- getProjectByProjectId
59
+ updateProject
61
60
  };
@@ -0,0 +1,3 @@
1
+ const DEFAULT_PROJECT_NAME = 'My First Project';
2
+
3
+ module.exports = { NAME: DEFAULT_PROJECT_NAME };
@@ -16,4 +16,9 @@ const models = {
16
16
  settings: settingsModels
17
17
  };
18
18
 
19
- module.exports = { models, services };
19
+ const utils = require('./utils/utils');
20
+ const consts = {
21
+ DEFAULT_PROJECT: require('./consts/defaultProject')
22
+ };
23
+
24
+ module.exports = { models, services, utils, consts };
@@ -1,6 +1,21 @@
1
- function CreateProjectModel(accountId, name, description, address, number, startDate, endDate,
2
- city, state, zipCode, companyNameForProject, certificateHolder = '', additionalInsured = '',
3
- tenantSolutionEnabled = 0, onboardingEnabled = 0, automaticRenewalEnabled = 0) {
1
+ function CreateProjectModel(
2
+ accountId,
3
+ name,
4
+ description,
5
+ address,
6
+ number,
7
+ startDate,
8
+ endDate,
9
+ city,
10
+ state,
11
+ zipCode,
12
+ companyNameForProject,
13
+ certificateHolder = '',
14
+ additionalInsured = '',
15
+ tenantSolutionEnabled = 0,
16
+ onboardingEnabled = 0,
17
+ automaticRenewalEnabled = 0
18
+ ) {
4
19
  this.projectName = name;
5
20
  this.userId = accountId;
6
21
  this.regionOrDivision = description;
@@ -1,6 +1,23 @@
1
- function UpdateProjectModel(accountId, projectId, name, description, address, number, startDate, endDate,
2
- city, state, zipCode, companyNameForProject, certificateHolder = '', additionalInsured = '',
3
- tenantSolutionEnabled = 0, onboardingEnabled = 0, automaticRenewalEnabled = 0, onboardedVendors = 0) {
1
+ function UpdateProjectModel(
2
+ accountId,
3
+ projectId,
4
+ name,
5
+ description,
6
+ address,
7
+ number,
8
+ startDate,
9
+ endDate,
10
+ city,
11
+ state,
12
+ zipCode,
13
+ companyNameForProject,
14
+ certificateHolder = '',
15
+ additionalInsured = '',
16
+ tenantSolutionEnabled = 0,
17
+ onboardingEnabled = 0,
18
+ automaticRenewalEnabled = 0,
19
+ onboardedVendors = 0
20
+ ) {
4
21
  this.projectId = projectId;
5
22
  this.projectName = name;
6
23
  this.userId = accountId;
@@ -0,0 +1,61 @@
1
+ const services = require('../api/core/projects.service');
2
+
3
+ const CreateProjectModel = require('../models/core/create.project.model');
4
+ const UpdateProjectModel = require('../models/core/update.project.model');
5
+
6
+ const { NAME: DEFAULT_PROJECT_NAME } = require('../consts/defaultProject');
7
+
8
+ const getDefaultProjectId = async (accountId, context) => {
9
+ const defaultProject = await services.getProjectByName(accountId, DEFAULT_PROJECT_NAME, context);
10
+ return defaultProject ? defaultProject.projectId : null;
11
+ };
12
+
13
+ const getOrCreateProject = (accountId, projectConfig, context) => {
14
+ const createProjectModel = getCreateProjectModel(accountId, projectConfig);
15
+ return services.getOrCreateProject(createProjectModel, context);
16
+ };
17
+
18
+ const getCreateProjectModel = (accountId, projectData) => {
19
+ const createProjectModel = new CreateProjectModel(
20
+ accountId,
21
+ projectData.name || projectData['Property Name'] || projectData['Project Name'],
22
+ projectData.description || projectData['Region/Division'] || 'N/A',
23
+ projectData.address || projectData['Address'] || 'N/A',
24
+ projectData.number || projectData['Property Number'] || projectData['Project Number'] || 'N/A',
25
+ projectData.startDate || projectData['Start Date'] || '01/01/2021',
26
+ projectData.endDate || projectData['End Date'] || '01/01/2021',
27
+ projectData.city || projectData['City'] || 'N/A',
28
+ projectData.state || projectData['State'] || 'Alabama',
29
+ projectData.zipCode || projectData['Zip Code'] || '11111',
30
+ projectData.companyNameForProject || projectData['Company Name (for external communications)']
31
+ );
32
+ return createProjectModel;
33
+ };
34
+
35
+ const getUpdateProjectModel = (accountId, projectId, projectData) => {
36
+ const updateProjectModel = new UpdateProjectModel(
37
+ accountId,
38
+ projectId,
39
+ projectData.name || projectData['Property Name'] || projectData['Project Name'],
40
+ projectData.description || projectData['Region/Division'],
41
+ projectData.address || projectData['Address'],
42
+ projectData.number || projectData['Property Number'] || projectData['Project Number'],
43
+ projectData.startDate || projectData['Start Date'],
44
+ projectData.endDate || projectData['End Date'],
45
+ projectData.city || projectData['City'],
46
+ projectData.state || projectData['State'],
47
+ projectData.zipCode || projectData['Zip Code'] || '11111',
48
+ projectData.companyNameForProject || projectData['Company Name (for external communications)']
49
+ );
50
+
51
+ return updateProjectModel;
52
+ };
53
+
54
+ // combine the config handling in single func
55
+
56
+ module.exports = {
57
+ getOrCreateProject,
58
+ getDefaultProjectId,
59
+ getCreateProjectModel,
60
+ getUpdateProjectModel
61
+ };
@@ -0,0 +1,42 @@
1
+ const { expect } = require('chai');;
2
+
3
+ const { validateDateString } = require('../src/common/validations/typeValidations');
4
+ const VALID_DATE_STRINGS = Object.freeze([
5
+ '2022-08-03T11:47:07.499Z',
6
+ '2022-08-03T14:16:27.000+0000'
7
+
8
+ ]);
9
+ const INVALID_DATE_STRINGS = Object.freeze([
10
+ '2022-08-03T11:47:07.',
11
+ '2022-08-03T11:47:07.499Z1',
12
+ '2022-08-03T11:47:07.Z',
13
+ '2022-08-03T11:47:07.499Za',
14
+ '2022-0803T11:47:07.499Z',
15
+ '2022-08-03T100:47:07.499Z',
16
+ '2022-08-03T11:4:07.499Z',
17
+ '2022-08-03T11:47:7z.499Z',
18
+ '2022-08-03T11:47:07.a499Z',
19
+ '2022-0803T14:16:27.000+0000',
20
+ '2022-08-03T14:16:27.000+000a',
21
+ '2022-08-03T14:16:27.000+0000c',
22
+ '2022-08-0314:16:27.000+0000',
23
+ '2022-08-03x14:16:27.000+0000',
24
+ '2022-08-03a14:16:27.000+0000',
25
+ '2022-08-03T14:16:2.000+0000',
26
+ 'asd1q2123'
27
+
28
+ ]);
29
+
30
+ describe('Validation | Test Validation functions', function() {
31
+ it('Should validate date strings', () => {
32
+ for (const dateString of VALID_DATE_STRINGS) {
33
+ expect(() => validateDateString(dateString), `Expect string: '${dateString}' to pass date validation.`).to.not.throw(TypeError);
34
+ }
35
+ });
36
+
37
+ it('Should throw error for invalid date strings', () => {
38
+ for (const dateString of INVALID_DATE_STRINGS) {
39
+ expect(() => validateDateString(dateString), `Expect string: '${dateString}' to fail date validation.`).to.throw(TypeError);
40
+ }
41
+ });
42
+ });