@swan-io/shared-business 18.4.0 → 18.6.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 (101) hide show
  1. package/package.json +3 -3
  2. package/src/components/BirthdatePicker.d.ts +3 -1
  3. package/src/components/BirthdatePicker.js +2 -2
  4. package/src/components/FraudReport/CardDetailsStep.d.ts +7 -0
  5. package/src/components/FraudReport/CardDetailsStep.js +46 -0
  6. package/src/components/FraudReport/FraudReportLayout.d.ts +23 -0
  7. package/src/components/FraudReport/FraudReportLayout.js +35 -0
  8. package/src/components/FraudReport/FraudsterDetailsStep.d.ts +7 -0
  9. package/src/components/FraudReport/FraudsterDetailsStep.js +56 -0
  10. package/src/components/FraudReport/IncidentStep.d.ts +7 -0
  11. package/src/components/FraudReport/IncidentStep.js +55 -0
  12. package/src/components/FraudReport/IntroStep.d.ts +5 -0
  13. package/src/components/FraudReport/IntroStep.js +32 -0
  14. package/src/components/FraudReport/TransactionPicker.d.ts +13 -0
  15. package/src/components/FraudReport/TransactionPicker.js +213 -0
  16. package/src/components/FraudReport/TransactionPickerFilters.d.ts +8 -0
  17. package/src/components/FraudReport/TransactionPickerFilters.js +213 -0
  18. package/src/components/FraudReport/TransactionRows.d.ts +8 -0
  19. package/src/components/FraudReport/TransactionRows.js +32 -0
  20. package/src/components/FraudReport/TransactionsStep.d.ts +16 -0
  21. package/src/components/FraudReport/TransactionsStep.js +120 -0
  22. package/src/components/FraudReport/VictimStep.d.ts +11 -0
  23. package/src/components/FraudReport/VictimStep.js +88 -0
  24. package/src/components/InlineDatePicker.js +7 -6
  25. package/src/components/LakeModal.js +1 -1
  26. package/src/constants/__tests__/countries.test.js +32 -1
  27. package/src/constants/countries.d.ts +2 -1
  28. package/src/constants/countries.js +36 -2
  29. package/src/hooks/__tests__/useFraudReportFlow.test.d.ts +1 -0
  30. package/src/hooks/__tests__/useFraudReportFlow.test.js +1067 -0
  31. package/src/hooks/useFraudReportFlow.d.ts +32 -0
  32. package/src/hooks/useFraudReportFlow.js +265 -0
  33. package/src/locales/de.json +130 -0
  34. package/src/locales/en.json +130 -0
  35. package/src/locales/es.json +130 -0
  36. package/src/locales/fi.json +130 -0
  37. package/src/locales/fr.json +130 -0
  38. package/src/locales/it.json +130 -0
  39. package/src/locales/nl.json +130 -0
  40. package/src/locales/pt.json +130 -0
  41. package/src/utils/__tests__/fraudReport.card.test.d.ts +1 -0
  42. package/src/utils/__tests__/fraudReport.card.test.js +39 -0
  43. package/src/utils/__tests__/fraudReport.fakeApi.test.js +42 -13
  44. package/src/utils/__tests__/fraudReport.fraudster.test.d.ts +1 -0
  45. package/src/utils/__tests__/fraudReport.fraudster.test.js +35 -0
  46. package/src/utils/__tests__/fraudReport.messages.test.d.ts +1 -0
  47. package/src/utils/__tests__/fraudReport.messages.test.js +28 -0
  48. package/src/utils/__tests__/fraudReport.picker.test.d.ts +1 -0
  49. package/src/utils/__tests__/fraudReport.picker.test.js +171 -0
  50. package/src/utils/__tests__/fraudReport.pickerFilters.test.d.ts +1 -0
  51. package/src/utils/__tests__/fraudReport.pickerFilters.test.js +144 -0
  52. package/src/utils/__tests__/fraudReport.prefill.test.d.ts +1 -0
  53. package/src/utils/__tests__/fraudReport.prefill.test.js +151 -0
  54. package/src/utils/__tests__/fraudReport.rejections.test.d.ts +1 -0
  55. package/src/utils/__tests__/fraudReport.rejections.test.js +155 -0
  56. package/src/utils/__tests__/fraudReport.resume.test.d.ts +1 -0
  57. package/src/utils/__tests__/fraudReport.resume.test.js +81 -0
  58. package/src/utils/__tests__/fraudReport.stepper.test.d.ts +1 -0
  59. package/src/utils/__tests__/fraudReport.stepper.test.js +102 -0
  60. package/src/utils/__tests__/fraudReport.toInput.test.js +111 -37
  61. package/src/utils/__tests__/fraudReport.transactions.test.d.ts +1 -0
  62. package/src/utils/__tests__/fraudReport.transactions.test.js +38 -0
  63. package/src/utils/__tests__/fraudReport.types.test.d.ts +1 -0
  64. package/src/utils/__tests__/fraudReport.types.test.js +22 -0
  65. package/src/utils/__tests__/fraudReport.victim.test.d.ts +1 -0
  66. package/src/utils/__tests__/fraudReport.victim.test.js +168 -0
  67. package/src/utils/__tests__/phone.test.js +60 -5
  68. package/src/utils/__tests__/validation.test.js +69 -2
  69. package/src/utils/fraudReport/card.d.ts +11 -0
  70. package/src/utils/fraudReport/card.js +15 -0
  71. package/src/utils/fraudReport/fakeApi.d.ts +7 -4
  72. package/src/utils/fraudReport/fakeApi.js +19 -6
  73. package/src/utils/fraudReport/fraudster.d.ts +10 -0
  74. package/src/utils/fraudReport/fraudster.js +11 -0
  75. package/src/utils/fraudReport/messages.d.ts +4 -0
  76. package/src/utils/fraudReport/messages.js +7 -0
  77. package/src/utils/fraudReport/picker.d.ts +18 -0
  78. package/src/utils/fraudReport/picker.js +49 -0
  79. package/src/utils/fraudReport/pickerFilters.d.ts +26 -0
  80. package/src/utils/fraudReport/pickerFilters.js +62 -0
  81. package/src/utils/fraudReport/prefill.d.ts +3 -0
  82. package/src/utils/fraudReport/prefill.js +16 -0
  83. package/src/utils/fraudReport/rejections.d.ts +9 -0
  84. package/src/utils/fraudReport/rejections.js +49 -0
  85. package/src/utils/fraudReport/resume.d.ts +4 -0
  86. package/src/utils/fraudReport/resume.js +26 -0
  87. package/src/utils/fraudReport/stepper.d.ts +16 -0
  88. package/src/utils/fraudReport/stepper.js +21 -0
  89. package/src/utils/fraudReport/toInput.d.ts +14 -3
  90. package/src/utils/fraudReport/toInput.js +37 -31
  91. package/src/utils/fraudReport/transactions.d.ts +8 -0
  92. package/src/utils/fraudReport/transactions.js +11 -0
  93. package/src/utils/fraudReport/types.d.ts +8 -0
  94. package/src/utils/fraudReport/validation.d.ts +2 -1
  95. package/src/utils/fraudReport/validation.js +5 -0
  96. package/src/utils/fraudReport/victim.d.ts +41 -0
  97. package/src/utils/fraudReport/victim.js +37 -0
  98. package/src/utils/phone.d.ts +1 -0
  99. package/src/utils/phone.js +31 -4
  100. package/src/utils/validation.d.ts +2 -0
  101. package/src/utils/validation.js +14 -7
@@ -1,13 +1,15 @@
1
1
  import { Option } from "@bloodyowl/boxed";
2
2
  import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
3
- import { createFakeFraudReportApi } from "../fraudReport/fakeApi";
3
+ import { createFakeFraudReportApi, createFakeTransaction } from "../fraudReport/fakeApi";
4
+ import { toFormValues } from "../fraudReport/prefill";
4
5
  import { getCaseRail, getTransactionRail } from "../fraudReport/rail";
5
6
  import { toDraftInput, toUpdateInput } from "../fraudReport/toInput";
6
- import { validateDescription, validateDiscoveryDetails, validateExternalReference, validateNotInFuture, validateSharedInformation, validateTransactionIds, } from "../fraudReport/validation";
7
- const card1 = { id: "card-1", rail: "Card" };
8
- const card2 = { id: "card-2", rail: "Card" };
9
- const transfer1 = { id: "transfer-1", rail: "Transfer" };
10
- const transfer2 = { id: "transfer-2", rail: "Transfer" };
7
+ import { MAX_TRANSACTIONS } from "../fraudReport/transactions";
8
+ import { validateDescription, validateDiscoveryDetails, validateExternalReference, validateNotInFuture, validateSelected, validateSharedInformation, validateTransactionIds, } from "../fraudReport/validation";
9
+ const card1 = createFakeTransaction("card-1", "CardOutDebit");
10
+ const card2 = createFakeTransaction("card-2", "CardOutDebit");
11
+ const transfer1 = createFakeTransaction("transfer-1", "SepaCreditTransferOut");
12
+ const transfer2 = createFakeTransaction("transfer-2", "SepaCreditTransferOut");
11
13
  const DESCRIPTION_REGEX = /^(?=[\s\S]*\S)[\s\S]{1,2000}$/;
12
14
  const DISCOVERY_DETAILS_REGEX = /^(?=[\s\S]*\S)[\s\S]{1,1000}$/;
13
15
  const EXTERNAL_REFERENCE_REGEX = /^[\x20-\x7E]{1,255}$/;
@@ -91,6 +93,19 @@ describe("validateTransactionIds", () => {
91
93
  expect(validateTransactionIds(["card-1"])).toBeUndefined();
92
94
  expect(validateTransactionIds(["card-1", "transfer-1"])).toBeUndefined();
93
95
  });
96
+ test("accepts the most transactions a report takes, rejects one more", () => {
97
+ const ids = Array.from({ length: MAX_TRANSACTIONS + 1 }, (_, index) => `transfer-${index}`);
98
+ expect(validateTransactionIds(ids.slice(0, MAX_TRANSACTIONS))).toBeUndefined();
99
+ expect(validateTransactionIds(ids)).toBe("TooMany");
100
+ });
101
+ });
102
+ describe("validateSelected", () => {
103
+ test("requires a value", () => {
104
+ expect(validateSelected(undefined)).toBe("Required");
105
+ });
106
+ test("accepts a selected value", () => {
107
+ expect(validateSelected("Manipulated")).toBeUndefined();
108
+ });
94
109
  });
95
110
  describe("validateNotInFuture", () => {
96
111
  beforeEach(() => {
@@ -318,6 +333,21 @@ describe("toDraftInput", () => {
318
333
  expect(toDraftInput({ ...incident, transactions: [card1] })).not.toHaveProperty("fraudCardDetails");
319
334
  expect(toDraftInput({ ...incident, lostOrStolenNoticedAt: "", transactions: [card1] })).not.toHaveProperty("fraudCardDetails");
320
335
  });
336
+ test("sends the actions taken from the form", () => {
337
+ var _a;
338
+ const input = toDraftInput({
339
+ ...incident,
340
+ hasFiledPoliceComplaint: true,
341
+ hasContactedMerchant: true,
342
+ transactions: [card1],
343
+ });
344
+ expect((_a = input.fraudDetails) === null || _a === void 0 ? void 0 : _a.hasFiledPoliceComplaint).toBe(true);
345
+ expect(input.fraudCardDetails).toStrictEqual({
346
+ isLostOrStolen: null,
347
+ lostOrStolenNoticedAt: null,
348
+ hasContactedMerchant: true,
349
+ });
350
+ });
321
351
  test("sends null for the card detail left empty", () => {
322
352
  expect(toDraftInput({ isLostOrStolen: false, transactions: [card1] }).fraudCardDetails).toStrictEqual({
323
353
  isLostOrStolen: false,
@@ -337,11 +367,11 @@ describe("toDraftInput", () => {
337
367
  });
338
368
  });
339
369
  describe("toUpdateInput", () => {
340
- const savedCase = { id: "case-1", fraudDetails: null, fraudCardDetails: null };
370
+ const savedCase = { id: "case-1" };
341
371
  const disputeCaseId = savedCase.id;
342
372
  test("sends the card details and no victim on a card-only case", () => {
343
373
  expect(toUpdateInput({
344
- savedCase,
374
+ disputeCaseId: savedCase.id,
345
375
  values: { ...filled, transactions: [card1, card2] },
346
376
  savedTransactionIds: ["card-1"],
347
377
  })).toStrictEqual({
@@ -354,7 +384,7 @@ describe("toUpdateInput", () => {
354
384
  });
355
385
  test("sends the victim and no card details on a transfer-only case", () => {
356
386
  expect(toUpdateInput({
357
- savedCase,
387
+ disputeCaseId: savedCase.id,
358
388
  values: { ...filled, transactions: [transfer1] },
359
389
  savedTransactionIds: ["transfer-1", "card-1"],
360
390
  })).toStrictEqual({
@@ -367,7 +397,7 @@ describe("toUpdateInput", () => {
367
397
  });
368
398
  test("sends the card details and no victim on a mixed case", () => {
369
399
  expect(toUpdateInput({
370
- savedCase,
400
+ disputeCaseId: savedCase.id,
371
401
  values: { ...filled, transactions: [transfer1, card1] },
372
402
  savedTransactionIds: ["transfer-1"],
373
403
  })).toStrictEqual({
@@ -380,17 +410,33 @@ describe("toUpdateInput", () => {
380
410
  });
381
411
  test("never sends transfer details", () => {
382
412
  expect(toUpdateInput({
383
- savedCase,
413
+ disputeCaseId: savedCase.id,
384
414
  values: { ...filled, transactions: [transfer1] },
385
415
  savedTransactionIds: [],
386
416
  })).not.toHaveProperty("fraudTransferDetails");
387
417
  });
418
+ test("clears the fraudster answers once no fraudster convinced the user", () => {
419
+ expect(toUpdateInput({
420
+ disputeCaseId: savedCase.id,
421
+ values: { ...filled, reportedReason: "Unauthorized", transactions: [card1] },
422
+ savedTransactionIds: ["card-1"],
423
+ }).fraudDetails).toStrictEqual({
424
+ ...fraudDetails,
425
+ reportedReason: "Unauthorized",
426
+ fraudsterChannels: null,
427
+ sharedInformationWithFraudster: null,
428
+ });
429
+ });
388
430
  test("leaves the transaction IDs out when the selection didn't change", () => {
389
431
  expect(toUpdateInput({
390
- savedCase,
432
+ disputeCaseId: savedCase.id,
391
433
  values: { ...incident, transactions: [card1, transfer1] },
392
434
  savedTransactionIds: ["transfer-1", "card-1"],
393
- })).toStrictEqual({ disputeCaseId, fraudDetails: expect.any(Object) });
435
+ })).toStrictEqual({
436
+ disputeCaseId,
437
+ fraudDetails: expect.any(Object),
438
+ fraudCardDetails: expect.any(Object),
439
+ });
394
440
  });
395
441
  test.each([
396
442
  ["a transaction was added", [card1, card2], ["card-1"]],
@@ -398,49 +444,63 @@ describe("toUpdateInput", () => {
398
444
  ["a transaction was swapped", [card1, transfer1], ["card-1", "card-2"]],
399
445
  ["a transaction is there twice", [card1, card1], ["card-1", "card-2"]],
400
446
  ])("sends the whole selection when %s", (_, transactions, savedTransactionIds) => {
401
- expect(toUpdateInput({ savedCase, values: { transactions }, savedTransactionIds })).toStrictEqual({ disputeCaseId, transactionIds: transactions.map(({ id }) => id) });
447
+ expect(toUpdateInput({ disputeCaseId: savedCase.id, values: { transactions }, savedTransactionIds })).toStrictEqual({
448
+ disputeCaseId,
449
+ transactionIds: transactions.map(({ id }) => id),
450
+ fraudCardDetails: expect.any(Object),
451
+ });
402
452
  });
403
453
  test("leaves every group out when nothing is filled", () => {
404
454
  expect(toUpdateInput({
405
- savedCase,
455
+ disputeCaseId: savedCase.id,
456
+ values: { transactions: [transfer1] },
457
+ savedTransactionIds: ["transfer-1"],
458
+ })).toStrictEqual({ disputeCaseId });
459
+ });
460
+ test("sends the card details even when empty, so removed answers are cleared", () => {
461
+ expect(toUpdateInput({
462
+ disputeCaseId: savedCase.id,
406
463
  values: { transactions: [card1] },
407
464
  savedTransactionIds: ["card-1"],
408
- })).toStrictEqual({ disputeCaseId });
465
+ })).toStrictEqual({
466
+ disputeCaseId,
467
+ fraudCardDetails: {
468
+ isLostOrStolen: null,
469
+ lostOrStolenNoticedAt: null,
470
+ hasContactedMerchant: null,
471
+ },
472
+ });
409
473
  });
410
474
  test("clears the external reference when it was emptied", () => {
411
475
  expect(toUpdateInput({
412
- savedCase,
413
- values: { externalReference: "", transactions: [card1] },
414
- savedTransactionIds: ["card-1"],
476
+ disputeCaseId: savedCase.id,
477
+ values: { externalReference: "", transactions: [transfer1] },
478
+ savedTransactionIds: ["transfer-1"],
415
479
  })).toStrictEqual({ disputeCaseId, externalReference: null });
416
480
  });
417
481
  test("keeps the stored external reference when the form has none", () => {
418
482
  expect(toUpdateInput({
419
- savedCase,
483
+ disputeCaseId: savedCase.id,
420
484
  values: { ...incident, transactions: [card1] },
421
485
  savedTransactionIds: ["card-1"],
422
486
  })).not.toHaveProperty("externalReference");
423
487
  });
424
488
  test("holds the card details and the victim back while no transaction is selected", () => {
425
489
  expect(toUpdateInput({
426
- savedCase,
490
+ disputeCaseId: savedCase.id,
427
491
  values: { ...filled, transactions: [] },
428
492
  savedTransactionIds: [],
429
493
  })).toStrictEqual({ disputeCaseId, fraudDetails, externalReference: "REF-42" });
430
494
  });
431
- test("sends back the actions taken saved on the case, which the form doesn't hold", () => {
495
+ test("sends the actions taken from the form", () => {
432
496
  var _a, _b;
433
497
  const input = toUpdateInput({
434
- savedCase: {
435
- id: "case-1",
436
- fraudDetails: { ...fraudDetails, hasFiledPoliceComplaint: true },
437
- fraudCardDetails: { ...fraudCardDetails, hasContactedMerchant: false },
438
- },
439
- values: { ...filled, transactions: [card1] },
498
+ disputeCaseId: savedCase.id,
499
+ values: { ...filled, hasContactedMerchant: true, transactions: [card1] },
440
500
  savedTransactionIds: ["card-1"],
441
501
  });
442
- expect((_a = input.fraudDetails) === null || _a === void 0 ? void 0 : _a.hasFiledPoliceComplaint).toBe(true);
443
- expect((_b = input.fraudCardDetails) === null || _b === void 0 ? void 0 : _b.hasContactedMerchant).toBe(false);
502
+ expect((_a = input.fraudDetails) === null || _a === void 0 ? void 0 : _a.hasFiledPoliceComplaint).toBeNull();
503
+ expect((_b = input.fraudCardDetails) === null || _b === void 0 ? void 0 : _b.hasContactedMerchant).toBe(true);
444
504
  });
445
505
  });
446
506
  describe("inputs sent to the API", () => {
@@ -449,10 +509,10 @@ describe("inputs sent to the API", () => {
449
509
  {
450
510
  id: "card-1",
451
511
  accountId: "account-1",
452
- rail: "Card",
512
+ type: "CardOutDebit",
453
513
  cardholderAccountMembershipId: "member-2",
454
514
  },
455
- { id: "transfer-1", accountId: "account-1", rail: "Transfer" },
515
+ { id: "transfer-1", accountId: "account-1", type: "SepaCreditTransferOut" },
456
516
  ],
457
517
  accountMemberships: [
458
518
  { id: "member-1", accountId: "account-1" },
@@ -484,7 +544,7 @@ describe("inputs sent to the API", () => {
484
544
  const api = createApi();
485
545
  const savedCase = getCase(await api.draft(toDraftInput({ ...filled, transactions: [card1] })));
486
546
  const updated = getCase(await api.update(toUpdateInput({
487
- savedCase,
547
+ disputeCaseId: savedCase.id,
488
548
  values: { ...filled, transactions: [transfer1] },
489
549
  savedTransactionIds: ["card-1"],
490
550
  })));
@@ -496,7 +556,7 @@ describe("inputs sent to the API", () => {
496
556
  const api = createApi();
497
557
  const savedCase = getCase(await api.draft(toDraftInput({ ...filled, transactions: [transfer1] })));
498
558
  const updated = getCase(await api.update(toUpdateInput({
499
- savedCase,
559
+ disputeCaseId: savedCase.id,
500
560
  values: { ...filled, transactions: [card1] },
501
561
  savedTransactionIds: ["transfer-1"],
502
562
  })));
@@ -504,7 +564,21 @@ describe("inputs sent to the API", () => {
504
564
  expect(updated.fraudCardDetails).toMatchObject({ isLostOrStolen: true });
505
565
  expect(updated.victimAccountMembershipId).toBe("member-2");
506
566
  });
507
- test("an update keeps the actions taken that another client stored on the draft", async () => {
567
+ test("an update clears an action the user removed", async () => {
568
+ var _a;
569
+ const api = createApi();
570
+ const savedCase = getCase(await api.draft({
571
+ transactionIds: ["card-1"],
572
+ fraudCardDetails: { hasContactedMerchant: true },
573
+ }));
574
+ const updated = getCase(await api.update(toUpdateInput({
575
+ disputeCaseId: savedCase.id,
576
+ values: { ...toFormValues(savedCase), hasContactedMerchant: undefined },
577
+ savedTransactionIds: ["card-1"],
578
+ })));
579
+ expect((_a = updated.fraudCardDetails) === null || _a === void 0 ? void 0 : _a.hasContactedMerchant).toBeNull();
580
+ });
581
+ test("an update keeps the details another client stored on a resumed draft", async () => {
508
582
  var _a;
509
583
  const api = createApi();
510
584
  const savedCase = getCase(await api.draft({
@@ -514,8 +588,8 @@ describe("inputs sent to the API", () => {
514
588
  fraudTransferDetails: { hasContactedBankOrBeneficiary: true },
515
589
  }));
516
590
  const updated = getCase(await api.update(toUpdateInput({
517
- savedCase,
518
- values: { ...filled, transactions: [card1, transfer1] },
591
+ disputeCaseId: savedCase.id,
592
+ values: { ...toFormValues(savedCase), ...filled, transactions: [card1, transfer1] },
519
593
  savedTransactionIds: ["card-1", "transfer-1"],
520
594
  })));
521
595
  expect((_a = updated.fraudDetails) === null || _a === void 0 ? void 0 : _a.hasFiledPoliceComplaint).toBe(true);
@@ -0,0 +1,38 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { createFakeTransaction } from "../fraudReport/fakeApi";
3
+ import { getTransactionsOverLimit, getTransactionsTotal, MAX_TRANSACTIONS, 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
+ });
29
+ describe("getTransactionsOverLimit", () => {
30
+ test("is 0 up to the limit", () => {
31
+ expect(getTransactionsOverLimit(0)).toBe(0);
32
+ expect(getTransactionsOverLimit(MAX_TRANSACTIONS)).toBe(0);
33
+ });
34
+ test("is the number of transactions to remove over the limit", () => {
35
+ expect(getTransactionsOverLimit(MAX_TRANSACTIONS + 1)).toBe(1);
36
+ expect(getTransactionsOverLimit(MAX_TRANSACTIONS + 2)).toBe(2);
37
+ });
38
+ });
@@ -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 {};
@@ -0,0 +1,168 @@
1
+ import { Option } from "@bloodyowl/boxed";
2
+ import { describe, expect, test } from "vitest";
3
+ import { createFakeTransaction } from "../fraudReport/fakeApi";
4
+ import { getInitialVictimChoice, getOtherAccountMemberships, getSelectedAccountMembershipId, getVictimAccountMembershipId, getVictimChange, } from "../fraudReport/victim";
5
+ const julia = { id: "member-1", name: "Julia Fox" };
6
+ const nicolas = { id: "member-2", name: "Nicolas Saison" };
7
+ const ada = { id: "member-3", name: "Ada Lovelace" };
8
+ const accountMemberships = [julia, nicolas, ada];
9
+ const asMember = Option.Some(julia);
10
+ const asOperator = Option.None();
11
+ const choiceOf = (answer, selectedId) => ({
12
+ answer: Option.fromUndefined(answer),
13
+ selectedId: Option.fromUndefined(selectedId),
14
+ });
15
+ describe("getOtherAccountMemberships", () => {
16
+ test("leaves the current member out of the picker", () => {
17
+ expect(getOtherAccountMemberships({ currentAccountMembership: asMember, accountMemberships })).toEqual([nicolas, ada]);
18
+ });
19
+ test("lists every member for an operator", () => {
20
+ expect(getOtherAccountMemberships({ currentAccountMembership: asOperator, accountMemberships })).toEqual(accountMemberships);
21
+ });
22
+ });
23
+ describe("getInitialVictimChoice", () => {
24
+ test.each([
25
+ {
26
+ name: "nothing chosen yet",
27
+ victimAccountMembershipId: undefined,
28
+ answer: undefined,
29
+ victim: undefined,
30
+ },
31
+ {
32
+ name: "the member themselves",
33
+ victimAccountMembershipId: "member-1",
34
+ answer: "Myself",
35
+ victim: "member-1",
36
+ },
37
+ {
38
+ name: "another member",
39
+ victimAccountMembershipId: "member-2",
40
+ answer: "SomeoneElse",
41
+ victim: "member-2",
42
+ },
43
+ {
44
+ name: "a member no longer listed",
45
+ victimAccountMembershipId: "member-9",
46
+ answer: "SomeoneElse",
47
+ victim: undefined,
48
+ },
49
+ ])("gives back $name when a member comes back", ({ victimAccountMembershipId, answer, victim }) => {
50
+ const choice = getInitialVictimChoice({
51
+ currentAccountMembership: asMember,
52
+ victimAccountMembershipId,
53
+ });
54
+ expect(choice.answer.toUndefined()).toBe(answer);
55
+ expect(getVictimAccountMembershipId({
56
+ currentAccountMembership: asMember,
57
+ accountMemberships,
58
+ choice,
59
+ }).toUndefined()).toBe(victim);
60
+ });
61
+ test.each([
62
+ { name: "nothing chosen yet", victimAccountMembershipId: undefined, victim: undefined },
63
+ { name: "a listed member", victimAccountMembershipId: "member-1", victim: "member-1" },
64
+ { name: "a member no longer listed", victimAccountMembershipId: "member-9", victim: undefined },
65
+ ])("gives back $name when an operator comes back, with no answer", ({ victimAccountMembershipId, victim }) => {
66
+ const choice = getInitialVictimChoice({
67
+ currentAccountMembership: asOperator,
68
+ victimAccountMembershipId,
69
+ });
70
+ expect(choice.answer.isNone()).toBe(true);
71
+ expect(getVictimAccountMembershipId({
72
+ currentAccountMembership: asOperator,
73
+ accountMemberships,
74
+ choice,
75
+ }).toUndefined()).toBe(victim);
76
+ });
77
+ });
78
+ describe("getSelectedAccountMembershipId", () => {
79
+ test.each([
80
+ { name: "another listed member", selectedId: "member-2", shown: "member-2" },
81
+ { name: "the member themselves", selectedId: "member-1", shown: undefined },
82
+ ])("shows $name in a member's picker", ({ selectedId, shown }) => {
83
+ expect(getSelectedAccountMembershipId({
84
+ currentAccountMembership: asMember,
85
+ accountMemberships,
86
+ choice: choiceOf("SomeoneElse", selectedId),
87
+ }).toUndefined()).toBe(shown);
88
+ });
89
+ test("drops a pick once the member leaves the list", () => {
90
+ const choice = choiceOf("SomeoneElse", "member-2");
91
+ expect(getSelectedAccountMembershipId({
92
+ currentAccountMembership: asMember,
93
+ accountMemberships,
94
+ choice,
95
+ }).toUndefined()).toBe("member-2");
96
+ expect(getSelectedAccountMembershipId({
97
+ currentAccountMembership: asMember,
98
+ accountMemberships: [julia, ada],
99
+ choice,
100
+ }).toUndefined()).toBeUndefined();
101
+ });
102
+ });
103
+ describe("getVictimAccountMembershipId", () => {
104
+ test.each([
105
+ { name: "no answer", answer: undefined, selectedId: "member-2", victim: undefined },
106
+ { name: "Myself", answer: "Myself", selectedId: "member-2", victim: "member-1" },
107
+ {
108
+ name: "SomeoneElse with a member picked",
109
+ answer: "SomeoneElse",
110
+ selectedId: "member-2",
111
+ victim: "member-2",
112
+ },
113
+ {
114
+ name: "SomeoneElse with no member picked",
115
+ answer: "SomeoneElse",
116
+ selectedId: undefined,
117
+ victim: undefined,
118
+ },
119
+ {
120
+ name: "SomeoneElse with a member no longer listed",
121
+ answer: "SomeoneElse",
122
+ selectedId: "member-9",
123
+ victim: undefined,
124
+ },
125
+ ])("gives the victim for a member answering $name", ({ answer, selectedId, victim }) => {
126
+ expect(getVictimAccountMembershipId({
127
+ currentAccountMembership: asMember,
128
+ accountMemberships,
129
+ choice: choiceOf(answer, selectedId),
130
+ }).toUndefined()).toBe(victim);
131
+ });
132
+ test.each([
133
+ { name: "a member picked", selectedId: "member-2", victim: "member-2" },
134
+ { name: "no member picked", selectedId: undefined, victim: undefined },
135
+ { name: "a member no longer listed", selectedId: "member-9", victim: undefined },
136
+ ])("gives the victim for an operator with $name", ({ selectedId, victim }) => {
137
+ expect(getVictimAccountMembershipId({
138
+ currentAccountMembership: asOperator,
139
+ accountMemberships,
140
+ choice: choiceOf(undefined, selectedId),
141
+ }).toUndefined()).toBe(victim);
142
+ });
143
+ });
144
+ describe("getVictimChange", () => {
145
+ const card = createFakeTransaction("card-1", "CardOutDebit");
146
+ const transfer = createFakeTransaction("transfer-1", "SepaCreditTransferOut");
147
+ test("removes the card transactions when the victim changes", () => {
148
+ expect(getVictimChange({
149
+ transactions: [card, transfer],
150
+ previousVictimAccountMembershipId: "member-1",
151
+ victimAccountMembershipId: "member-2",
152
+ })).toEqual({ changed: true, removed: [card], kept: [transfer] });
153
+ });
154
+ test("removes nothing when the victim stays the same", () => {
155
+ expect(getVictimChange({
156
+ transactions: [card, transfer],
157
+ previousVictimAccountMembershipId: "member-1",
158
+ victimAccountMembershipId: "member-1",
159
+ })).toEqual({ changed: false, removed: [], kept: [card, transfer] });
160
+ });
161
+ test("removes the card transactions when the previous victim isn't known", () => {
162
+ expect(getVictimChange({
163
+ transactions: [card, transfer],
164
+ previousVictimAccountMembershipId: undefined,
165
+ victimAccountMembershipId: "member-2",
166
+ })).toEqual({ changed: true, removed: [card], kept: [transfer] });
167
+ });
168
+ });
@@ -1,7 +1,6 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
2
  import { france, getCountryByCCA2, getCountryByCCA3 } from "../../constants/countries";
3
- import { getMostLikelyUserCountry } from "../localization";
4
- import { maskPhoneNumber, parsePhoneNumber, prefixPhoneNumber } from "../phone";
3
+ import { getDefaultPhoneCountry, maskPhoneNumber, parsePhoneNumber, prefixPhoneNumber, } from "../phone";
5
4
  const gambia = getCountryByCCA2("GM");
6
5
  const jamaica = getCountryByCCA2("JM");
7
6
  const curacao = getCountryByCCA2("CW");
@@ -51,8 +50,11 @@ describe("parsePhoneNumber splits an international number into its country and n
51
50
  });
52
51
  });
53
52
  });
54
- describe("parsePhoneNumber falls back to the most likely user country and an empty national number", () => {
55
- const fallback = { country: getMostLikelyUserCountry(), nationalNumber: "" };
53
+ describe("parsePhoneNumber falls back to the default phone country and an empty national number", () => {
54
+ const fallback = { country: france, nationalNumber: "" };
55
+ beforeEach(() => {
56
+ vi.stubGlobal("navigator", { languages: ["en-GB"] });
57
+ });
56
58
  afterEach(() => {
57
59
  vi.unstubAllGlobals();
58
60
  });
@@ -88,6 +90,59 @@ describe("parsePhoneNumber falls back to the most likely user country and an emp
88
90
  });
89
91
  });
90
92
  });
93
+ describe("getDefaultPhoneCountry picks one of our markets from the browser languages", () => {
94
+ const germany = getCountryByCCA2("DE");
95
+ const belgium = getCountryByCCA2("BE");
96
+ afterEach(() => {
97
+ vi.unstubAllGlobals();
98
+ });
99
+ it.each([[["en"]], [["en-GB"]], [["en-US"]], [["ja-JP"]], [[]]])("falls back to France for %j", languages => {
100
+ expect(getDefaultPhoneCountry(languages)).toEqual(france);
101
+ });
102
+ it.each([
103
+ ["fr", "FR"],
104
+ ["de", "DE"],
105
+ ["es", "ES"],
106
+ ["it", "IT"],
107
+ ["nl", "NL"],
108
+ ["pt", "PT"],
109
+ ])("maps the %s language to its country", (language, cca2) => {
110
+ expect(getDefaultPhoneCountry([language])).toEqual(getCountryByCCA2(cca2));
111
+ });
112
+ it.each([
113
+ ["nl-BE", "BE"],
114
+ ["fr-BE", "BE"],
115
+ ["en-BE", "BE"],
116
+ ["en-DE", "DE"],
117
+ ["es-PT", "PT"],
118
+ ])("uses the region of %s when it is one of our markets", (language, cca2) => {
119
+ expect(getDefaultPhoneCountry([language])).toEqual(getCountryByCCA2(cca2));
120
+ });
121
+ it.each([
122
+ ["de-AT", "DE"],
123
+ ["fr-CA", "FR"],
124
+ ["pt-BR", "PT"],
125
+ ])("uses the language of %s when its region isn't one of our markets", (language, cca2) => {
126
+ expect(getDefaultPhoneCountry([language])).toEqual(getCountryByCCA2(cca2));
127
+ });
128
+ it("keeps the browser's order of preference", () => {
129
+ expect(getDefaultPhoneCountry(["de-DE", "fr-FR"])).toEqual(germany);
130
+ expect(getDefaultPhoneCountry(["de", "nl-BE"])).toEqual(germany);
131
+ });
132
+ it("skips languages that don't match one of our markets", () => {
133
+ expect(getDefaultPhoneCountry(["en-US", "nl-BE"])).toEqual(belgium);
134
+ });
135
+ it("matches the language and region case-insensitively", () => {
136
+ expect(getDefaultPhoneCountry(["NL-be"])).toEqual(belgium);
137
+ });
138
+ it("skips invalid language tags", () => {
139
+ expect(getDefaultPhoneCountry(["not a tag", "de"])).toEqual(germany);
140
+ });
141
+ it("reads the browser languages by default", () => {
142
+ vi.stubGlobal("navigator", { languages: ["it-IT"] });
143
+ expect(getDefaultPhoneCountry()).toEqual(getCountryByCCA2("IT"));
144
+ });
145
+ });
91
146
  describe("prefixPhoneNumber turns a national number into an E.164 number", () => {
92
147
  it("prefixes a French national number", () => {
93
148
  expect(prefixPhoneNumber(france, "612345678")).toEqual({