@simplybusiness/services 2.0.2 → 2.2.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.
@@ -5,5 +5,5 @@ export type GetAirbrakeOptions = {
5
5
  forceSend?: boolean;
6
6
  };
7
7
  export declare function getAirbrake(options?: GetAirbrakeOptions): {
8
- notify: jest.Mock<any, any, any> | ((...data: any[]) => void);
8
+ notify: (...data: any[]) => void;
9
9
  };
@@ -25,6 +25,7 @@ declare const _default: ({
25
25
  question: string;
26
26
  answer: string;
27
27
  vertical: string;
28
+ journey_id: string;
28
29
  };
29
30
  };
30
31
  contexts: string[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simplybusiness/services",
3
3
  "license": "UNLICENSED",
4
- "version": "2.0.2",
4
+ "version": "2.2.0",
5
5
  "description": "Internal library for services",
6
6
  "repository": {
7
7
  "type": "git",
@@ -12,7 +12,7 @@ const notifierInstances = new Map<number, Notifier>();
12
12
  const fakeAirbrake = {
13
13
  notify:
14
14
  globalThis.process?.env?.NODE_ENV === "test"
15
- ? jest.fn()
15
+ ? () => {}
16
16
  : console.error.bind(console),
17
17
  };
18
18
 
@@ -24,7 +24,7 @@ export default [
24
24
 
25
25
  return {
26
26
  schema:
27
- "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-3",
27
+ "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-4",
28
28
  data: {
29
29
  site: context.site,
30
30
  page_index: 1,
@@ -34,6 +34,7 @@ export default [
34
34
  question,
35
35
  answer,
36
36
  vertical: context.vertical,
37
+ journey_id: context.journeyId,
37
38
  },
38
39
  };
39
40
  },
@@ -130,4 +130,42 @@ describe("coverageSelectionEventDefinitions", () => {
130
130
  expect("data" in result && result.data.vertical).toBe("");
131
131
  });
132
132
  });
133
+
134
+ describe("learnMoreModalOpened", () => {
135
+ it("should create correct structured event payload", () => {
136
+ const params = {
137
+ product: "general_liability",
138
+ };
139
+
140
+ const result = findEventByName(
141
+ coverageSelectionEventDefinitions,
142
+ "learnMoreModalOpened",
143
+ ).makePayload(params);
144
+
145
+ expect(result).toEqual({
146
+ category: "coverage_selection",
147
+ action: "learn_more_modal_opened",
148
+ label: "general_liability",
149
+ property: window.location.href,
150
+ });
151
+ });
152
+
153
+ it("should handle different product IDs", () => {
154
+ const params = {
155
+ product: "business_owners_policy",
156
+ };
157
+
158
+ const result = findEventByName(
159
+ coverageSelectionEventDefinitions,
160
+ "learnMoreModalOpened",
161
+ ).makePayload(params);
162
+
163
+ expect(result).toEqual({
164
+ category: "coverage_selection",
165
+ action: "learn_more_modal_opened",
166
+ label: "business_owners_policy",
167
+ property: window.location.href,
168
+ });
169
+ });
170
+ });
133
171
  });
@@ -33,4 +33,18 @@ export const coverageSelectionEventDefinitions: EventDefinition[] = [
33
33
  };
34
34
  },
35
35
  },
36
+ {
37
+ name: "learnMoreModalOpened",
38
+ type: "structured",
39
+ makePayload: params => {
40
+ const { product } = params as ParamsType & { product: string };
41
+
42
+ return {
43
+ category: "coverage_selection",
44
+ action: "learn_more_modal_opened",
45
+ label: product,
46
+ property: window.location.href,
47
+ };
48
+ },
49
+ },
36
50
  ];
@@ -0,0 +1,304 @@
1
+ import { personalisedCoverEventDefinitions } from "./personalised_cover";
2
+ import { findEventByName } from "./test-utils";
3
+
4
+ describe("personalisedCoverEventDefinitions", () => {
5
+ describe("coverQuestionAnswered", () => {
6
+ it("should create correct payload", () => {
7
+ const params = {
8
+ context: {
9
+ site: "uk",
10
+ vertical: "shop",
11
+ journeyId: "journey-123",
12
+ },
13
+ question: "test-question",
14
+ answer: "test-answer",
15
+ };
16
+
17
+ const result = findEventByName(
18
+ personalisedCoverEventDefinitions,
19
+ "coverQuestionAnswered",
20
+ ).makePayload(params);
21
+
22
+ expect(result).toEqual({
23
+ schema:
24
+ "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-4",
25
+ data: {
26
+ site: "uk",
27
+ page_name: "personalised_cover",
28
+ section_name: "Personalised Cover Questions",
29
+ question: "test-question",
30
+ answer: "test-answer",
31
+ vertical: "shop",
32
+ journey_id: "journey-123",
33
+ },
34
+ });
35
+ });
36
+
37
+ it("should flatten array answers", () => {
38
+ const params = {
39
+ context: {
40
+ site: "uk",
41
+ vertical: "shop",
42
+ journeyId: "journey-456",
43
+ },
44
+ question: "test-question",
45
+ answer: ["one", "two", "three"],
46
+ };
47
+
48
+ const result = findEventByName(
49
+ personalisedCoverEventDefinitions,
50
+ "coverQuestionAnswered",
51
+ ).makePayload(params);
52
+
53
+ expect(result).toEqual({
54
+ schema:
55
+ "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-4",
56
+ data: {
57
+ site: "uk",
58
+ page_name: "personalised_cover",
59
+ section_name: "Personalised Cover Questions",
60
+ question: "test-question",
61
+ answer: "one|two|three",
62
+ vertical: "shop",
63
+ journey_id: "journey-456",
64
+ },
65
+ });
66
+ });
67
+
68
+ it("should redact answers", () => {
69
+ const params = {
70
+ context: {
71
+ site: "uk",
72
+ vertical: "shop",
73
+ journeyId: "journey-789",
74
+ },
75
+ question: "customer_first_name",
76
+ answer: "Secret-John",
77
+ };
78
+
79
+ const result = findEventByName(
80
+ personalisedCoverEventDefinitions,
81
+ "coverQuestionAnswered",
82
+ ).makePayload(params);
83
+
84
+ expect(result).toEqual({
85
+ schema:
86
+ "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-4",
87
+ data: {
88
+ site: "uk",
89
+ page_name: "personalised_cover",
90
+ section_name: "Personalised Cover Questions",
91
+ question: "customer_first_name",
92
+ answer: "REDACTED",
93
+ vertical: "shop",
94
+ journey_id: "journey-789",
95
+ },
96
+ });
97
+ });
98
+
99
+ it("should handle undefined journeyId", () => {
100
+ const params = {
101
+ context: {
102
+ site: "uk",
103
+ vertical: "shop",
104
+ },
105
+ question: "test-question",
106
+ answer: "test-answer",
107
+ };
108
+
109
+ const result = findEventByName(
110
+ personalisedCoverEventDefinitions,
111
+ "coverQuestionAnswered",
112
+ ).makePayload(params);
113
+
114
+ expect(result).toEqual({
115
+ schema:
116
+ "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-4",
117
+ data: {
118
+ site: "uk",
119
+ page_name: "personalised_cover",
120
+ section_name: "Personalised Cover Questions",
121
+ question: "test-question",
122
+ answer: "test-answer",
123
+ vertical: "shop",
124
+ journey_id: undefined,
125
+ },
126
+ });
127
+ });
128
+ });
129
+
130
+ describe("seeMoreClicked", () => {
131
+ it("should create correct payload", () => {
132
+ const result = findEventByName(
133
+ personalisedCoverEventDefinitions,
134
+ "seeMoreClicked",
135
+ ).makePayload({});
136
+
137
+ expect(result).toEqual({
138
+ category: "personalised_cover",
139
+ action: "see_more_clicked",
140
+ label: "page",
141
+ property: "personalised_cover",
142
+ });
143
+ });
144
+ });
145
+
146
+ describe("selectPackageClicked", () => {
147
+ it("should create correct payload", () => {
148
+ const result = findEventByName(
149
+ personalisedCoverEventDefinitions,
150
+ "selectPackageClicked",
151
+ ).makePayload({});
152
+
153
+ expect(result).toEqual({
154
+ category: "personalised_cover",
155
+ action: "select_package_clicked",
156
+ label: "page",
157
+ property: "personalised_cover",
158
+ });
159
+ });
160
+ });
161
+
162
+ describe("validationShown", () => {
163
+ it("should create correct payload", () => {
164
+ const params = {
165
+ cover: "Public Liability",
166
+ question: "What is your turnover?",
167
+ };
168
+
169
+ const result = findEventByName(
170
+ personalisedCoverEventDefinitions,
171
+ "validationShown",
172
+ ).makePayload(params);
173
+
174
+ expect(result).toEqual({
175
+ category: "personalised_cover",
176
+ action: "validation_shown",
177
+ label: "cover_question",
178
+ property: "public_liability_what_is_your_turnover?",
179
+ });
180
+ });
181
+ });
182
+
183
+ describe("limitLinkClicked", () => {
184
+ it("should create correct payload", () => {
185
+ const params = {
186
+ label: "test-label",
187
+ };
188
+
189
+ const result = findEventByName(
190
+ personalisedCoverEventDefinitions,
191
+ "limitLinkClicked",
192
+ ).makePayload(params);
193
+
194
+ expect(result).toEqual({
195
+ category: "personalised_cover",
196
+ action: "limit_link_clicked",
197
+ label: "test-label",
198
+ property: "link_clicked",
199
+ });
200
+ });
201
+ });
202
+
203
+ describe("limitChanged", () => {
204
+ it("should create correct payload", () => {
205
+ const params = {
206
+ label: "Public Liability",
207
+ limit: "1000000",
208
+ };
209
+
210
+ const result = findEventByName(
211
+ personalisedCoverEventDefinitions,
212
+ "limitChanged",
213
+ ).makePayload(params);
214
+
215
+ expect(result).toEqual({
216
+ category: "personalised_cover",
217
+ action: "limit_changed",
218
+ label: "Public Liability",
219
+ property: "1000000",
220
+ });
221
+ });
222
+ });
223
+
224
+ describe("coverPresented", () => {
225
+ it("should create correct payload", () => {
226
+ const params = {
227
+ property: "Public Liability",
228
+ };
229
+
230
+ const result = findEventByName(
231
+ personalisedCoverEventDefinitions,
232
+ "coverPresented",
233
+ ).makePayload(params);
234
+
235
+ expect(result).toEqual({
236
+ category: "personalised_cover",
237
+ action: "cover_presented",
238
+ label: "cover_name",
239
+ property: "Public Liability",
240
+ });
241
+ });
242
+ });
243
+
244
+ describe("coverDetailsClicked", () => {
245
+ it("should create correct payload", () => {
246
+ const params = {
247
+ property: "Public Liability",
248
+ };
249
+
250
+ const result = findEventByName(
251
+ personalisedCoverEventDefinitions,
252
+ "coverDetailsClicked",
253
+ ).makePayload(params);
254
+
255
+ expect(result).toEqual({
256
+ category: "personalised_cover",
257
+ action: "cover_details_clicked",
258
+ label: "cover_name",
259
+ property: "Public Liability",
260
+ });
261
+ });
262
+ });
263
+
264
+ describe("additionalQuestionsClicked", () => {
265
+ it("should create correct payload", () => {
266
+ const params = {
267
+ property: "Public Liability",
268
+ };
269
+
270
+ const result = findEventByName(
271
+ personalisedCoverEventDefinitions,
272
+ "additionalQuestionsClicked",
273
+ ).makePayload(params);
274
+
275
+ expect(result).toEqual({
276
+ category: "personalised_cover",
277
+ action: "cover_details_clicked",
278
+ label: "cover_name",
279
+ property: "Public Liability",
280
+ });
281
+ });
282
+ });
283
+
284
+ describe("chatbotPromptClicked", () => {
285
+ it("should create correct payload", () => {
286
+ const params = {
287
+ label: "test-label",
288
+ property: "test-property",
289
+ };
290
+
291
+ const result = findEventByName(
292
+ personalisedCoverEventDefinitions,
293
+ "chatbotPromptClicked",
294
+ ).makePayload(params);
295
+
296
+ expect(result).toEqual({
297
+ category: "personalised_cover",
298
+ action: "chatbot_prompt_clicked",
299
+ label: "test-property",
300
+ property: "test-label",
301
+ });
302
+ });
303
+ });
304
+ });
@@ -72,13 +72,15 @@ export const personalisedCoverEventDefinitions: EventDefinition[] = [
72
72
 
73
73
  return {
74
74
  schema:
75
- "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-1",
75
+ "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-4",
76
76
  data: {
77
77
  site: context.site,
78
78
  page_name: "personalised_cover",
79
79
  section_name: "Personalised Cover Questions",
80
80
  question,
81
81
  answer: flatAnswer,
82
+ vertical: context.vertical,
83
+ journey_id: context.journeyId,
82
84
  },
83
85
  };
84
86
  },
@@ -9,6 +9,7 @@ describe("questionnaireEventDefinitions", () => {
9
9
  context: {
10
10
  site: "uk",
11
11
  vertical: "shop",
12
+ journeyId: "journey-123",
12
13
  },
13
14
  question: "test-question",
14
15
  answer: "test-answer",
@@ -31,6 +32,7 @@ describe("questionnaireEventDefinitions", () => {
31
32
  question: "test-question",
32
33
  answer: "test-answer",
33
34
  vertical: "shop",
35
+ journey_id: "journey-123",
34
36
  },
35
37
  });
36
38
  });
@@ -41,6 +43,7 @@ describe("questionnaireEventDefinitions", () => {
41
43
  context: {
42
44
  site: "uk",
43
45
  vertical: "shop",
46
+ journeyId: "journey-123",
44
47
  },
45
48
  question: "test-question",
46
49
  answer: ["one", "two", "four"],
@@ -63,6 +66,7 @@ describe("questionnaireEventDefinitions", () => {
63
66
  question: "test-question",
64
67
  answer: "one|two|four",
65
68
  vertical: "shop",
69
+ journey_id: "journey-123",
66
70
  },
67
71
  });
68
72
  });
@@ -73,6 +77,7 @@ describe("questionnaireEventDefinitions", () => {
73
77
  context: {
74
78
  site: "uk",
75
79
  vertical: "shop",
80
+ journeyId: "journey-123",
76
81
  },
77
82
  question: "customer_first_name",
78
83
  answer: "Secret-Joanne",
@@ -95,6 +100,7 @@ describe("questionnaireEventDefinitions", () => {
95
100
  question: "customer_first_name",
96
101
  answer: "REDACTED",
97
102
  vertical: "shop",
103
+ journey_id: "journey-123",
98
104
  },
99
105
  });
100
106
  });
@@ -106,6 +112,7 @@ describe("questionnaireEventDefinitions", () => {
106
112
  context: {
107
113
  site: "us",
108
114
  vertical: "shop",
115
+ journeyId: "journey-123",
109
116
  },
110
117
  answer: "test-answer",
111
118
  vertical: "shop",
@@ -27,6 +27,7 @@ export const questionnaireEventDefinitions: EventDefinition[] = [
27
27
  question,
28
28
  answer: flatAnswer,
29
29
  vertical: context.vertical,
30
+ journey_id: context.journeyId,
30
31
  },
31
32
  };
32
33
  },
@@ -179,7 +179,7 @@ describe("Snowplow Analytics Class", () => {
179
179
 
180
180
  const expectedPayload = {
181
181
  schema:
182
- "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-3",
182
+ "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-4",
183
183
  data: {
184
184
  site: "simplybusiness_us",
185
185
  vertical: "usa",
@@ -189,6 +189,7 @@ describe("Snowplow Analytics Class", () => {
189
189
  submitted_from: "quick_to_quote_experiment",
190
190
  question: "test-question",
191
191
  answer: "test-answer",
192
+ journey_id: "666ff79d90abbc3582e496da",
192
193
  },
193
194
  };
194
195
 
@@ -225,7 +226,7 @@ describe("Snowplow Analytics Class", () => {
225
226
 
226
227
  const expectedPayload = {
227
228
  schema:
228
- "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-3",
229
+ "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-4",
229
230
  data: {
230
231
  site: "simplybusiness_us",
231
232
  vertical: "usa",
@@ -235,6 +236,7 @@ describe("Snowplow Analytics Class", () => {
235
236
  submitted_from: "quick_to_quote_experiment",
236
237
  question: "sof_bankrupt",
237
238
  answer: "REDACTED",
239
+ journey_id: "666ff79d90abbc3582e496da",
238
240
  },
239
241
  };
240
242
 
@@ -271,7 +273,7 @@ describe("Snowplow Analytics Class", () => {
271
273
 
272
274
  const expectedPayload = {
273
275
  schema:
274
- "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-3",
276
+ "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-4",
275
277
  data: {
276
278
  site: "simplybusiness_us",
277
279
  vertical: "usa",
@@ -281,6 +283,7 @@ describe("Snowplow Analytics Class", () => {
281
283
  submitted_from: "quick_to_quote_experiment",
282
284
  question: "have_secondary_trade",
283
285
  answer: "Yes",
286
+ journey_id: "666ff79d90abbc3582e496da",
284
287
  },
285
288
  };
286
289
 
@@ -317,7 +320,7 @@ describe("Snowplow Analytics Class", () => {
317
320
 
318
321
  const expectedPayload = {
319
322
  schema:
320
- "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-3",
323
+ "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-4",
321
324
  data: {
322
325
  site: "simplybusiness_us",
323
326
  vertical: "usa",
@@ -327,6 +330,7 @@ describe("Snowplow Analytics Class", () => {
327
330
  submitted_from: "quick_to_quote_experiment",
328
331
  question: "address_lookup",
329
332
  answer: "123 Test Street",
333
+ journey_id: "666ff79d90abbc3582e496da",
330
334
  },
331
335
  };
332
336
 
@@ -455,7 +459,7 @@ describe("Snowplow Analytics Class", () => {
455
459
 
456
460
  const expectedPayload = {
457
461
  schema:
458
- "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-3",
462
+ "iglu:com.simplybusiness/form_question_answered/jsonschema/1-0-4",
459
463
  data: {
460
464
  site: "simplybusiness_us",
461
465
  vertical: "usa",
@@ -465,6 +469,7 @@ describe("Snowplow Analytics Class", () => {
465
469
  submitted_from: "quick_to_quote_experiment",
466
470
  question: "test-question",
467
471
  answer: "test-answer",
472
+ journey_id: "666ff79d90abbc3582e496da",
468
473
  },
469
474
  };
470
475