@amanat-qa/utils-backend 1.0.10 → 1.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/data/dataUtils.js +13 -247
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amanat-qa/utils-backend",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,6 +1,5 @@
1
1
  const fs = require('fs');
2
2
  const moment = require('moment');
3
- const JSONMapper = require('./JSONMapper');
4
3
  const JSONLoader = require('./JSONLoader');
5
4
  const TimeUtils = require('../time/timeUtils');
6
5
  const Randomizer = require('../random/randomizer');
@@ -13,256 +12,12 @@ class DataUtils {
13
12
  fs.writeFileSync(`./test/artifacts/${name}.json`, JSON.stringify(data, replacer, 4));
14
13
  }
15
14
 
16
- static passBugsTWB(mappedData, getPolicyData) {
17
- const outputData = { ...mappedData };
18
-
19
- // Pass TWB bug with "doc_gived_by" value
20
- const docGivedByFullKeys = JSONMapper.getNestedProperty(outputData, 'doc_gived_by').keys;
21
- docGivedByFullKeys.forEach((fullKey) => {
22
- if (JSONMapper.flattenJSON(getPolicyData)[fullKey] === 'МВД РК'
23
- || JSONMapper.flattenJSON(getPolicyData)[fullKey] === '-') {
24
- outputData[fullKey] = JSONMapper.flattenJSON(getPolicyData)[fullKey];
25
- }
26
- });
27
-
28
- // Pass TWB bug with "driver_certificate_date" empty value
29
- const driverCertificateDateFullKeys = JSONMapper
30
- .getNestedProperty(outputData, 'driver_certificate_date').keys;
31
- driverCertificateDateFullKeys.forEach((fullKey) => {
32
- if (JSONMapper.flattenJSON(getPolicyData)[fullKey] === '') {
33
- outputData[fullKey] = JSONMapper.flattenJSON(getPolicyData)[fullKey];
34
- }
35
- });
36
-
37
- // Pass TWB bug with "verify_bool" value without verification
38
- if (getPolicyData.contracts[0].verify_bool === 1
39
- && outputData['contracts.0.verify_bool'] === 0) {
40
- outputData['contracts.0.verify_bool'] = getPolicyData.contracts[0].verify_bool;
41
- }
42
-
43
- return outputData;
44
- }
45
-
46
- /* eslint-disable no-param-reassign */
47
- static mapRequestToOnes(onesData, requestData, isOGPO, optionalSchema) {
48
- let onesDataFileName = 'onesDataCommon';
49
- let requestToOnesMappedDataFileName = 'requestToOnesMappedDataCommon';
50
- let mapSchema = JSONLoader.requestToOnesMapSchemaCommonKASKO;
51
-
52
- if (isOGPO) {
53
- mapSchema = JSONLoader.requestToOnesMapSchemaOGPO;
54
- onesDataFileName = 'onesDataOGPO';
55
- requestToOnesMappedDataFileName = 'requestToOnesMappedDataOGPO';
56
- }
57
-
58
- const mappedData = JSONMapper.mapValues(
59
- { onesData },
60
- { requestData },
61
- optionalSchema ?? mapSchema,
62
- );
63
-
64
- const rewrittenData = JSONMapper.rewriteValues(
65
- mappedData,
66
- JSONLoader.dictOnes,
67
- JSONLoader.dictRequest,
68
- );
69
-
70
- const requestToOnesMappedData = JSONMapper.unflattenJSON(rewrittenData);
71
- requestToOnesMappedData.ie_date = TimeUtils.reformatDateFromDMYToYMDHms(rewrittenData.ie_date);
72
- requestToOnesMappedData.claims.forEach((claim, index) => {
73
- const rewrittenDateKey = `claims.${index}.notice_date`; // Build the dynamic key
74
- claim.notice_date = TimeUtils.reformatDateFromDMYToYMDHms(rewrittenData[rewrittenDateKey]);
75
- });
76
- this.saveToJSON({ [onesDataFileName]: onesData });
77
- this.saveToJSON({ [requestToOnesMappedDataFileName]: requestToOnesMappedData });
78
- return requestToOnesMappedData;
79
- }
80
-
81
- static sortOGPORequestAndOnesData(requestData, onesData) {
82
- /* This method sorts victim objects in requestData and claims in onesData for OGPO case
83
- in preparation for mapping.
84
- Order: 1st - Victim_Vehicle, 2nd - Victim_Client, 3rd - Victim_Other.
85
- */
86
-
87
- const priority = JSONLoader.testData.victimObjectsSortPriority;
88
-
89
- requestData.victim_objects.sort((a, b) => {
90
- const typeA = a.type;
91
- const typeB = b.type;
92
- return (priority[typeA] || 999) - (priority[typeB] || 999);
93
- });
94
-
95
- onesData.claims.sort((a, b) => {
96
- const typeA = a.victim_objects[0].type;
97
- const typeB = b.victim_objects[0].type;
98
- return (priority[typeA] || 999) - (priority[typeB] || 999);
99
- });
100
-
101
- this.saveToJSON({ requestDataSorted: requestData });
102
- this.saveToJSON({ onesDataSorted: onesData });
103
- return { requestData, onesData };
104
- }
105
-
106
- static mapIEESBDToRequestOGPO(requestData, getIEESBDResponse) {
107
- /* OGPO IE and victim object mapping is separated into 4 parts:
108
- IE and each of 3 victim objects.
109
- Victim objects are created asynchronically, so we can't rely on
110
- their array order in request to map them with ESBD.
111
- So we need to separate them and determine which victim object from
112
- response is to be mapped with victim object in response.
113
- */
114
-
115
- // Save input data into files.
116
- this.saveToJSON({ requestDataOGPO: requestData });
117
- this.saveToJSON({ getIEESBDResponseOGPO: getIEESBDResponse });
118
-
119
- // Main part of mapping - ie from ESBD to request.
120
- const IEMappedPart = JSONMapper.mapValues(
121
- { requestDataOGPO: requestData },
122
- { getIEESBDResponse },
123
- JSONLoader.IEToRequestMapSchemaOGPO,
124
- );
125
-
126
- // Form array of victim objects from request and esbd response.
127
- const victimObjectsRequestArray = requestData.victim_objects;
128
- const victimObjectsESBDArray = getIEESBDResponse
129
- .GetInsuranceEventsResult.Insurance_Event.Victim_Objects.Victim_Object;
130
-
131
- // Find victim objects in request and ESBD response and using unique keys.
132
- const victimVehicleRequest = JSONMapper
133
- .getObjectWithSpecifiedKeyFromArray(victimObjectsRequestArray, 'TF_ID');
134
- const victimVehicleESBD = JSONMapper
135
- .getObjectWithSpecifiedKeyFromArray(victimObjectsESBDArray, 'Victim_Vehicle');
136
- let victimVehicleMappedPart = JSONMapper.mapValues(
137
- { victimVehicleRequest },
138
- { victimVehicleESBD },
139
- JSONLoader.victimVehicleToRequestMapSchema,
140
- );
141
- victimVehicleMappedPart = JSONMapper.appendPrefixToKeys(victimVehicleMappedPart, 'victim_objects.0.');
142
-
143
- const victimClientRequest = JSONMapper
144
- .getObjectWithSpecifiedKeyFromArray(victimObjectsRequestArray, 'DEATH_BOOL');
145
- const victimClientESBD = JSONMapper
146
- .getObjectWithSpecifiedKeyFromArray(victimObjectsESBDArray, 'Victim_Client');
147
- let victimClientMappedPart = JSONMapper.mapValues(
148
- { victimClientRequest },
149
- { victimClientESBD },
150
- JSONLoader.victimClientToRequestMapSchema,
151
- );
152
- victimClientMappedPart = JSONMapper.appendPrefixToKeys(victimClientMappedPart, 'victim_objects.1.');
153
-
154
- const victimOtherRequest = JSONMapper
155
- .getObjectWithSpecifiedKeyFromArray(victimObjectsRequestArray, 'VICTIM_OTHER_TYPE_ID');
156
- const victimOtherESBD = JSONMapper
157
- .getObjectWithSpecifiedKeyFromArray(victimObjectsESBDArray, 'Victim_Other');
158
- let victimOtherMappedPart = JSONMapper.mapValues(
159
- { victimOtherRequest },
160
- { victimOtherESBD },
161
- JSONLoader.victimOtherToRequestMapSchema,
162
- );
163
- victimOtherMappedPart = JSONMapper.appendPrefixToKeys(victimOtherMappedPart, 'victim_objects.2.');
164
-
165
- // After mapping merge them together into single mapped object.
166
- const mappingResult = JSONMapper.safeMergeObjects(
167
- { IEMappedPart },
168
- { victimVehicleMappedPart },
169
- { victimClientMappedPart },
170
- { victimOtherMappedPart },
171
- );
172
-
173
- // Save output data into files.
174
- this.saveToJSON({ IEMappedPart });
175
- this.saveToJSON({ victimVehicleMappedPart });
176
- this.saveToJSON({ victimClientMappedPart });
177
- this.saveToJSON({ victimOtherMappedPart });
178
-
179
- const IEToRequestMappedData = JSONMapper.unflattenJSON(mappingResult);
180
- this.saveToJSON({ OGPOMappingResult: mappingResult });
181
- this.saveToJSON({ OGPOIEToRequestMappedData: IEToRequestMappedData });
182
-
183
- return IEToRequestMappedData;
184
- }
185
-
186
- static mapClaimESBDToRequestOGPO(claimESBD) {
187
- const mappedBody = JSONLoader.claimToRequestMapTemplateOGPO;
188
-
189
- mappedBody.informer.id_esbd = claimESBD.CLAIMANT_ID;
190
- mappedBody.victim_objects[0].pre_appraisal_damage = claimESBD.PRELIMINARY_DAMAGE_APPRAISAL;
191
- mappedBody.claimant_type_id = claimESBD.CLAIMANT_TYPE_ID;
192
-
193
- const claimESBDFileName = `claim_ESBD_${claimESBD.IE_CLAIM_ID}`;
194
- const claimMappingResultFileName = `claim_mapped_ESBD_to_request_${claimESBD.IE_CLAIM_ID}`;
195
- this.saveToJSON({ [claimMappingResultFileName]: mappedBody });
196
- this.saveToJSON({ [claimESBDFileName]: claimESBD });
197
-
198
- return mappedBody;
199
- }
200
-
201
- static mapESBDToRequestCommon(requestData, getIEESBDResponse) {
202
- // Common IE, claim, victim objects are possible to get
203
- // using single ESBD method to get common IE.
204
-
205
- this.saveToJSON({ requestDataCommonKASKO: requestData });
206
- this.saveToJSON({ getIEESBDResponseCommonKASKO: getIEESBDResponse });
207
-
208
- const mappedData = JSONMapper.mapValues(
209
- { requestData },
210
- { getIEESBDResponse },
211
- JSONLoader.IEToRequestMapSchemaCommon,
212
- );
213
-
214
- const IEToRequestMappedData = JSONMapper.unflattenJSON(mappedData);
215
-
216
- // Calculating preliminary damage appraisal from ESBD average RBNS reserve value
217
- const insuranceTypeID = requestData.victim_objects[0].insurance_type_id;
218
- const averageRBNS = JSONLoader
219
- .averageRBNS.filter((avgRBNS) => (
220
- avgRBNS.insurance_type_id_esbd === insuranceTypeID
221
- ? avgRBNS.insurance_type_id_esbd
222
- : null))[0];
223
- let preliminaryDamageCalculated = getIEESBDResponse
224
- .data.GetIECommon_By_IdResult.COMMON_CLAIMS.COMMON_CLAIM.PRELIMINARY_DAMAGE_APPRAISAL;
225
- preliminaryDamageCalculated = Math
226
- .round(preliminaryDamageCalculated / (1 + (averageRBNS.percent * 0.01)));
227
- IEToRequestMappedData.victim_objects[0].pre_appraisal_damage = preliminaryDamageCalculated;
228
-
229
- // Delete redundant mapped "descriptions".
230
- delete IEToRequestMappedData.location.description;
231
- delete IEToRequestMappedData.victim_objects[0].participants.client.description;
232
-
233
- this.saveToJSON({ IEToRequestMappedDataCommon: IEToRequestMappedData });
234
-
235
- return IEToRequestMappedData;
236
- }
237
-
238
- /* eslint camelcase: ["error", {"properties": "never",
239
- ignoreDestructuring: true, allow: ["verify_bool", "verify_type_id"]}] */
240
- static generateSetPolicyRequest() {
241
- const params = {};
242
- const datesInterval = TimeUtils.getDatesInterval(...JSONLoader.testData.timeIncrement);
243
- params.date_beg = datesInterval.startDate;
244
- params.date_end = datesInterval.finishDate;
245
-
246
- const { testClients } = JSONLoader;
247
- const { testCars } = JSONLoader;
248
-
249
- const { holder, insured } = DataUtils.createRandomHolderAndInsuredStructures(testClients);
250
- const car = DataUtils.createRandomCarStructure(testCars);
251
-
252
- params.insured_people = [];
253
- params.insured_people[0] = insured;
254
- params.holder = holder;
255
- params.vehicles = [];
256
- params.vehicles[0] = car;
257
-
258
- return params;
259
- }
260
-
261
15
  static filterClients(clients, options = {}) {
262
16
  const { isResident } = options;
263
17
  const { hasPassport } = options;
264
18
  const { hasDriverLicence } = options;
265
19
  const { isUnderSixtyYearsOld } = options;
20
+ const { isJuridical } = options;
266
21
  let filteredClients = [...clients];
267
22
 
268
23
  filteredClients = filteredClients.filter((client) => {
@@ -283,7 +38,10 @@ class DataUtils {
283
38
 
284
39
  filteredClients = filteredClients.filter((client) => {
285
40
  if (hasPassport !== undefined) {
286
- return hasPassport ? client.document_type_id === 2 : client.document_type_id !== 2;
41
+ const hasLetter = /[a-zA-Z]/.test(client.document_number);
42
+ return hasPassport
43
+ ? client.document_type_id === 11 && hasLetter
44
+ : client.document_type_id !== 11;
287
45
  }
288
46
 
289
47
  return true;
@@ -299,6 +57,14 @@ class DataUtils {
299
57
  return true;
300
58
  });
301
59
 
60
+ filteredClients = filteredClients.filter((client) => {
61
+ if (isJuridical !== undefined) {
62
+ return isJuridical ? !client.natural_person_bool : client.natural_person_bool;
63
+ }
64
+
65
+ return true;
66
+ });
67
+
302
68
  return filteredClients;
303
69
  }
304
70