@swan-io/shared-business 18.3.0 → 18.5.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.
Files changed (68) hide show
  1. package/package.json +3 -3
  2. package/src/components/FraudReport/FraudReportLayout.d.ts +23 -0
  3. package/src/components/FraudReport/FraudReportLayout.js +35 -0
  4. package/src/components/FraudReport/IncidentStep.d.ts +7 -0
  5. package/src/components/FraudReport/IncidentStep.js +55 -0
  6. package/src/components/FraudReport/IntroStep.d.ts +5 -0
  7. package/src/components/FraudReport/IntroStep.js +28 -0
  8. package/src/components/FraudReport/TransactionsStep.d.ts +16 -0
  9. package/src/components/FraudReport/TransactionsStep.js +138 -0
  10. package/src/components/FraudReport/VictimStep.d.ts +9 -0
  11. package/src/components/FraudReport/VictimStep.js +55 -0
  12. package/src/components/InlineDatePicker.js +7 -6
  13. package/src/constants/__tests__/countries.test.js +32 -1
  14. package/src/constants/countries.d.ts +2 -1
  15. package/src/constants/countries.js +36 -2
  16. package/src/hooks/__tests__/useFraudReportFlow.test.d.ts +1 -0
  17. package/src/hooks/__tests__/useFraudReportFlow.test.js +979 -0
  18. package/src/hooks/useFraudReportFlow.d.ts +32 -0
  19. package/src/hooks/useFraudReportFlow.js +260 -0
  20. package/src/locales/de.json +76 -0
  21. package/src/locales/en.json +76 -0
  22. package/src/locales/es.json +76 -0
  23. package/src/locales/fi.json +76 -0
  24. package/src/locales/fr.json +76 -0
  25. package/src/locales/it.json +76 -0
  26. package/src/locales/nl.json +76 -0
  27. package/src/locales/pt.json +76 -0
  28. package/src/utils/__tests__/fraudReport.fakeApi.test.js +42 -13
  29. package/src/utils/__tests__/fraudReport.prefill.test.d.ts +1 -0
  30. package/src/utils/__tests__/fraudReport.prefill.test.js +149 -0
  31. package/src/utils/__tests__/fraudReport.rejections.test.d.ts +1 -0
  32. package/src/utils/__tests__/fraudReport.rejections.test.js +163 -0
  33. package/src/utils/__tests__/fraudReport.resume.test.d.ts +1 -0
  34. package/src/utils/__tests__/fraudReport.resume.test.js +67 -0
  35. package/src/utils/__tests__/fraudReport.stepper.test.d.ts +1 -0
  36. package/src/utils/__tests__/fraudReport.stepper.test.js +102 -0
  37. package/src/utils/__tests__/fraudReport.toInput.test.d.ts +1 -0
  38. package/src/utils/__tests__/fraudReport.toInput.test.js +549 -0
  39. package/src/utils/__tests__/fraudReport.transactions.test.d.ts +1 -0
  40. package/src/utils/__tests__/fraudReport.transactions.test.js +28 -0
  41. package/src/utils/__tests__/fraudReport.types.test.d.ts +1 -0
  42. package/src/utils/__tests__/fraudReport.types.test.js +22 -0
  43. package/src/utils/__tests__/fraudReport.victim.test.d.ts +1 -0
  44. package/src/utils/__tests__/fraudReport.victim.test.js +142 -0
  45. package/src/utils/__tests__/phone.test.js +60 -5
  46. package/src/utils/fraudReport/fakeApi.d.ts +7 -4
  47. package/src/utils/fraudReport/fakeApi.js +18 -5
  48. package/src/utils/fraudReport/prefill.d.ts +3 -0
  49. package/src/utils/fraudReport/prefill.js +14 -0
  50. package/src/utils/fraudReport/rail.d.ts +5 -0
  51. package/src/utils/fraudReport/rail.js +14 -0
  52. package/src/utils/fraudReport/rejections.d.ts +10 -0
  53. package/src/utils/fraudReport/rejections.js +53 -0
  54. package/src/utils/fraudReport/resume.d.ts +4 -0
  55. package/src/utils/fraudReport/resume.js +26 -0
  56. package/src/utils/fraudReport/stepper.d.ts +16 -0
  57. package/src/utils/fraudReport/stepper.js +21 -0
  58. package/src/utils/fraudReport/toInput.d.ts +30 -0
  59. package/src/utils/fraudReport/toInput.js +82 -0
  60. package/src/utils/fraudReport/transactions.d.ts +6 -0
  61. package/src/utils/fraudReport/transactions.js +7 -0
  62. package/src/utils/fraudReport/types.d.ts +8 -0
  63. package/src/utils/fraudReport/validation.d.ts +15 -0
  64. package/src/utils/fraudReport/validation.js +55 -0
  65. package/src/utils/fraudReport/victim.d.ts +30 -0
  66. package/src/utils/fraudReport/victim.js +28 -0
  67. package/src/utils/phone.d.ts +1 -0
  68. package/src/utils/phone.js +31 -4
@@ -0,0 +1,549 @@
1
+ import { Option } from "@bloodyowl/boxed";
2
+ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
3
+ import { createFakeFraudReportApi, createFakeTransaction } from "../fraudReport/fakeApi";
4
+ import { getCaseRail, getTransactionRail } from "../fraudReport/rail";
5
+ import { toDraftInput, toUpdateInput } from "../fraudReport/toInput";
6
+ import { validateDescription, validateDiscoveryDetails, validateExternalReference, validateNotInFuture, validateSelected, validateSharedInformation, validateTransactionIds, } from "../fraudReport/validation";
7
+ const card1 = createFakeTransaction("card-1", "CardOutDebit");
8
+ const card2 = createFakeTransaction("card-2", "CardOutDebit");
9
+ const transfer1 = createFakeTransaction("transfer-1", "SepaCreditTransferOut");
10
+ const transfer2 = createFakeTransaction("transfer-2", "SepaCreditTransferOut");
11
+ const DESCRIPTION_REGEX = /^(?=[\s\S]*\S)[\s\S]{1,2000}$/;
12
+ const DISCOVERY_DETAILS_REGEX = /^(?=[\s\S]*\S)[\s\S]{1,1000}$/;
13
+ const EXTERNAL_REFERENCE_REGEX = /^[\x20-\x7E]{1,255}$/;
14
+ describe("getTransactionRail", () => {
15
+ test("gives the card rail to outgoing card debits", () => {
16
+ expect(getTransactionRail("CardOutDebit")).toEqual(Option.Some("Card"));
17
+ });
18
+ test.each([
19
+ "SepaCreditTransferOut",
20
+ "SepaInstantCreditTransferOut",
21
+ "InternationalCreditTransferOut",
22
+ "InternalCreditTransferOut",
23
+ ])("gives the transfer rail to %s", type => {
24
+ expect(getTransactionRail(type)).toEqual(Option.Some("Transfer"));
25
+ });
26
+ test.each([
27
+ "CardOutAuthorization",
28
+ "CardOutDebitReversal",
29
+ "CardOutCredit",
30
+ "CardOutCreditReversal",
31
+ "CardInCredit",
32
+ "CardInChargeback",
33
+ "CardInChargebackReversal",
34
+ "SepaCreditTransferOutReturn",
35
+ "SepaCreditTransferOutRecall",
36
+ "SepaCreditTransferIn",
37
+ "SepaCreditTransferInReturn",
38
+ "SepaCreditTransferInRecall",
39
+ "SepaInstantCreditTransferOutRecall",
40
+ "SepaInstantCreditTransferIn",
41
+ "SepaInstantCreditTransferInRecall",
42
+ "InternationalCreditTransferOutReturn",
43
+ "InternationalCreditTransferIn",
44
+ "InternationalCreditTransferInReturn",
45
+ "InternalCreditTransferOutReturn",
46
+ "InternalCreditTransferOutRecall",
47
+ "InternalCreditTransferIn",
48
+ "InternalCreditTransferInReturn",
49
+ "InternalCreditTransferInRecall",
50
+ "SepaDirectDebitOut",
51
+ "SepaDirectDebitOutReturn",
52
+ "SepaDirectDebitOutReversal",
53
+ "SepaDirectDebitIn",
54
+ "SepaDirectDebitInReturn",
55
+ "SepaDirectDebitInReversal",
56
+ "InternalDirectDebitOut",
57
+ "InternalDirectDebitOutReturn",
58
+ "InternalDirectDebitIn",
59
+ "InternalDirectDebitInReturn",
60
+ "CheckIn",
61
+ "CheckInReturn",
62
+ "FeesOut",
63
+ "FeesIn",
64
+ "",
65
+ ])("gives no rail to %s, which can't be reported", type => {
66
+ expect(getTransactionRail(type)).toEqual(Option.None());
67
+ });
68
+ });
69
+ describe("getCaseRail", () => {
70
+ test("is card-only when every transaction is a card transaction", () => {
71
+ expect(getCaseRail([card1, card2])).toEqual(Option.Some("CardOnly"));
72
+ });
73
+ test("is transfer-only when every transaction is a transfer", () => {
74
+ expect(getCaseRail([transfer1, transfer2])).toEqual(Option.Some("TransferOnly"));
75
+ });
76
+ test("is mixed when the selection holds both rails", () => {
77
+ expect(getCaseRail([transfer1, card1])).toEqual(Option.Some("Mixed"));
78
+ });
79
+ test("has no rail without transactions", () => {
80
+ expect(getCaseRail([])).toEqual(Option.None());
81
+ });
82
+ });
83
+ describe("validateTransactionIds", () => {
84
+ test("requires at least one transaction", () => {
85
+ expect(validateTransactionIds([])).toBe("Required");
86
+ });
87
+ test("refuses duplicates", () => {
88
+ expect(validateTransactionIds(["card-1", "transfer-1", "card-1"])).toBe("Duplicates");
89
+ });
90
+ test("accepts unique transaction IDs", () => {
91
+ expect(validateTransactionIds(["card-1"])).toBeUndefined();
92
+ expect(validateTransactionIds(["card-1", "transfer-1"])).toBeUndefined();
93
+ });
94
+ });
95
+ describe("validateSelected", () => {
96
+ test("requires a value", () => {
97
+ expect(validateSelected(undefined)).toBe("Required");
98
+ });
99
+ test("accepts a selected value", () => {
100
+ expect(validateSelected("Manipulated")).toBeUndefined();
101
+ });
102
+ });
103
+ describe("validateNotInFuture", () => {
104
+ beforeEach(() => {
105
+ vi.useFakeTimers();
106
+ vi.setSystemTime(new Date("2026-11-20T10:00:00.000Z"));
107
+ });
108
+ afterEach(() => {
109
+ vi.useRealTimers();
110
+ vi.unstubAllEnvs();
111
+ });
112
+ test("accepts today and past dates", () => {
113
+ expect(validateNotInFuture("2026-11-20")).toBeUndefined();
114
+ expect(validateNotInFuture("2026-11-19")).toBeUndefined();
115
+ expect(validateNotInFuture("2025-01-01")).toBeUndefined();
116
+ });
117
+ test("refuses dates after today", () => {
118
+ expect(validateNotInFuture("2026-11-21")).toBe("DateInFuture");
119
+ expect(validateNotInFuture("2027-01-01")).toBe("DateInFuture");
120
+ });
121
+ test("takes today from UTC, whatever the time of day", () => {
122
+ vi.setSystemTime(new Date("2026-11-20T23:59:59.000Z"));
123
+ expect(validateNotInFuture("2026-11-20")).toBeUndefined();
124
+ expect(validateNotInFuture("2026-11-21")).toBe("DateInFuture");
125
+ vi.setSystemTime(new Date("2026-11-21T00:00:00.000Z"));
126
+ expect(validateNotInFuture("2026-11-21")).toBeUndefined();
127
+ });
128
+ test("refuses tomorrow in UTC, even where it is already tomorrow", () => {
129
+ vi.stubEnv("TZ", "Pacific/Auckland");
130
+ vi.setSystemTime(new Date("2026-11-20T12:30:00.000Z"));
131
+ expect(validateNotInFuture("2026-11-20")).toBeUndefined();
132
+ expect(validateNotInFuture("2026-11-21")).toBe("DateInFuture");
133
+ });
134
+ test("accepts today in UTC, even where it is still yesterday", () => {
135
+ vi.stubEnv("TZ", "America/Los_Angeles");
136
+ vi.setSystemTime(new Date("2026-11-21T02:00:00.000Z"));
137
+ expect(validateNotInFuture("2026-11-21")).toBeUndefined();
138
+ expect(validateNotInFuture("2026-11-22")).toBe("DateInFuture");
139
+ });
140
+ test("refuses anything that isn't a YYYY-MM-DD date", () => {
141
+ expect(validateNotInFuture("20/11/2026")).toBe("InvalidDate");
142
+ expect(validateNotInFuture("2026-13-45")).toBe("InvalidDate");
143
+ expect(validateNotInFuture("2026-11-20T10:00:00.000Z")).toBe("InvalidDate");
144
+ expect(validateNotInFuture("yesterday")).toBe("InvalidDate");
145
+ });
146
+ test("accepts an empty value, as both dates are optional", () => {
147
+ expect(validateNotInFuture(undefined)).toBeUndefined();
148
+ expect(validateNotInFuture("")).toBeUndefined();
149
+ });
150
+ });
151
+ describe("validateSharedInformation", () => {
152
+ test("refuses None with other values", () => {
153
+ expect(validateSharedInformation(["None", "CardDetails"])).toBe("NoneWithOtherValues");
154
+ expect(validateSharedInformation(["SwanPasscode", "Other", "None"])).toBe("NoneWithOtherValues");
155
+ });
156
+ test("accepts None alone", () => {
157
+ expect(validateSharedInformation(["None"])).toBeUndefined();
158
+ });
159
+ test("accepts any other values, or no answer", () => {
160
+ expect(validateSharedInformation(["CardDetails", "BankDetails"])).toBeUndefined();
161
+ expect(validateSharedInformation([])).toBeUndefined();
162
+ expect(validateSharedInformation(undefined)).toBeUndefined();
163
+ });
164
+ });
165
+ describe("validateDescription", () => {
166
+ test("requires text that isn't only whitespace", () => {
167
+ expect(validateDescription(undefined)).toBe("Required");
168
+ expect(validateDescription("")).toBe("Required");
169
+ expect(validateDescription(" \n\t ")).toBe("Required");
170
+ });
171
+ test("refuses more than 2000 characters", () => {
172
+ expect(validateDescription("a".repeat(2001))).toBe("TooLong");
173
+ });
174
+ test("accepts up to 2000 characters, line breaks included", () => {
175
+ expect(validateDescription("a")).toBeUndefined();
176
+ expect(validateDescription("My card was used\nin a shop I never went to.")).toBeUndefined();
177
+ expect(validateDescription("a".repeat(2000))).toBeUndefined();
178
+ });
179
+ test.each(["", " ", "\n", "a", " a ", "é\n\nè", "a".repeat(2000), "a".repeat(2001)])("agrees with the format documented by the API (sample %#)", sample => {
180
+ expect(validateDescription(sample) == null).toBe(DESCRIPTION_REGEX.test(sample));
181
+ });
182
+ });
183
+ describe("validateDiscoveryDetails", () => {
184
+ test("refuses more than 1000 characters", () => {
185
+ expect(validateDiscoveryDetails("a".repeat(1001))).toBe("TooLong");
186
+ });
187
+ test("accepts up to 1000 characters", () => {
188
+ expect(validateDiscoveryDetails("I saw it on my statement.")).toBeUndefined();
189
+ expect(validateDiscoveryDetails("a".repeat(1000))).toBeUndefined();
190
+ });
191
+ test("accepts an empty value, as the field is optional", () => {
192
+ expect(validateDiscoveryDetails(undefined)).toBeUndefined();
193
+ expect(validateDiscoveryDetails("")).toBeUndefined();
194
+ expect(validateDiscoveryDetails(" ")).toBeUndefined();
195
+ });
196
+ test.each(["a", " a ", "é\n\nè", "a".repeat(1000), "a".repeat(1001)])("agrees with the format documented by the API for values that are sent (sample %#)", sample => {
197
+ expect(validateDiscoveryDetails(sample) == null).toBe(DISCOVERY_DETAILS_REGEX.test(sample));
198
+ });
199
+ });
200
+ describe("validateExternalReference", () => {
201
+ test("refuses characters outside printable ASCII", () => {
202
+ expect(validateExternalReference("réf-123")).toBe("InvalidCharacters");
203
+ expect(validateExternalReference("ref\n123")).toBe("InvalidCharacters");
204
+ expect(validateExternalReference("ref\t123")).toBe("InvalidCharacters");
205
+ expect(validateExternalReference("ref\x1F")).toBe("InvalidCharacters");
206
+ expect(validateExternalReference("ref\x7F")).toBe("InvalidCharacters");
207
+ expect(validateExternalReference("ref 🙂")).toBe("InvalidCharacters");
208
+ });
209
+ test("refuses more than 255 characters", () => {
210
+ expect(validateExternalReference("a".repeat(256))).toBe("TooLong");
211
+ });
212
+ test("accepts up to 255 printable ASCII characters", () => {
213
+ expect(validateExternalReference("REF-2026/11 #42 ~ok")).toBeUndefined();
214
+ expect(validateExternalReference("a".repeat(255))).toBeUndefined();
215
+ });
216
+ test("accepts an empty value, as the field is optional", () => {
217
+ expect(validateExternalReference(undefined)).toBeUndefined();
218
+ expect(validateExternalReference("")).toBeUndefined();
219
+ });
220
+ test.each(["a", " ", "REF 1", "réf", "a\nb", "a".repeat(255), "a".repeat(256)])("agrees with the format documented by the API for values that are sent (sample %#)", sample => {
221
+ expect(validateExternalReference(sample) == null).toBe(EXTERNAL_REFERENCE_REGEX.test(sample));
222
+ });
223
+ });
224
+ const incident = {
225
+ reportedReason: "Manipulated",
226
+ reportedTypology: "FakeAdvisor",
227
+ description: "Someone called me pretending to be my bank.",
228
+ };
229
+ const filled = {
230
+ ...incident,
231
+ victimAccountMembershipId: "member-1",
232
+ discoveredAt: "2026-11-18",
233
+ discoveryDetails: "I saw it on my statement.",
234
+ fraudsterChannels: ["Phone", "Sms"],
235
+ sharedInformationWithFraudster: ["VerificationCode"],
236
+ isLostOrStolen: true,
237
+ lostOrStolenNoticedAt: "2026-11-17",
238
+ externalReference: "REF-42",
239
+ };
240
+ const fraudDetails = {
241
+ reportedReason: "Manipulated",
242
+ reportedTypology: "FakeAdvisor",
243
+ description: "Someone called me pretending to be my bank.",
244
+ discoveredAt: "2026-11-18",
245
+ discoveryDetails: "I saw it on my statement.",
246
+ fraudsterChannels: ["Phone", "Sms"],
247
+ sharedInformationWithFraudster: ["VerificationCode"],
248
+ hasFiledPoliceComplaint: null,
249
+ };
250
+ const fraudCardDetails = {
251
+ isLostOrStolen: true,
252
+ lostOrStolenNoticedAt: "2026-11-17",
253
+ hasContactedMerchant: null,
254
+ };
255
+ describe("toDraftInput", () => {
256
+ test("sends only the transaction IDs when nothing else is filled", () => {
257
+ expect(toDraftInput({ transactions: [card1, transfer1] })).toStrictEqual({
258
+ transactionIds: ["card-1", "transfer-1"],
259
+ });
260
+ });
261
+ test("sends the card details and no victim on a card-only case", () => {
262
+ expect(toDraftInput({ ...filled, transactions: [card1, card2] })).toStrictEqual({
263
+ transactionIds: ["card-1", "card-2"],
264
+ fraudDetails,
265
+ fraudCardDetails,
266
+ externalReference: "REF-42",
267
+ });
268
+ });
269
+ test("sends the victim and no card details on a transfer-only case", () => {
270
+ expect(toDraftInput({ ...filled, transactions: [transfer1, transfer2] })).toStrictEqual({
271
+ transactionIds: ["transfer-1", "transfer-2"],
272
+ fraudDetails,
273
+ victimAccountMembershipId: "member-1",
274
+ externalReference: "REF-42",
275
+ });
276
+ });
277
+ test("sends the card details and no victim on a mixed case", () => {
278
+ expect(toDraftInput({ ...filled, transactions: [transfer1, card1] })).toStrictEqual({
279
+ transactionIds: ["transfer-1", "card-1"],
280
+ fraudDetails,
281
+ fraudCardDetails,
282
+ externalReference: "REF-42",
283
+ });
284
+ });
285
+ test("never sends transfer details", () => {
286
+ expect(toDraftInput({ ...filled, transactions: [transfer1] })).not.toHaveProperty("fraudTransferDetails");
287
+ expect(toDraftInput({ ...filled, transactions: [transfer1, card1] })).not.toHaveProperty("fraudTransferDetails");
288
+ });
289
+ test("leaves the victim out of a transfer-only case until one is picked", () => {
290
+ expect(toDraftInput({ ...incident, transactions: [transfer1] })).not.toHaveProperty("victimAccountMembershipId");
291
+ });
292
+ test.each([
293
+ ["reason", { reportedReason: undefined }],
294
+ ["fraud type", { reportedTypology: undefined }],
295
+ ["description", { description: undefined }],
296
+ ["description", { description: " \n " }],
297
+ ])("leaves the fraud details out while the %s is missing", (_, missing) => {
298
+ expect(toDraftInput({ ...filled, ...missing, transactions: [transfer1] })).not.toHaveProperty("fraudDetails");
299
+ });
300
+ test("sends null for the optional fraud details left empty", () => {
301
+ expect(toDraftInput({
302
+ ...incident,
303
+ discoveredAt: "",
304
+ discoveryDetails: " ",
305
+ fraudsterChannels: [],
306
+ sharedInformationWithFraudster: [],
307
+ transactions: [card1],
308
+ })).toStrictEqual({
309
+ transactionIds: ["card-1"],
310
+ fraudDetails: {
311
+ ...incident,
312
+ discoveredAt: null,
313
+ discoveryDetails: null,
314
+ fraudsterChannels: null,
315
+ sharedInformationWithFraudster: null,
316
+ hasFiledPoliceComplaint: null,
317
+ },
318
+ });
319
+ });
320
+ test("keeps the description as the user typed it", () => {
321
+ var _a;
322
+ const description = " First line\n\nSecond line ";
323
+ expect((_a = toDraftInput({ ...incident, description, transactions: [card1] }).fraudDetails) === null || _a === void 0 ? void 0 : _a.description).toBe(description);
324
+ });
325
+ test("leaves the card details out until one of them is answered", () => {
326
+ expect(toDraftInput({ ...incident, transactions: [card1] })).not.toHaveProperty("fraudCardDetails");
327
+ expect(toDraftInput({ ...incident, lostOrStolenNoticedAt: "", transactions: [card1] })).not.toHaveProperty("fraudCardDetails");
328
+ });
329
+ test("sends null for the card detail left empty", () => {
330
+ expect(toDraftInput({ isLostOrStolen: false, transactions: [card1] }).fraudCardDetails).toStrictEqual({
331
+ isLostOrStolen: false,
332
+ lostOrStolenNoticedAt: null,
333
+ hasContactedMerchant: null,
334
+ });
335
+ expect(toDraftInput({ lostOrStolenNoticedAt: "2026-11-17", transactions: [card1] }).fraudCardDetails).toStrictEqual({
336
+ isLostOrStolen: null,
337
+ lostOrStolenNoticedAt: "2026-11-17",
338
+ hasContactedMerchant: null,
339
+ });
340
+ });
341
+ test("leaves an empty external reference out", () => {
342
+ expect(toDraftInput({ externalReference: "", transactions: [card1] })).toStrictEqual({
343
+ transactionIds: ["card-1"],
344
+ });
345
+ });
346
+ });
347
+ describe("toUpdateInput", () => {
348
+ const savedCase = { id: "case-1", fraudDetails: null, fraudCardDetails: null };
349
+ const disputeCaseId = savedCase.id;
350
+ test("sends the card details and no victim on a card-only case", () => {
351
+ expect(toUpdateInput({
352
+ savedCase,
353
+ values: { ...filled, transactions: [card1, card2] },
354
+ savedTransactionIds: ["card-1"],
355
+ })).toStrictEqual({
356
+ disputeCaseId,
357
+ transactionIds: ["card-1", "card-2"],
358
+ fraudDetails,
359
+ fraudCardDetails,
360
+ externalReference: "REF-42",
361
+ });
362
+ });
363
+ test("sends the victim and no card details on a transfer-only case", () => {
364
+ expect(toUpdateInput({
365
+ savedCase,
366
+ values: { ...filled, transactions: [transfer1] },
367
+ savedTransactionIds: ["transfer-1", "card-1"],
368
+ })).toStrictEqual({
369
+ disputeCaseId,
370
+ transactionIds: ["transfer-1"],
371
+ fraudDetails,
372
+ victimAccountMembershipId: "member-1",
373
+ externalReference: "REF-42",
374
+ });
375
+ });
376
+ test("sends the card details and no victim on a mixed case", () => {
377
+ expect(toUpdateInput({
378
+ savedCase,
379
+ values: { ...filled, transactions: [transfer1, card1] },
380
+ savedTransactionIds: ["transfer-1"],
381
+ })).toStrictEqual({
382
+ disputeCaseId,
383
+ transactionIds: ["transfer-1", "card-1"],
384
+ fraudDetails,
385
+ fraudCardDetails,
386
+ externalReference: "REF-42",
387
+ });
388
+ });
389
+ test("never sends transfer details", () => {
390
+ expect(toUpdateInput({
391
+ savedCase,
392
+ values: { ...filled, transactions: [transfer1] },
393
+ savedTransactionIds: [],
394
+ })).not.toHaveProperty("fraudTransferDetails");
395
+ });
396
+ test("clears the fraudster answers once no fraudster convinced the user", () => {
397
+ expect(toUpdateInput({
398
+ savedCase,
399
+ values: { ...filled, reportedReason: "Unauthorized", transactions: [card1] },
400
+ savedTransactionIds: ["card-1"],
401
+ }).fraudDetails).toStrictEqual({
402
+ ...fraudDetails,
403
+ reportedReason: "Unauthorized",
404
+ fraudsterChannels: null,
405
+ sharedInformationWithFraudster: null,
406
+ });
407
+ });
408
+ test("leaves the transaction IDs out when the selection didn't change", () => {
409
+ expect(toUpdateInput({
410
+ savedCase,
411
+ values: { ...incident, transactions: [card1, transfer1] },
412
+ savedTransactionIds: ["transfer-1", "card-1"],
413
+ })).toStrictEqual({ disputeCaseId, fraudDetails: expect.any(Object) });
414
+ });
415
+ test.each([
416
+ ["a transaction was added", [card1, card2], ["card-1"]],
417
+ ["a transaction was removed", [card1], ["card-1", "card-2"]],
418
+ ["a transaction was swapped", [card1, transfer1], ["card-1", "card-2"]],
419
+ ["a transaction is there twice", [card1, card1], ["card-1", "card-2"]],
420
+ ])("sends the whole selection when %s", (_, transactions, savedTransactionIds) => {
421
+ expect(toUpdateInput({ savedCase, values: { transactions }, savedTransactionIds })).toStrictEqual({ disputeCaseId, transactionIds: transactions.map(({ id }) => id) });
422
+ });
423
+ test("leaves every group out when nothing is filled", () => {
424
+ expect(toUpdateInput({
425
+ savedCase,
426
+ values: { transactions: [card1] },
427
+ savedTransactionIds: ["card-1"],
428
+ })).toStrictEqual({ disputeCaseId });
429
+ });
430
+ test("clears the external reference when it was emptied", () => {
431
+ expect(toUpdateInput({
432
+ savedCase,
433
+ values: { externalReference: "", transactions: [card1] },
434
+ savedTransactionIds: ["card-1"],
435
+ })).toStrictEqual({ disputeCaseId, externalReference: null });
436
+ });
437
+ test("keeps the stored external reference when the form has none", () => {
438
+ expect(toUpdateInput({
439
+ savedCase,
440
+ values: { ...incident, transactions: [card1] },
441
+ savedTransactionIds: ["card-1"],
442
+ })).not.toHaveProperty("externalReference");
443
+ });
444
+ test("holds the card details and the victim back while no transaction is selected", () => {
445
+ expect(toUpdateInput({
446
+ savedCase,
447
+ values: { ...filled, transactions: [] },
448
+ savedTransactionIds: [],
449
+ })).toStrictEqual({ disputeCaseId, fraudDetails, externalReference: "REF-42" });
450
+ });
451
+ test("sends back the actions taken saved on the case, which the form doesn't hold", () => {
452
+ var _a, _b;
453
+ const input = toUpdateInput({
454
+ savedCase: {
455
+ id: "case-1",
456
+ fraudDetails: { ...fraudDetails, hasFiledPoliceComplaint: true },
457
+ fraudCardDetails: { ...fraudCardDetails, hasContactedMerchant: false },
458
+ },
459
+ values: { ...filled, transactions: [card1] },
460
+ savedTransactionIds: ["card-1"],
461
+ });
462
+ expect((_a = input.fraudDetails) === null || _a === void 0 ? void 0 : _a.hasFiledPoliceComplaint).toBe(true);
463
+ expect((_b = input.fraudCardDetails) === null || _b === void 0 ? void 0 : _b.hasContactedMerchant).toBe(false);
464
+ });
465
+ });
466
+ describe("inputs sent to the API", () => {
467
+ const createApi = () => createFakeFraudReportApi({
468
+ transactions: [
469
+ {
470
+ id: "card-1",
471
+ accountId: "account-1",
472
+ type: "CardOutDebit",
473
+ cardholderAccountMembershipId: "member-2",
474
+ },
475
+ { id: "transfer-1", accountId: "account-1", type: "SepaCreditTransferOut" },
476
+ ],
477
+ accountMemberships: [
478
+ { id: "member-1", accountId: "account-1" },
479
+ { id: "member-2", accountId: "account-1" },
480
+ ],
481
+ });
482
+ const getCase = (result) => result.match({
483
+ Ok: value => value,
484
+ Error: error => {
485
+ throw new Error(`The API refused the input: ${JSON.stringify(error)}`);
486
+ },
487
+ });
488
+ test("a card-only draft is accepted, with its card details and the cardholder as victim", async () => {
489
+ const created = getCase(await createApi().draft(toDraftInput({ ...filled, transactions: [card1] })));
490
+ expect(created.fraudCardDetails).toMatchObject({ isLostOrStolen: true });
491
+ expect(created.victimAccountMembershipId).toBe("member-2");
492
+ });
493
+ test("a transfer-only draft is accepted, with the victim picked in the form", async () => {
494
+ const created = getCase(await createApi().draft(toDraftInput({ ...filled, transactions: [transfer1] })));
495
+ expect(created.fraudCardDetails).toBeNull();
496
+ expect(created.victimAccountMembershipId).toBe("member-1");
497
+ });
498
+ test("a mixed draft is accepted, with its card details and the cardholder as victim", async () => {
499
+ const created = getCase(await createApi().draft(toDraftInput({ ...filled, transactions: [transfer1, card1] })));
500
+ expect(created.fraudCardDetails).toMatchObject({ isLostOrStolen: true });
501
+ expect(created.victimAccountMembershipId).toBe("member-2");
502
+ });
503
+ test("an update is accepted when the selection moves from card-only to transfer-only", async () => {
504
+ const api = createApi();
505
+ const savedCase = getCase(await api.draft(toDraftInput({ ...filled, transactions: [card1] })));
506
+ const updated = getCase(await api.update(toUpdateInput({
507
+ savedCase,
508
+ values: { ...filled, transactions: [transfer1] },
509
+ savedTransactionIds: ["card-1"],
510
+ })));
511
+ expect(updated.transactions).toStrictEqual([transfer1]);
512
+ expect(updated.fraudCardDetails).toBeNull();
513
+ expect(updated.victimAccountMembershipId).toBe("member-1");
514
+ });
515
+ test("an update is accepted when the selection moves from transfer-only to card-only", async () => {
516
+ const api = createApi();
517
+ const savedCase = getCase(await api.draft(toDraftInput({ ...filled, transactions: [transfer1] })));
518
+ const updated = getCase(await api.update(toUpdateInput({
519
+ savedCase,
520
+ values: { ...filled, transactions: [card1] },
521
+ savedTransactionIds: ["transfer-1"],
522
+ })));
523
+ expect(updated.transactions).toStrictEqual([card1]);
524
+ expect(updated.fraudCardDetails).toMatchObject({ isLostOrStolen: true });
525
+ expect(updated.victimAccountMembershipId).toBe("member-2");
526
+ });
527
+ test("an update keeps the actions taken that another client stored on the draft", async () => {
528
+ var _a;
529
+ const api = createApi();
530
+ const savedCase = getCase(await api.draft({
531
+ transactionIds: ["card-1", "transfer-1"],
532
+ fraudDetails: { ...incident, hasFiledPoliceComplaint: true },
533
+ fraudCardDetails: { hasContactedMerchant: true },
534
+ fraudTransferDetails: { hasContactedBankOrBeneficiary: true },
535
+ }));
536
+ const updated = getCase(await api.update(toUpdateInput({
537
+ savedCase,
538
+ values: { ...filled, transactions: [card1, transfer1] },
539
+ savedTransactionIds: ["card-1", "transfer-1"],
540
+ })));
541
+ expect((_a = updated.fraudDetails) === null || _a === void 0 ? void 0 : _a.hasFiledPoliceComplaint).toBe(true);
542
+ expect(updated.fraudCardDetails).toStrictEqual({
543
+ isLostOrStolen: true,
544
+ lostOrStolenNoticedAt: "2026-11-17",
545
+ hasContactedMerchant: true,
546
+ });
547
+ expect(updated.fraudTransferDetails).toStrictEqual({ hasContactedBankOrBeneficiary: true });
548
+ });
549
+ });
@@ -0,0 +1,28 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { createFakeTransaction } from "../fraudReport/fakeApi";
3
+ import { getTransactionsTotal, removeDuplicateTransactions } from "../fraudReport/transactions";
4
+ const withAmount = (value, currency = "EUR") => createFakeTransaction(`card-${value}`, "CardOutDebit", { amount: { value, currency } });
5
+ describe("getTransactionsTotal", () => {
6
+ test("adds the amounts without rounding drift", () => {
7
+ expect(getTransactionsTotal([withAmount("1.15"), withAmount("2.30")])).toEqual({
8
+ value: 3.45,
9
+ currency: "EUR",
10
+ });
11
+ });
12
+ test("uses the first transaction's currency, while mixed currencies are pending Product", () => {
13
+ expect(getTransactionsTotal([withAmount("5.00", "GBP"), withAmount("1.00")])).toEqual({
14
+ value: 6,
15
+ currency: "GBP",
16
+ });
17
+ });
18
+ test("is zero euros when nothing is selected", () => {
19
+ expect(getTransactionsTotal([])).toEqual({ value: 0, currency: "EUR" });
20
+ });
21
+ });
22
+ describe("removeDuplicateTransactions", () => {
23
+ test("keeps the first of rows with the same ID, in order", () => {
24
+ const card = createFakeTransaction("card-1", "CardOutDebit");
25
+ const transfer = createFakeTransaction("transfer-1", "SepaCreditTransferOut");
26
+ expect(removeDuplicateTransactions([card, transfer, { ...card, counterparty: "Lidl" }])).toEqual([card, transfer]);
27
+ });
28
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { isTranslationKey } from "../i18n";
3
+ // A Record, so a rejection added to the contract fails typecheck until it is listed here
4
+ const rejectionTypenames = {
5
+ AccountMembershipNotFoundRejection: true,
6
+ DisputeCaseDetailsNotApplicableRejection: true,
7
+ DisputeCaseIncompleteRejection: true,
8
+ DisputeCaseMultipleAccountsRejection: true,
9
+ DisputeCaseMultipleCardHoldersRejection: true,
10
+ DisputeCaseNotFoundRejection: true,
11
+ DisputeCaseTransactionsAlreadyReportedRejection: true,
12
+ DisputeCaseTransactionsLimitExceededRejection: true,
13
+ DisputeCaseTransactionsNotFoundRejection: true,
14
+ DisputeCaseTransactionsNotReportableRejection: true,
15
+ DisputeCaseTransactionsOutsideReportingWindowRejection: true,
16
+ DisputeCaseWrongStatusRejection: true,
17
+ };
18
+ describe("fraud report rejections", () => {
19
+ test.each(Object.keys(rejectionTypenames))("%s has a translation key", typename => {
20
+ expect(isTranslationKey(`rejection.${typename}`)).toBe(true);
21
+ });
22
+ });
@@ -0,0 +1 @@
1
+ export {};