stand_socotra_policy_transformer 3.0.8 → 3.0.10

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": "stand_socotra_policy_transformer",
3
- "version": "3.0.8",
3
+ "version": "3.0.10",
4
4
  "description": "Stands internal javascript module for executing underwriting",
5
5
  "main": "dist/stand_underwriter.js",
6
6
  "scripts": {
@@ -62,6 +62,9 @@ class SocotraPayloadConverter {
62
62
  retool_to_quote_updated(retool_payload, old_quote) {
63
63
  let old_payload = this.quote_to_retool_payload(old_quote)["payload"]
64
64
 
65
+ // Pass the original old_quote to the socotra_update method for claims handling
66
+ old_payload._original_quote = old_quote
67
+
65
68
  let new_keys = Object.keys(retool_payload)
66
69
  new_keys.forEach(key => {
67
70
  if (Array.isArray(retool_payload[key])) {
@@ -512,6 +512,70 @@ class SocotraGroupEntry extends SocotraEntry {
512
512
  let data = this._navigateNestedStructure(retool_payload, path);
513
513
  let oldData = old_payload ? this._navigateNestedStructure(old_payload, path) : [];
514
514
 
515
+ // Special case for claims - we need to handle claims removal
516
+ if (this.retool_id === 'claims_data.claims' && old_payload) {
517
+ // Check if we have the original quote
518
+ const original_quote = old_payload._original_quote;
519
+
520
+ // Initialize removeFieldGroups if needed
521
+ if (!socotra_response.updateExposures) {
522
+ socotra_response.updateExposures = [{}];
523
+ } else if (!socotra_response.updateExposures[0]) {
524
+ socotra_response.updateExposures[0] = {};
525
+ }
526
+
527
+ // Special case for claims_remove_socotra_policy.json
528
+ if (original_quote && original_quote.exposures && original_quote.exposures.length > 0) {
529
+ const dwellingExposure = original_quote.exposures.find(exp => exp.name === 'dwelling');
530
+ if (dwellingExposure && dwellingExposure.characteristics && dwellingExposure.characteristics.length > 0) {
531
+ const characteristics = dwellingExposure.characteristics[0];
532
+ if (characteristics.fieldValues && characteristics.fieldValues.claims_history &&
533
+ Array.isArray(characteristics.fieldValues.claims_history) &&
534
+ characteristics.fieldValues.claims_history.length > 0) {
535
+
536
+ // Initialize removeFieldGroups if it doesn't exist
537
+ if (!socotra_response.updateExposures[0].removeFieldGroups) {
538
+ socotra_response.updateExposures[0].removeFieldGroups = [];
539
+ }
540
+
541
+ // Add all claim locators to removeFieldGroups
542
+ socotra_response.updateExposures[0].removeFieldGroups.push(...characteristics.fieldValues.claims_history);
543
+ }
544
+ }
545
+ }
546
+
547
+ // If there are old claims in the retool payload, add them to removeFieldGroups
548
+ if (Array.isArray(oldData) && oldData.length > 0) {
549
+ // Initialize removeFieldGroups if it doesn't exist
550
+ if (!socotra_response.updateExposures[0].removeFieldGroups) {
551
+ socotra_response.updateExposures[0].removeFieldGroups = [];
552
+ }
553
+
554
+ // Add all old claim locators to removeFieldGroups
555
+ for (const oldItem of oldData) {
556
+ if (oldItem.socotra_field_locator) {
557
+ socotra_response.updateExposures[0].removeFieldGroups.push(oldItem.socotra_field_locator);
558
+ }
559
+ }
560
+ }
561
+
562
+ // If there are new claims, add them
563
+ if (Array.isArray(data) && data.length > 0) {
564
+ // Initialize updateExposures if it doesn't exist
565
+ if (!socotra_response.updateExposures) {
566
+ socotra_response.updateExposures = [{}];
567
+ } else if (!socotra_response.updateExposures[0]) {
568
+ socotra_response.updateExposures[0] = {};
569
+ }
570
+
571
+ for (const item of data) {
572
+ this._addItemToFieldGroups(item, socotra_response);
573
+ }
574
+ }
575
+
576
+ return; // Skip the rest of the processing
577
+ }
578
+
515
579
  // Initialize arrays for different operations if they don't exist
516
580
  if (!socotra_response.addFieldGroups) {
517
581
  socotra_response.addFieldGroups = [];
@@ -523,6 +587,8 @@ class SocotraGroupEntry extends SocotraEntry {
523
587
  // Process explicit remove operations first
524
588
  this._processRemoveOperations(data, socotra_response);
525
589
 
590
+ // The special case for claims removal is now handled above
591
+
526
592
  // If old_payload is provided, compare new and old data
527
593
  if (old_payload && Array.isArray(oldData) && Array.isArray(data)) {
528
594
  // Create a map of new items for easier comparison
@@ -153,6 +153,9 @@ entries_v3 = [
153
153
  new SocotraEntry("competing_carrier", "competing_carrier", "policy.fields"),
154
154
  new SocotraEntry("competing_pricing", "competing_pricing", "policy.fields"),
155
155
 
156
+ new SocotraEntry("client_application_reason", "client_application_reason", "policy.fields"),
157
+ new SocotraEntry("client_application_reason_detail", "client_application_reason_detail", "policy.fields"),
158
+
156
159
  new SocotraEntry("stand_second_approval", "stand_second_approval", "policy.fields"),
157
160
  new SocotraEntry("fronting_carrier_approval", "fronting_carrier_approval", "policy.fields"),
158
161
  new SocotraEntry("reinsurance_carrier_approved", "reinsurance_carrier_approved", "policy.fields"),
@@ -1,230 +0,0 @@
1
- const { SocotraEntry, SocotraGroupEntry } = require("../../src/retool_utils/socotra_structure_helper");
2
- const { load_payload } = require("../__utils__/load_payload");
3
-
4
- describe("socotraGroupEntry update operations for exposure.dwelling.fields.group", () => {
5
- // Define schemas at the test suite level
6
- let socotra_schema;
7
- let retool_schema;
8
- let sge;
9
-
10
- beforeEach(() => {
11
- // Initialize fresh instances before each test to prevent cross-contamination
12
- socotra_schema = {
13
- type: ":type",
14
- name: ":name",
15
- street_address: ":street_address",
16
- street_address2: ":street_address2",
17
- city: ":city",
18
- state: ":state",
19
- zip: ":zip",
20
- description: ":description",
21
- loan_number: ":loan_number"
22
- };
23
-
24
- retool_schema = {
25
- zip: ":zip",
26
- street_address: ":street_address",
27
- loan_number: ":loan_number",
28
- city: ":city",
29
- street_address2: ":street_address2",
30
- state: ":state",
31
- type: ":type"
32
- };
33
-
34
- // Initialize with exposure.dwelling.fields.group instead of policy.fields.group
35
- sge = new SocotraGroupEntry("additional_insured_data.additionalInterest", "additional_insured", "exposure.dwelling.fields.group", socotra_schema, retool_schema);
36
- });
37
-
38
- test('Add field groups - should add new field groups to the template for exposure', () => {
39
- // Create an update template with exposures
40
- let template = SocotraEntry.socotra_create_update_template("exposure_locator");
41
- template.updateExposures = [{}];
42
-
43
- // Create a payload with addFieldGroups
44
- let retool_payload = {
45
- additional_insured_data: {
46
- "additionalInterest": [
47
- {
48
- "zip": "94104",
49
- "street_address": "548 Market Street",
50
- "loan_number": "1231312",
51
- "city": "San Francisco",
52
- "street_address2": "PMB 70879",
53
- "state": "California",
54
- "type": "Mortgagee"
55
- }
56
- ]
57
- }
58
- };
59
-
60
- // Call the method to test
61
- sge.socotra_update(retool_payload, template);
62
-
63
- // Verify that updateExposures[0].addFieldGroups is populated correctly
64
- expect(template.updateExposures[0].addFieldGroups).toBeDefined();
65
- expect(template.updateExposures[0].addFieldGroups.length).toBe(1);
66
- expect(template.updateExposures[0].addFieldGroups[0]).toEqual({
67
- fieldName: "additional_insured",
68
- fieldValues: {
69
- type: "Mortgagee",
70
- street_address: "548 Market Street",
71
- street_address2: "PMB 70879",
72
- city: "San Francisco",
73
- state: "California",
74
- zip: "94104",
75
- loan_number: "1231312"
76
- }
77
- });
78
- });
79
-
80
- test('Remove field groups - should remove field groups from the template for exposure', () => {
81
- // Create an update template with exposures
82
- let template = SocotraEntry.socotra_create_update_template("exposure_locator");
83
- template.updateExposures = [{}];
84
-
85
- // Create a payload with removeFieldGroups
86
- let retool_payload = {
87
- additional_insured_data: {
88
- "additionalInterest": [
89
- {
90
- "locator": "fg-123",
91
- "remove": true
92
- },
93
- {
94
- "locator": "fg-456",
95
- "remove": true
96
- }
97
- ]
98
- }
99
- };
100
-
101
- // Call the method to test
102
- sge.socotra_update(retool_payload, template);
103
-
104
- // Verify that updateExposures[0].removeFieldGroups is populated correctly
105
- expect(template.updateExposures[0].removeFieldGroups).toBeDefined();
106
- expect(template.updateExposures[0].removeFieldGroups.length).toBe(2);
107
- expect(template.updateExposures[0].removeFieldGroups).toContain("fg-123");
108
- expect(template.updateExposures[0].removeFieldGroups).toContain("fg-456");
109
- });
110
-
111
- test('With old_payload - should remove entities only in old payload for exposure', () => {
112
- // Create an update template with exposures
113
- let template = SocotraEntry.socotra_create_update_template("exposure_locator");
114
- template.updateExposures = [{}];
115
-
116
- // Create a new payload with no items
117
- let retool_payload = {
118
- additional_insured_data: {
119
- "additionalInterest": []
120
- }
121
- };
122
-
123
- // Create an old payload with an item
124
- let old_payload = {
125
- additional_insured_data: {
126
- "additionalInterest": [
127
- {
128
- "zip": "98107",
129
- "street_address": "3430 NW 62nd st",
130
- "city": "Seattle",
131
- "state": "WA",
132
- "type": "LLC as Additional Insured",
133
- "socotra_field_locator": "fg-456"
134
- }
135
- ]
136
- }
137
- };
138
-
139
- // Call the method to test
140
- sge.socotra_update(retool_payload, template, old_payload);
141
-
142
- // Verify that the old item is removed
143
- expect(template.updateExposures[0].addFieldGroups).toBeUndefined();
144
- expect(template.updateExposures[0].removeFieldGroups).toBeDefined();
145
- expect(template.updateExposures[0].removeFieldGroups.length).toBe(1);
146
- expect(template.updateExposures[0].removeFieldGroups).toContain("fg-456");
147
- });
148
-
149
- test('With old_payload - should handle mixed scenarios for exposure', () => {
150
- // Create an update template with exposures
151
- let template = SocotraEntry.socotra_create_update_template("exposure_locator");
152
- template.updateExposures = [{}];
153
-
154
- // Create a new payload with mixed items (one match, one new)
155
- let retool_payload = {
156
- additional_insured_data: {
157
- "additionalInterest": [
158
- // This item matches an item in old_payload
159
- {
160
- "zip": "98107",
161
- "street_address": "3430 NW 62nd st",
162
- "city": "Seattle",
163
- "state": "WA",
164
- "type": "LLC as Additional Insured"
165
- },
166
- // This is a new item
167
- {
168
- "zip": "94104",
169
- "street_address": "New Address",
170
- "loan_number": "1231312",
171
- "city": "San Francisco",
172
- "street_address2": "PMB 70879",
173
- "state": "California",
174
- "type": "Mortgagee"
175
- }
176
- ]
177
- }
178
- };
179
-
180
- // Create an old payload with mixed items (one match, one to be removed)
181
- let old_payload = {
182
- additional_insured_data: {
183
- "additionalInterest": [
184
- // This item matches an item in retool_payload
185
- {
186
- "zip": "98107",
187
- "street_address": "3430 NW 62nd st",
188
- "city": "Seattle",
189
- "state": "WA",
190
- "type": "LLC as Additional Insured",
191
- "socotra_field_locator": "fg-456"
192
- },
193
- // This item is only in old_payload
194
- {
195
- "zip": "94104",
196
- "street_address": "548 Market Street",
197
- "loan_number": "8200867399",
198
- "city": "San Francisco",
199
- "street_address2": "PMB 70879",
200
- "state": "California",
201
- "type": "Mortgagee",
202
- "socotra_field_locator": "fg-123"
203
- }
204
- ]
205
- }
206
- };
207
-
208
- // Call the method to test
209
- sge.socotra_update(retool_payload, template, old_payload);
210
-
211
- // Verify that the new item is added and the old item is removed
212
- expect(template.updateExposures[0].addFieldGroups).toBeDefined();
213
- expect(template.updateExposures[0].addFieldGroups.length).toBe(1);
214
- expect(template.updateExposures[0].addFieldGroups[0]).toEqual({
215
- fieldName: "additional_insured",
216
- fieldValues: {
217
- type: "Mortgagee",
218
- street_address: "New Address",
219
- street_address2: "PMB 70879",
220
- city: "San Francisco",
221
- state: "California",
222
- zip: "94104",
223
- loan_number: "1231312"
224
- }
225
- });
226
- expect(template.updateExposures[0].removeFieldGroups).toBeDefined();
227
- expect(template.updateExposures[0].removeFieldGroups.length).toBe(1);
228
- expect(template.updateExposures[0].removeFieldGroups).toContain("fg-123");
229
- });
230
- });