stand_socotra_policy_transformer 3.0.7 → 3.0.9

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.
@@ -2,6 +2,6 @@ const { package_version } = require("../src/index");
2
2
 
3
3
  describe("Version", () => {
4
4
  test('Prints current version', () => {
5
- expect(package_version).toBe("3.0.7")
5
+ expect(package_version).toBe("3.0.9")
6
6
  });
7
7
  });
@@ -0,0 +1,230 @@
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
+ });
@@ -214,6 +214,34 @@ describe("Update Socotra Quote", () => {
214
214
  expect(res.status).toBe("success")
215
215
  });
216
216
 
217
+ test('works when removing claims', () => {
218
+ let retool_payload = load_payload('__tests__/__utils__/payloads/claims_remove_new_payload.json')
219
+ let old_quote = load_payload('__tests__/__utils__/payloads/claims_remove_socotra_policy.json')
220
+
221
+ let res = converter.retool_to_quote_updated(retool_payload, old_quote)
222
+
223
+
224
+ expect(res.payload.updateExposures[0]).toHaveProperty("addFieldGroups")
225
+ expect(res.payload.updateExposures[0]).toHaveProperty("removeFieldGroups")
226
+ expect(res.payload.updateExposures[0].fieldValues.has_any_claim_history).toBe('Yes')
227
+ expect(res.error_message).toBe("")
228
+ expect(res.status).toBe("success")
229
+ });
230
+
231
+ test('works when removing claims', () => {
232
+ let retool_payload = load_payload('__tests__/__utils__/payloads/claims_new_policy.json')
233
+ let old_quote = load_payload('__tests__/__utils__/payloads/claims_socotra_payload.json')
234
+
235
+ let res = converter.retool_to_quote_updated(retool_payload, old_quote)
236
+
237
+
238
+ expect(res.payload.updateExposures[0]).toHaveProperty("addFieldGroups")
239
+ expect(res.payload.updateExposures[0]).not.toHaveProperty("removeFieldGroups")
240
+ expect(res.payload.updateExposures[0].fieldValues.has_any_claim_history).toBe('Yes')
241
+ expect(res.error_message).toBe("")
242
+ expect(res.status).toBe("success")
243
+ });
244
+
217
245
  test('works with claims', () => {
218
246
  let retool_payload = load_payload('__tests__/__utils__/payloads/claims_new_policy.json')
219
247