@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,11 +1,11 @@
1
1
  import { Option } from "@bloodyowl/boxed";
2
2
  import { describe, expect, expectTypeOf, test } from "vitest";
3
- import { createFakeFraudReportApi, } from "../fraudReport/fakeApi";
3
+ import { createFakeFraudReportApi, createFakeTransaction, } from "../fraudReport/fakeApi";
4
4
  const NOW = new Date("2026-11-20T10:00:00.000Z");
5
5
  const card1 = {
6
6
  id: "card-1",
7
7
  accountId: "account-1",
8
- rail: "Card",
8
+ type: "CardOutDebit",
9
9
  cardholderAccountMembershipId: "member-1",
10
10
  };
11
11
  const card2 = { ...card1, id: "card-2" };
@@ -14,7 +14,11 @@ const cardOtherHolder = {
14
14
  id: "card-3",
15
15
  cardholderAccountMembershipId: "member-2",
16
16
  };
17
- const transfer1 = { id: "transfer-1", accountId: "account-1", rail: "Transfer" };
17
+ const transfer1 = {
18
+ id: "transfer-1",
19
+ accountId: "account-1",
20
+ type: "SepaCreditTransferOut",
21
+ };
18
22
  const transferOtherAccount = {
19
23
  ...transfer1,
20
24
  id: "transfer-2",
@@ -64,6 +68,15 @@ const getOk = (result) => result.match({
64
68
  },
65
69
  });
66
70
  const draft = async (api, input) => getOk(await api.draft(input));
71
+ describe("createFakeTransaction", () => {
72
+ test("takes the rail from the transaction type", () => {
73
+ expect(createFakeTransaction("card-1", "CardOutDebit").rail).toBe("Card");
74
+ expect(createFakeTransaction("transfer-1", "SepaInstantCreditTransferOut").rail).toBe("Transfer");
75
+ });
76
+ test("gives each transaction its own default counterparty", () => {
77
+ expect(createFakeTransaction("card-1", "CardOutDebit").counterparty).not.toBe(createFakeTransaction("card-2", "CardOutDebit").counterparty);
78
+ });
79
+ });
67
80
  describe("contract types", () => {
68
81
  test("the fake adapter implements FraudReportApi", () => {
69
82
  expectTypeOf(createApi()).toExtend();
@@ -78,6 +91,20 @@ describe("contract types", () => {
78
91
  expectTypeOf().not.toExtend();
79
92
  });
80
93
  });
94
+ describe("seeded transactions", () => {
95
+ test("keep their type on the case", async () => {
96
+ const api = createFakeFraudReportApi({
97
+ transactions: [
98
+ { id: "instant-1", accountId: "account-1", type: "SepaInstantCreditTransferOut" },
99
+ ],
100
+ accountMemberships: [],
101
+ });
102
+ const created = await draft(api, { transactionIds: ["instant-1"] });
103
+ expect(created.transactions).toMatchObject([
104
+ { id: "instant-1", rail: "Transfer", type: "SepaInstantCreditTransferOut" },
105
+ ]);
106
+ });
107
+ });
81
108
  describe("happy path", () => {
82
109
  test("draft → update → submit", async () => {
83
110
  var _a, _b;
@@ -321,12 +348,12 @@ describe("submit and cancel rejections", () => {
321
348
  const notReportableCase = {
322
349
  ...seeded,
323
350
  id: "case-1",
324
- transactions: [{ id: "transfer-3", rail: "Transfer" }],
351
+ transactions: [createFakeTransaction("transfer-3", "SepaCreditTransferOut")],
325
352
  };
326
353
  const outsideCase = {
327
354
  ...seeded,
328
355
  id: "case-2",
329
- transactions: [{ id: "transfer-4", rail: "Transfer" }],
356
+ transactions: [createFakeTransaction("transfer-4", "SepaCreditTransferOut")],
330
357
  };
331
358
  const api = createApi({ cases: [notReportableCase, outsideCase] });
332
359
  expect(getRejection(await api.submit({ disputeCaseId: "case-1" }))).toMatchObject({
@@ -416,7 +443,7 @@ describe("check order", () => {
416
443
  const outsideAndReported = {
417
444
  ...seeded,
418
445
  id: "case-1",
419
- transactions: [{ id: "transfer-4", rail: "Transfer" }],
446
+ transactions: [createFakeTransaction("transfer-4", "SepaCreditTransferOut")],
420
447
  };
421
448
  const api = createApi({
422
449
  cases: [outsideAndReported, { ...seeded, id: "case-2" }],
@@ -431,7 +458,9 @@ describe("check order", () => {
431
458
  test("submit: DisputeCaseTransactionsNotFoundRejection when a transaction can no longer be reported", async () => {
432
459
  const seeded = await draft(createApi(), { transactionIds: ["transfer-1"], fraudDetails });
433
460
  const api = createApi({
434
- cases: [{ ...seeded, transactions: [{ id: "gone", rail: "Transfer" }] }],
461
+ cases: [
462
+ { ...seeded, transactions: [createFakeTransaction("gone", "SepaCreditTransferOut")] },
463
+ ],
435
464
  });
436
465
  expect(getRejection(await api.submit({ disputeCaseId: seeded.id }))).toMatchObject({
437
466
  __typename: "DisputeCaseTransactionsNotFoundRejection",
@@ -484,8 +513,8 @@ describe("details and victim after a transaction change", () => {
484
513
  fraudCardDetails: { isLostOrStolen: true },
485
514
  });
486
515
  expect(created.transactions).toEqual([
487
- { id: "card-1", rail: "Card" },
488
- { id: "transfer-1", rail: "Transfer" },
516
+ createFakeTransaction("card-1", "CardOutDebit"),
517
+ createFakeTransaction("transfer-1", "SepaCreditTransferOut"),
489
518
  ]);
490
519
  const updated = getOk(await api.update({ disputeCaseId: created.id, transactionIds: ["transfer-1"] }));
491
520
  expect(updated.fraudCardDetails).toBeNull();
@@ -545,16 +574,16 @@ describe("more precedence", () => {
545
574
  ...seeded,
546
575
  id: "case-1",
547
576
  transactions: [
548
- { id: "gone", rail: "Transfer" },
549
- { id: "transfer-3", rail: "Transfer" },
577
+ createFakeTransaction("gone", "SepaCreditTransferOut"),
578
+ createFakeTransaction("transfer-3", "SepaCreditTransferOut"),
550
579
  ],
551
580
  },
552
581
  {
553
582
  ...seeded,
554
583
  id: "case-2",
555
584
  transactions: [
556
- { id: "transfer-3", rail: "Transfer" },
557
- { id: "transfer-4", rail: "Transfer" },
585
+ createFakeTransaction("transfer-3", "SepaCreditTransferOut"),
586
+ createFakeTransaction("transfer-4", "SepaCreditTransferOut"),
558
587
  ],
559
588
  },
560
589
  ],
@@ -0,0 +1,35 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { getSharedInformationChoice, toSharedInformation } from "../fraudReport/fraudster";
3
+ describe("getSharedInformationChoice", () => {
4
+ test.each([undefined, []])("leaves the question unanswered for %j", shared => {
5
+ expect(getSharedInformationChoice(shared)).toEqual({ answer: undefined, items: [] });
6
+ });
7
+ test("answers No when nothing was shared", () => {
8
+ expect(getSharedInformationChoice(["None"])).toEqual({ answer: "No", items: [] });
9
+ expect(getSharedInformationChoice(["None", "CardDetails"])).toEqual({
10
+ answer: "No",
11
+ items: [],
12
+ });
13
+ });
14
+ test("answers Yes with what was shared", () => {
15
+ expect(getSharedInformationChoice(["VerificationCode", "CardDetails"])).toEqual({
16
+ answer: "Yes",
17
+ items: ["VerificationCode", "CardDetails"],
18
+ });
19
+ });
20
+ });
21
+ describe("toSharedInformation", () => {
22
+ test("sends None for No, even with items picked before", () => {
23
+ expect(toSharedInformation({ answer: "No", items: ["CardDetails"] })).toEqual(["None"]);
24
+ });
25
+ test("sends what was shared for Yes", () => {
26
+ expect(toSharedInformation({ answer: "Yes", items: ["SwanPasscode", "BankDetails"] })).toEqual([
27
+ "SwanPasscode",
28
+ "BankDetails",
29
+ ]);
30
+ });
31
+ test("leaves the answer empty for Yes with nothing picked, or no answer", () => {
32
+ expect(toSharedInformation({ answer: "Yes", items: [] })).toBeUndefined();
33
+ expect(toSharedInformation({ answer: undefined, items: ["CardDetails"] })).toBeUndefined();
34
+ });
35
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { expect, test } from "vitest";
2
+ import en from "../../locales/en.json";
3
+ import { getTransactionsLimitMessage } from "../fraudReport/messages";
4
+ import { MAX_TRANSACTIONS } from "../fraudReport/transactions";
5
+ test("gives the limit of a report", () => {
6
+ expect(getTransactionsLimitMessage()).toBe(`You can report up to ${MAX_TRANSACTIONS} transactions at a time.`);
7
+ });
8
+ test("gives the limit the API rejection carries", () => {
9
+ expect(getTransactionsLimitMessage({ max: 50 })).toBe("You can report up to 50 transactions at a time.");
10
+ });
11
+ test("says how many transactions to remove", () => {
12
+ expect(getTransactionsLimitMessage({ toRemove: 2 })).toBe(`You can report up to ${MAX_TRANSACTIONS} transactions at a time. Remove 2 to continue.`);
13
+ });
14
+ test("says how many to remove with the limit the API rejection carries", () => {
15
+ expect(getTransactionsLimitMessage({ max: 50, toRemove: 2 })).toBe("You can report up to 50 transactions at a time. Remove 2 to continue.");
16
+ });
17
+ test("asks to remove nothing when nothing is over the limit", () => {
18
+ expect(getTransactionsLimitMessage({ toRemove: 0 })).toBe(getTransactionsLimitMessage());
19
+ });
20
+ test.each([
21
+ "fraudReport.transactions.limit",
22
+ "fraudReport.picker.limitExceeded",
23
+ "fraudReport.picker.description",
24
+ "fraudReport.intro.rule.transactions",
25
+ ])("%s takes the limit as an argument", key => {
26
+ expect(en[key]).toContain("{max}");
27
+ expect(en[key]).not.toContain(String(MAX_TRANSACTIONS));
28
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,171 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { createFakeTransaction } from "../fraudReport/fakeApi";
3
+ import { countPagesWithoutRows, getPickerTransactions, getSelectAllValue, restartPickerPages, toggleAllTransactions, toggleTransaction, } from "../fraudReport/picker";
4
+ const victimCard = createFakeTransaction("card-victim", "CardOutDebit");
5
+ const otherCard = createFakeTransaction("card-other", "CardOutDebit");
6
+ const sepa = createFakeTransaction("transfer-sepa", "SepaCreditTransferOut");
7
+ const instant = createFakeTransaction("transfer-instant", "SepaInstantCreditTransferOut");
8
+ const international = createFakeTransaction("transfer-international", "InternationalCreditTransferOut");
9
+ const internal = createFakeTransaction("transfer-internal", "InternalCreditTransferOut");
10
+ const rows = [
11
+ { transaction: victimCard, cardAccountMembershipId: "member-victim" },
12
+ { transaction: otherCard, cardAccountMembershipId: "member-other" },
13
+ { transaction: sepa, cardAccountMembershipId: null },
14
+ { transaction: instant, cardAccountMembershipId: null },
15
+ { transaction: international, cardAccountMembershipId: null },
16
+ { transaction: internal, cardAccountMembershipId: null },
17
+ ];
18
+ describe("getPickerTransactions", () => {
19
+ test("lists a card transaction only when its card belongs to the victim", () => {
20
+ const listed = getPickerTransactions(rows, "member-victim");
21
+ expect(listed).toContain(victimCard);
22
+ expect(listed).not.toContain(otherCard);
23
+ });
24
+ test("lists every transfer, whoever the victim is", () => {
25
+ expect(getPickerTransactions(rows, "member-other")).toEqual([
26
+ otherCard,
27
+ sepa,
28
+ instant,
29
+ international,
30
+ internal,
31
+ ]);
32
+ });
33
+ test("lists no card transaction while the victim isn't known", () => {
34
+ expect(getPickerTransactions(rows, undefined)).toEqual([
35
+ sepa,
36
+ instant,
37
+ international,
38
+ internal,
39
+ ]);
40
+ });
41
+ test("leaves out a card transaction whose card has no known account membership", () => {
42
+ expect(getPickerTransactions([{ transaction: victimCard, cardAccountMembershipId: null }], "member-victim")).toEqual([]);
43
+ });
44
+ test("keeps the order of the rows and removes duplicates", () => {
45
+ expect(getPickerTransactions([
46
+ { transaction: sepa, cardAccountMembershipId: null },
47
+ { transaction: victimCard, cardAccountMembershipId: "member-victim" },
48
+ { transaction: sepa, cardAccountMembershipId: null },
49
+ ], "member-victim")).toEqual([sepa, victimCard]);
50
+ });
51
+ });
52
+ describe("toggleTransaction", () => {
53
+ test("adds a transaction that isn't selected, after the others", () => {
54
+ expect(toggleTransaction([sepa], victimCard)).toEqual([sepa, victimCard]);
55
+ });
56
+ test("removes a selected transaction, matched by ID", () => {
57
+ expect(toggleTransaction([sepa, victimCard], { ...sepa, counterparty: "Renamed" })).toEqual([
58
+ victimCard,
59
+ ]);
60
+ });
61
+ });
62
+ describe("getSelectAllValue", () => {
63
+ test("is false when no listed transaction is selected", () => {
64
+ expect(getSelectAllValue([otherCard], [sepa, instant])).toBe(false);
65
+ });
66
+ test("is mixed when some listed transactions are selected", () => {
67
+ expect(getSelectAllValue([sepa], [sepa, instant])).toBe("mixed");
68
+ });
69
+ test("is true when every listed transaction is selected", () => {
70
+ expect(getSelectAllValue([instant, sepa, otherCard], [sepa, instant])).toBe(true);
71
+ });
72
+ test("is false when nothing is listed", () => {
73
+ expect(getSelectAllValue([sepa], [])).toBe(false);
74
+ });
75
+ });
76
+ describe("toggleAllTransactions", () => {
77
+ test("selects the listed transactions that aren't selected yet", () => {
78
+ expect(toggleAllTransactions([instant], [sepa, instant, internal])).toEqual([
79
+ instant,
80
+ sepa,
81
+ internal,
82
+ ]);
83
+ });
84
+ test("unselects the listed transactions when all of them are selected", () => {
85
+ expect(toggleAllTransactions([sepa, instant], [sepa, instant])).toEqual([]);
86
+ });
87
+ test("keeps a selected transaction that isn't listed, both ways", () => {
88
+ expect(toggleAllTransactions([otherCard], [sepa])).toEqual([otherCard, sepa]);
89
+ expect(toggleAllTransactions([otherCard, sepa], [sepa])).toEqual([otherCard]);
90
+ });
91
+ });
92
+ describe("countPagesWithoutRows", () => {
93
+ const start = { rowCount: 20, listedCount: 4, withoutRows: 0, restarted: false };
94
+ test("counts a page that adds no listed row", () => {
95
+ expect(countPagesWithoutRows(start, 40, 4)).toEqual({
96
+ rowCount: 40,
97
+ listedCount: 4,
98
+ withoutRows: 1,
99
+ restarted: false,
100
+ });
101
+ });
102
+ test("keeps counting over pages in a row", () => {
103
+ const second = countPagesWithoutRows(countPagesWithoutRows(start, 40, 4), 60, 4);
104
+ expect(second.withoutRows).toBe(2);
105
+ });
106
+ test("starts again from zero when a page adds a listed row", () => {
107
+ const empty = countPagesWithoutRows(start, 40, 4);
108
+ expect(countPagesWithoutRows(empty, 60, 5)).toEqual({
109
+ rowCount: 60,
110
+ listedCount: 5,
111
+ withoutRows: 0,
112
+ restarted: false,
113
+ });
114
+ });
115
+ test("doesn't count a render with no new page", () => {
116
+ const empty = countPagesWithoutRows(start, 40, 4);
117
+ expect(countPagesWithoutRows(empty, 40, 4)).toBe(empty);
118
+ });
119
+ test("doesn't count the rows being cleared", () => {
120
+ const paused = { ...start, withoutRows: 3 };
121
+ expect(countPagesWithoutRows(paused, 0, 0)).toEqual({
122
+ rowCount: 0,
123
+ listedCount: 0,
124
+ withoutRows: 0,
125
+ restarted: false,
126
+ });
127
+ });
128
+ test("starts again when fewer rows come back: it is another list", () => {
129
+ const long = { rowCount: 60, listedCount: 10, withoutRows: 2, restarted: false };
130
+ expect(countPagesWithoutRows(long, 20, 3).withoutRows).toBe(0);
131
+ expect(countPagesWithoutRows(long, 20, 0).withoutRows).toBe(1);
132
+ });
133
+ });
134
+ describe("restartPickerPages", () => {
135
+ const paused = { rowCount: 20, listedCount: 10, withoutRows: 3, restarted: false };
136
+ test("ends the pause right away", () => {
137
+ expect(restartPickerPages(paused).withoutRows).toBe(0);
138
+ });
139
+ test("makes the next rows a first page, even when they are more than before", () => {
140
+ const restarted = restartPickerPages(paused);
141
+ expect(countPagesWithoutRows(restarted, 40, 3)).toEqual({
142
+ rowCount: 40,
143
+ listedCount: 3,
144
+ withoutRows: 0,
145
+ restarted: false,
146
+ });
147
+ expect(countPagesWithoutRows(restarted, 40, 0).withoutRows).toBe(1);
148
+ });
149
+ test("waits for the rows to change", () => {
150
+ const restarted = restartPickerPages(paused);
151
+ expect(countPagesWithoutRows(restarted, 20, 10)).toBe(restarted);
152
+ });
153
+ test("counts a first page with as many rows as before, once the load ended", () => {
154
+ const restarted = restartPickerPages(paused);
155
+ expect(countPagesWithoutRows(restarted, 20, 0, true)).toEqual({
156
+ rowCount: 20,
157
+ listedCount: 0,
158
+ withoutRows: 1,
159
+ restarted: false,
160
+ });
161
+ expect(countPagesWithoutRows(restarted, 20, 4, true).withoutRows).toBe(0);
162
+ });
163
+ test("the end of a load counts no page when the list wasn't replaced", () => {
164
+ expect(countPagesWithoutRows(paused, 20, 10, true)).toBe(paused);
165
+ });
166
+ test("counts the pages after the first one as usual", () => {
167
+ const first = countPagesWithoutRows(restartPickerPages(paused), 40, 3);
168
+ expect(countPagesWithoutRows(first, 60, 3).withoutRows).toBe(1);
169
+ expect(countPagesWithoutRows(first, 60, 4).withoutRows).toBe(0);
170
+ });
171
+ });
@@ -0,0 +1,144 @@
1
+ import dayjs from "dayjs";
2
+ import { describe, expect, test } from "vitest";
3
+ import { hasPickerFilters, isSamePickerFilters, parseAmountFilter, pickerFilterTypes, setPickerFilters, toExecutionDateBounds, togglePickerFilterType, validateFromDate, validateToDate, } from "../fraudReport/pickerFilters";
4
+ describe("setPickerFilters", () => {
5
+ test("adds a filter and keeps the others", () => {
6
+ expect(setPickerFilters({ amount: "12.50" }, { fromDate: "2026-11-01" })).toEqual({
7
+ amount: "12.50",
8
+ fromDate: "2026-11-01",
9
+ });
10
+ });
11
+ test("replaces a filter that is already set", () => {
12
+ expect(setPickerFilters({ types: ["CardOutDebit"] }, { types: ["SepaCreditTransferOut"] })).toEqual({ types: ["SepaCreditTransferOut"] });
13
+ });
14
+ test("removes a filter set to undefined, an empty text or an empty list", () => {
15
+ const filters = {
16
+ search: "rewe",
17
+ amount: "12.50",
18
+ types: ["CardOutDebit"],
19
+ toDate: "2026-11-02",
20
+ };
21
+ expect(setPickerFilters(filters, { search: "", amount: undefined, types: [], toDate: "2026-11-02" })).toEqual({ toDate: "2026-11-02" });
22
+ });
23
+ test("trims the search, and removes it when only spaces are left", () => {
24
+ expect(setPickerFilters({}, { search: " rewe " })).toEqual({ search: "rewe" });
25
+ expect(setPickerFilters({ search: "rewe" }, { search: " " })).toEqual({});
26
+ });
27
+ });
28
+ describe("hasPickerFilters", () => {
29
+ test("is false without any filter", () => {
30
+ expect(hasPickerFilters({})).toBe(false);
31
+ });
32
+ test("is true with a search or a chip filter", () => {
33
+ expect(hasPickerFilters({ search: "rewe" })).toBe(true);
34
+ expect(hasPickerFilters({ amount: "12" })).toBe(true);
35
+ });
36
+ });
37
+ describe("parseAmountFilter", () => {
38
+ test("accepts an amount with up to two decimals", () => {
39
+ expect(parseAmountFilter("12")).toEqual({ amount: "12" });
40
+ expect(parseAmountFilter(" 3010.99 ")).toEqual({ amount: "3010.99" });
41
+ expect(parseAmountFilter("0.5")).toEqual({ amount: "0.5" });
42
+ });
43
+ test("reads a comma as the decimal separator", () => {
44
+ expect(parseAmountFilter("657,75")).toEqual({ amount: "657.75" });
45
+ });
46
+ test("an empty text clears the filter", () => {
47
+ expect(parseAmountFilter(" ")).toEqual({ amount: undefined });
48
+ });
49
+ test("rejects anything else", () => {
50
+ expect(parseAmountFilter("abc")).toEqual({ error: "InvalidAmount" });
51
+ expect(parseAmountFilter("12.345")).toEqual({ error: "InvalidAmount" });
52
+ expect(parseAmountFilter("-12")).toEqual({ error: "InvalidAmount" });
53
+ expect(parseAmountFilter("1 000")).toEqual({ error: "InvalidAmount" });
54
+ expect(parseAmountFilter("12.")).toEqual({ error: "InvalidAmount" });
55
+ });
56
+ });
57
+ describe("validateFromDate", () => {
58
+ test("accepts any date without an end", () => {
59
+ expect(validateFromDate("2026-11-30", undefined)).toBeUndefined();
60
+ });
61
+ test("rejects a date after the end of the range, accepts the same day", () => {
62
+ expect(validateFromDate("2026-11-11", "2026-11-10")).toBe("StartAfterEnd");
63
+ expect(validateFromDate("2026-11-10", "2026-11-10")).toBeUndefined();
64
+ expect(validateFromDate("2026-11-09", "2026-11-10")).toBeUndefined();
65
+ });
66
+ test("rejects a date that doesn't exist", () => {
67
+ expect(validateFromDate("2026-02-30", undefined)).toBe("InvalidDate");
68
+ expect(validateFromDate("", undefined)).toBe("InvalidDate");
69
+ });
70
+ });
71
+ describe("validateToDate", () => {
72
+ test("accepts any date without a start", () => {
73
+ expect(validateToDate("2026-11-30", undefined)).toBeUndefined();
74
+ });
75
+ test("rejects a date before the start of the range, accepts the same day", () => {
76
+ expect(validateToDate("2026-11-09", "2026-11-10")).toBe("StartAfterEnd");
77
+ expect(validateToDate("2026-11-10", "2026-11-10")).toBeUndefined();
78
+ expect(validateToDate("2026-11-11", "2026-11-10")).toBeUndefined();
79
+ });
80
+ test("rejects a date that doesn't exist", () => {
81
+ expect(validateToDate("2026-13-01", undefined)).toBe("InvalidDate");
82
+ });
83
+ });
84
+ describe("toExecutionDateBounds", () => {
85
+ test("has no bound without a date filter", () => {
86
+ expect(toExecutionDateBounds({ search: "rewe" })).toEqual({});
87
+ });
88
+ test("starts at the beginning of the first day, in the user's time zone", () => {
89
+ expect(toExecutionDateBounds({ fromDate: "2026-11-04" })).toEqual({
90
+ isAfterExecutionDate: dayjs("2026-11-04T00:00:00").toISOString(),
91
+ });
92
+ });
93
+ test("ends at the beginning of the day after the last one, so the last day is included", () => {
94
+ expect(toExecutionDateBounds({ toDate: "2026-11-04" })).toEqual({
95
+ isBeforeExecutionDate: dayjs("2026-11-05T00:00:00").toISOString(),
96
+ });
97
+ });
98
+ test("includes a transaction of the only day of a one-day range", () => {
99
+ const { isAfterExecutionDate = "", isBeforeExecutionDate = "" } = toExecutionDateBounds({
100
+ fromDate: "2026-11-04",
101
+ toDate: "2026-11-04",
102
+ });
103
+ const executionDate = dayjs("2026-11-04T15:30:00").toISOString();
104
+ expect(isAfterExecutionDate <= executionDate).toBe(true);
105
+ expect(executionDate < isBeforeExecutionDate).toBe(true);
106
+ });
107
+ });
108
+ describe("togglePickerFilterType", () => {
109
+ test("adds a type that isn't ticked", () => {
110
+ expect(togglePickerFilterType(undefined, "CardOutDebit")).toEqual(["CardOutDebit"]);
111
+ });
112
+ test("removes a ticked type", () => {
113
+ expect(togglePickerFilterType(["CardOutDebit", "SepaCreditTransferOut"], "CardOutDebit")).toEqual(["SepaCreditTransferOut"]);
114
+ expect(togglePickerFilterType(["CardOutDebit"], "CardOutDebit")).toEqual([]);
115
+ });
116
+ test("keeps the order of the list, whatever the order of the ticks", () => {
117
+ expect(togglePickerFilterType(["InternalCreditTransferOut"], "CardOutDebit")).toEqual([
118
+ "CardOutDebit",
119
+ "InternalCreditTransferOut",
120
+ ]);
121
+ });
122
+ test("lists the card first, then the transfers", () => {
123
+ expect(pickerFilterTypes).toEqual([
124
+ "CardOutDebit",
125
+ "SepaCreditTransferOut",
126
+ "SepaInstantCreditTransferOut",
127
+ "InternationalCreditTransferOut",
128
+ "InternalCreditTransferOut",
129
+ ]);
130
+ });
131
+ });
132
+ describe("isSamePickerFilters", () => {
133
+ test("is true for the same values", () => {
134
+ expect(isSamePickerFilters({ search: "rewe", types: ["CardOutDebit"] }, { search: "rewe", types: ["CardOutDebit"] })).toBe(true);
135
+ expect(isSamePickerFilters({}, {})).toBe(true);
136
+ });
137
+ test("is false when a value differs, is added or is removed", () => {
138
+ expect(isSamePickerFilters({ search: "rewe" }, { search: "lidl" })).toBe(false);
139
+ expect(isSamePickerFilters({}, { amount: "12" })).toBe(false);
140
+ expect(isSamePickerFilters({ fromDate: "2026-11-01" }, {})).toBe(false);
141
+ expect(isSamePickerFilters({ toDate: "2026-11-01" }, { toDate: "2026-11-02" })).toBe(false);
142
+ expect(isSamePickerFilters({ types: ["CardOutDebit"] }, { types: ["CardOutDebit", "SepaCreditTransferOut"] })).toBe(false);
143
+ });
144
+ });
@@ -0,0 +1 @@
1
+ export {};