@getjones/test-infra 2.7.9 → 2.7.11

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.7.9",
3
+ "version": "2.7.11",
4
4
  "description": "Providing internal and openapi interface",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@ const { InviteUserModel } = users.models;
8
8
 
9
9
  const defaultsPassword = credentials.strongPassword;
10
10
  const roles = {
11
- readOnly: 'Read-only',
11
+ readOnly: 'Read-only User',
12
12
  inviter: 'Inviter',
13
13
  cm: 'Compliance Manager'
14
14
  };
@@ -1,6 +1,8 @@
1
1
  const { getProjectSettingsByProjectId, updateProjectSettingsByProjectId } = require('./project.settings.api');
2
2
  const { validateType } = require('../../../../../common/validations/typeValidations');
3
3
  const UpdateProjectSettingsModel = require('../../models/settings/update.project.settings.model');
4
+ const util = require('../../utils/utils');
5
+ const httpResponseStatusCodes = require('../../../../../common/httpResponseStatusCodes.json');
4
6
 
5
7
  const updateProjectSettings = (updateProjectSettingsModel, context) => {
6
8
  validateType(updateProjectSettingsModel, UpdateProjectSettingsModel);
@@ -11,7 +13,23 @@ const getProjectSettings = (projectId, context) => {
11
13
  return getProjectSettingsByProjectId(projectId, context);
12
14
  };
13
15
 
16
+ const setProjectSettings = async (projectId, settings, context) => {
17
+ const isUIConfig = util.isUIConfig(settings);
18
+
19
+ const settingsConfig = isUIConfig ? util.parseProjectSettingsConfig(projectId, settings) : settings;
20
+ const settingsModel = new UpdateProjectSettingsModel(settingsConfig);
21
+
22
+ const updateResponse = await updateProjectSettings(settingsModel, context);
23
+
24
+ if (updateResponse.status !== httpResponseStatusCodes.OK) {
25
+ throw new Error(`Failed to set project: ${projectId} settings\n${updateResponse.statusText}`);
26
+ }
27
+
28
+ return updateResponse;
29
+ };
30
+
14
31
  module.exports = {
15
32
  updateProjectSettings,
16
- getProjectSettings
33
+ getProjectSettings,
34
+ setProjectSettings
17
35
  };
@@ -1,39 +1,41 @@
1
- function UpdateProjectSettingsModel({
2
- autoGaps = defaultAutoGaps,
3
- autoRenewals = false,
4
- marketplace = defaultMarketplace,
5
- ocrEnabled = false,
6
- onboardingPhase = false,
7
- projectId = null,
8
- qrEnabled = false,
9
- tenantSolution = false,
10
- autocompleteAddVendors = defaultAutocompleteAddVendors
11
- }) {
12
- this.autoGaps = autoGaps;
13
- this.autoRenewals = autoRenewals;
14
- this.marketplace = marketplace;
15
- this.ocrEnabled = ocrEnabled;
16
- this.onboardingPhase = onboardingPhase;
17
- this.projectId = projectId;
18
- this.qrEnabled = qrEnabled;
19
- this.tenantSolution = tenantSolution;
20
- this.autocompleteAddVendors = autocompleteAddVendors;
1
+ class UpdateProjectSettingsModel {
2
+ constructor(
3
+ {
4
+ autoGaps = {},
5
+ autoRenewals = false,
6
+ marketplaceSettings = {},
7
+ ocrEnabled = false,
8
+ onboardingPhase = false,
9
+ projectId = null,
10
+ tenantSolution = false,
11
+ autocompleteSettings = {}
12
+ } = {}
13
+ ) {
14
+ this.autoGaps = { ... DEFAULT_AUTOGAPS, ... autoGaps };
15
+ this.autoRenewals = autoRenewals;
16
+ this.marketplaceSettings = { ... DEFAULT_MARKETPLACE, ... marketplaceSettings };
17
+ this.ocrEnabled = ocrEnabled;
18
+ this.onboardingPhase = onboardingPhase;
19
+ this.projectId = projectId;
20
+ this.tenantSolution = tenantSolution;
21
+ this.autocompleteSettings = { ... DEFAULT_AUTOCOMPLETE_ADD_VENDORS, ... autocompleteSettings };
22
+ }
21
23
  }
22
24
 
23
25
  module.exports = UpdateProjectSettingsModel;
24
26
 
25
- const defaultMarketplace = {
27
+ const DEFAULT_MARKETPLACE = {
26
28
  marketplaceEnabled: false,
27
29
  marketplacePreApproved: false,
28
30
  marketplaceOnboardedVendors: false,
29
31
  marketplaceCompliantVendorQuotationEnabled: false
30
32
  };
31
- const defaultAutoGaps = {
32
- Guests: false,
33
- Tenants: false,
34
- Vendors: false
33
+ const DEFAULT_AUTOGAPS = {
34
+ isAutoGapsEnabledForGuests: false,
35
+ isAutoGapsEnabledForTenants: false,
36
+ isAutoGapsEnabledForVendors: false
35
37
  };
36
- const defaultAutocompleteAddVendors = {
38
+ const DEFAULT_AUTOCOMPLETE_ADD_VENDORS = {
37
39
  autocompleteAddVendorsForPm: false,
38
40
  autocompleteAddVendorsForTenants: false
39
41
  };
@@ -68,8 +68,56 @@ const getProjectConfig = (projectName, { city, state, accountName, projectNumber
68
68
  };
69
69
  };
70
70
 
71
- const deleteProjectByName = (accounId, projectName, context) => {
72
- return services.deleteProjectByName(accounId, projectName, context);
71
+ const deleteProjectByName = (accountId, projectName, context) => {
72
+ return services.deleteProjectByName(accountId, projectName, context);
73
+ };
74
+
75
+ const isUIConfig = config => {
76
+ const allKeysSettings = { ... attributesConvertor, ... marketplaceAttributesConvertor, ... autoGapsConvertor, ... autocompleteAttributesConvertor };
77
+ const convectorKeys = Object.keys(allKeysSettings);
78
+ const configKeys = Object.keys(config);
79
+
80
+ return convectorKeys.some(key => configKeys.includes(key));
81
+ };
82
+
83
+ const assignNewSettingFormat = (target, sourceKey, sourceValue, dictionaryObject) => {
84
+ const attributeKey = dictionaryObject[sourceKey];
85
+ const attributeValue = JSON.parse(sourceValue);
86
+ Object.assign(target, { [attributeKey]: attributeValue });
87
+ };
88
+
89
+ const marketplaceParser = (settings, sourceKey, sourceValue, dictionary) => {
90
+ settings.marketplaceSettings = settings.marketplaceSettings || {};
91
+
92
+ assignNewSettingFormat(settings.marketplaceSettings, sourceKey, sourceValue, dictionary);
93
+ };
94
+
95
+ const autoGapsParser = (settings, sourceKey, sourceValue, dictionary) => {
96
+ settings.autoGaps = settings.autoGaps || {};
97
+
98
+ assignNewSettingFormat(settings.autoGaps, sourceKey, sourceValue, dictionary);
99
+ };
100
+
101
+ const autocompleteParser = (settings, sourceKey, sourceValue, dictionary) => {
102
+ settings.autocompleteSettings = settings.autocompleteSettings || {};
103
+
104
+ assignNewSettingFormat(settings.autocompleteSettings, sourceKey, sourceValue, dictionary);
105
+ };
106
+
107
+ const parseProjectSettingsConfig = (projectId, settingsConfig) => {
108
+ const settings = { projectId };
109
+
110
+ for (const setting in settingsConfig) {
111
+ marketplaceAttributesConvertor[setting] && marketplaceParser(settings, setting, settingsConfig[setting], marketplaceAttributesConvertor);
112
+
113
+ autocompleteAttributesConvertor[setting] && autocompleteParser(settings, setting, settingsConfig[setting], autocompleteAttributesConvertor);
114
+
115
+ attributesConvertor[setting] && assignNewSettingFormat(settings, setting, settingsConfig[setting], attributesConvertor);
116
+
117
+ autoGapsConvertor[setting] && autoGapsParser(settings, setting, settingsConfig[setting], autoGapsConvertor);
118
+ }
119
+
120
+ return settings;
73
121
  };
74
122
 
75
123
  module.exports = {
@@ -78,5 +126,31 @@ module.exports = {
78
126
  getDefaultProjectId,
79
127
  getCreateProjectModel,
80
128
  getUpdateProjectModel,
81
- deleteProjectByName
129
+ deleteProjectByName,
130
+ parseProjectSettingsConfig,
131
+ isUIConfig
132
+ };
133
+
134
+ const attributesConvertor = {
135
+ 'Automatic Renewal': 'autoRenewals',
136
+ 'Onboarding Phase Enabled': 'onboardingPhase',
137
+ 'Tenant App': 'tenantSolution'
138
+ };
139
+
140
+ const marketplaceAttributesConvertor = {
141
+ 'Vendor Network Onboarding': 'marketplaceEnabled',
142
+ 'Vendor Network - Show Onboarded Vendors': 'marketplaceOnboardedVendors',
143
+ 'Pre-Approved Tab': 'marketplacePreApproved',
144
+ 'Compliant Vendor Quotation': 'marketplaceCompliantVendorQuotationEnabled'
145
+ };
146
+
147
+ const autocompleteAttributesConvertor = {
148
+ 'For PM': 'autocompleteAddVendorsForPm',
149
+ 'For Tenants': 'autocompleteAddVendorsForTenants'
150
+ };
151
+
152
+ const autoGapsConvertor = {
153
+ 'Guests': 'isAutoGapsEnabledForGuests',
154
+ 'Tenants': 'isAutoGapsEnabledForTenants',
155
+ 'Vendors': 'isAutoGapsEnabledForVendors'
82
156
  };