@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
@@ -0,0 +1,151 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { createFakeTransaction } from "../fraudReport/fakeApi";
3
+ import { toFormValues } from "../fraudReport/prefill";
4
+ import { toUpdateInput } from "../fraudReport/toInput";
5
+ const card1 = createFakeTransaction("card-1", "CardOutDebit");
6
+ const transfer1 = createFakeTransaction("transfer-1", "SepaCreditTransferOut");
7
+ const fraudDetails = {
8
+ reportedReason: "Manipulated",
9
+ reportedTypology: "FakeAdvisor",
10
+ description: "A fake advisor called me",
11
+ discoveredAt: "2026-11-20",
12
+ discoveryDetails: "My bank app showed a payment I didn't make",
13
+ fraudsterChannels: ["Phone"],
14
+ sharedInformationWithFraudster: ["VerificationCode"],
15
+ hasFiledPoliceComplaint: true,
16
+ };
17
+ const fraudCardDetails = {
18
+ isLostOrStolen: true,
19
+ lostOrStolenNoticedAt: "2026-11-19",
20
+ hasContactedMerchant: false,
21
+ };
22
+ const draft = (overrides = {}) => ({
23
+ id: "case-1",
24
+ accountId: "account-1",
25
+ statusInfo: { status: "Draft", expiresAt: "2026-12-24T10:00:00.000Z" },
26
+ transactions: [],
27
+ fraudDetails: null,
28
+ fraudCardDetails: null,
29
+ fraudTransferDetails: null,
30
+ victimAccountMembershipId: null,
31
+ hasVictim: false,
32
+ externalReference: null,
33
+ supportingDocumentCollection: { id: "collection-1", status: "WaitingForDocument" },
34
+ createdAt: "2026-11-24T10:00:00.000Z",
35
+ updatedAt: "2026-11-24T10:00:00.000Z",
36
+ ...overrides,
37
+ });
38
+ const fullDraft = draft({
39
+ transactions: [card1, transfer1],
40
+ fraudDetails,
41
+ fraudCardDetails,
42
+ fraudTransferDetails: { hasContactedBankOrBeneficiary: true },
43
+ victimAccountMembershipId: "membership-2",
44
+ hasVictim: true,
45
+ externalReference: "ref-42",
46
+ });
47
+ const roundTrip = (savedCase) => toUpdateInput({
48
+ disputeCaseId: savedCase.id,
49
+ values: toFormValues(savedCase),
50
+ savedTransactionIds: savedCase.transactions.map(({ id }) => id),
51
+ });
52
+ describe("toFormValues", () => {
53
+ test("gives the form values of a draft with card, transfer and fraudster details", () => {
54
+ expect(toFormValues(fullDraft)).toEqual({
55
+ transactions: [card1, transfer1],
56
+ victimAccountMembershipId: "membership-2",
57
+ reportedReason: "Manipulated",
58
+ reportedTypology: "FakeAdvisor",
59
+ description: "A fake advisor called me",
60
+ discoveredAt: "2026-11-20",
61
+ discoveryDetails: "My bank app showed a payment I didn't make",
62
+ fraudsterChannels: ["Phone"],
63
+ sharedInformationWithFraudster: ["VerificationCode"],
64
+ hasFiledPoliceComplaint: true,
65
+ isLostOrStolen: true,
66
+ lostOrStolenNoticedAt: "2026-11-19",
67
+ hasContactedMerchant: false,
68
+ externalReference: "ref-42",
69
+ });
70
+ });
71
+ test("leaves every field empty on a draft with only transactions", () => {
72
+ expect(toFormValues(draft({ transactions: [card1] }))).toEqual({ transactions: [card1] });
73
+ });
74
+ test("leaves the missing fields empty on a partial draft", () => {
75
+ expect(toFormValues(draft({
76
+ transactions: [card1],
77
+ fraudDetails: {
78
+ ...fraudDetails,
79
+ discoveredAt: null,
80
+ discoveryDetails: null,
81
+ fraudsterChannels: [],
82
+ sharedInformationWithFraudster: [],
83
+ hasFiledPoliceComplaint: null,
84
+ },
85
+ fraudCardDetails: {
86
+ isLostOrStolen: false,
87
+ lostOrStolenNoticedAt: null,
88
+ hasContactedMerchant: null,
89
+ },
90
+ }))).toEqual({
91
+ transactions: [card1],
92
+ reportedReason: "Manipulated",
93
+ reportedTypology: "FakeAdvisor",
94
+ description: "A fake advisor called me",
95
+ fraudsterChannels: [],
96
+ sharedInformationWithFraudster: [],
97
+ isLostOrStolen: false,
98
+ });
99
+ });
100
+ test("gives no victim when the case has none to show", () => {
101
+ expect(toFormValues(draft({ transactions: [transfer1], hasVictim: true })).victimAccountMembershipId).toBeUndefined();
102
+ });
103
+ });
104
+ describe("toFormValues then toUpdateInput", () => {
105
+ test("sends back the stored details of a card-only draft", () => {
106
+ expect(roundTrip(draft({ transactions: [card1], fraudDetails, fraudCardDetails }))).toEqual({
107
+ disputeCaseId: "case-1",
108
+ fraudDetails,
109
+ fraudCardDetails,
110
+ });
111
+ });
112
+ test("sends back the stored details and victim of a transfer-only draft", () => {
113
+ expect(roundTrip(draft({
114
+ transactions: [transfer1],
115
+ fraudDetails,
116
+ victimAccountMembershipId: "membership-2",
117
+ hasVictim: true,
118
+ externalReference: "ref-42",
119
+ }))).toEqual({
120
+ disputeCaseId: "case-1",
121
+ fraudDetails,
122
+ victimAccountMembershipId: "membership-2",
123
+ externalReference: "ref-42",
124
+ });
125
+ });
126
+ test("sends back the stored details of a mixed draft", () => {
127
+ expect(roundTrip(fullDraft)).toEqual({
128
+ disputeCaseId: "case-1",
129
+ fraudDetails,
130
+ fraudCardDetails,
131
+ externalReference: "ref-42",
132
+ });
133
+ });
134
+ test("keeps the stored victim when the caller can't see it", () => {
135
+ expect(roundTrip(draft({ transactions: [transfer1], fraudDetails, hasVictim: true }))).toEqual({
136
+ disputeCaseId: "case-1",
137
+ fraudDetails,
138
+ });
139
+ });
140
+ test("sends empty fraudster lists back as null", () => {
141
+ const savedCase = draft({
142
+ transactions: [transfer1],
143
+ fraudDetails: { ...fraudDetails, fraudsterChannels: [], sharedInformationWithFraudster: [] },
144
+ });
145
+ expect(roundTrip(savedCase).fraudDetails).toEqual({
146
+ ...fraudDetails,
147
+ fraudsterChannels: null,
148
+ sharedInformationWithFraudster: null,
149
+ });
150
+ });
151
+ });
@@ -0,0 +1,155 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { getRejectionStep, } from "../fraudReport/rejections";
3
+ import { fraudReportDetailsSteps, } from "../fraudReport/types";
4
+ // A Record, so a rejection added to the contract fails typecheck until it is listed here
5
+ const rejections = {
6
+ AccountMembershipNotFoundRejection: {
7
+ __typename: "AccountMembershipNotFoundRejection",
8
+ message: "",
9
+ id: "membership-2",
10
+ },
11
+ DisputeCaseDetailsNotApplicableRejection: {
12
+ __typename: "DisputeCaseDetailsNotApplicableRejection",
13
+ message: "",
14
+ fields: [{ path: ["fraudCardDetails"] }],
15
+ },
16
+ DisputeCaseIncompleteRejection: {
17
+ __typename: "DisputeCaseIncompleteRejection",
18
+ message: "",
19
+ missingFields: [{ path: ["fraudDetails"] }],
20
+ },
21
+ DisputeCaseMultipleAccountsRejection: {
22
+ __typename: "DisputeCaseMultipleAccountsRejection",
23
+ message: "",
24
+ accountIds: ["account-1", "account-2"],
25
+ },
26
+ DisputeCaseMultipleCardHoldersRejection: {
27
+ __typename: "DisputeCaseMultipleCardHoldersRejection",
28
+ message: "",
29
+ accountMembershipIds: ["membership-1", "membership-2"],
30
+ },
31
+ DisputeCaseNotFoundRejection: {
32
+ __typename: "DisputeCaseNotFoundRejection",
33
+ message: "",
34
+ disputeCaseId: "case-1",
35
+ },
36
+ DisputeCaseTransactionsAlreadyReportedRejection: {
37
+ __typename: "DisputeCaseTransactionsAlreadyReportedRejection",
38
+ message: "",
39
+ transactions: [{ transactionId: "card-1", disputeCaseId: null }],
40
+ },
41
+ DisputeCaseTransactionsLimitExceededRejection: {
42
+ __typename: "DisputeCaseTransactionsLimitExceededRejection",
43
+ message: "",
44
+ transactionCount: 101,
45
+ maxTransactionCount: 100,
46
+ },
47
+ DisputeCaseTransactionsNotFoundRejection: {
48
+ __typename: "DisputeCaseTransactionsNotFoundRejection",
49
+ message: "",
50
+ transactionIds: ["card-1"],
51
+ },
52
+ DisputeCaseTransactionsNotReportableRejection: {
53
+ __typename: "DisputeCaseTransactionsNotReportableRejection",
54
+ message: "",
55
+ transactions: [{ transactionId: "card-1", reason: "TransactionStatusNotReportable" }],
56
+ },
57
+ DisputeCaseTransactionsOutsideReportingWindowRejection: {
58
+ __typename: "DisputeCaseTransactionsOutsideReportingWindowRejection",
59
+ message: "",
60
+ transactions: [{ transactionId: "card-1", reportingWindowEndedAt: "2026-01-01T00:00:00.000Z" }],
61
+ },
62
+ DisputeCaseWrongStatusRejection: {
63
+ __typename: "DisputeCaseWrongStatusRejection",
64
+ message: "",
65
+ disputeCaseId: "case-1",
66
+ currentStatus: "Canceled",
67
+ expectedStatuses: ["Draft"],
68
+ },
69
+ };
70
+ const expectedSteps = {
71
+ AccountMembershipNotFoundRejection: "Victim",
72
+ DisputeCaseDetailsNotApplicableRejection: "Transactions",
73
+ DisputeCaseIncompleteRejection: "Incident",
74
+ DisputeCaseMultipleAccountsRejection: "Transactions",
75
+ DisputeCaseMultipleCardHoldersRejection: "Transactions",
76
+ DisputeCaseNotFoundRejection: "Rejected",
77
+ DisputeCaseTransactionsAlreadyReportedRejection: "Rejected",
78
+ DisputeCaseTransactionsLimitExceededRejection: "Transactions",
79
+ DisputeCaseTransactionsNotFoundRejection: "Transactions",
80
+ DisputeCaseTransactionsNotReportableRejection: "Transactions",
81
+ DisputeCaseTransactionsOutsideReportingWindowRejection: "Rejected",
82
+ DisputeCaseWrongStatusRejection: "Rejected",
83
+ };
84
+ const incomplete = (...paths) => ({
85
+ __typename: "DisputeCaseIncompleteRejection",
86
+ message: "",
87
+ missingFields: paths.map(path => ({ path })),
88
+ });
89
+ const context = {
90
+ detailsSteps: fraudReportDetailsSteps,
91
+ };
92
+ describe("getRejectionStep", () => {
93
+ test.each(Object.values(rejections))("maps $__typename", rejection => {
94
+ expect(getRejectionStep(rejection, context)).toBe(expectedSteps[rejection.__typename]);
95
+ });
96
+ test("shows the submitted screen when the case was submitted elsewhere", () => {
97
+ expect(getRejectionStep({ ...rejections.DisputeCaseWrongStatusRejection, currentStatus: "Submitted" }, context)).toBe("Submitted");
98
+ });
99
+ });
100
+ describe("getRejectionStep: incomplete", () => {
101
+ test.each([
102
+ [["victimAccountMembershipId"], "Victim"],
103
+ [["transactionIds"], "Transactions"],
104
+ [["fraudDetails"], "Incident"],
105
+ [["fraudDetails", "reportedReason"], "Incident"],
106
+ [["fraudDetails", "reportedTypology"], "Incident"],
107
+ [["fraudDetails", "description"], "Incident"],
108
+ [["fraudDetails", "discoveredAt"], "Incident"],
109
+ [["fraudDetails", "discoveryDetails"], "Incident"],
110
+ [["fraudDetails", "fraudsterChannels"], "Fraudster"],
111
+ [["fraudDetails", "sharedInformationWithFraudster"], "Fraudster"],
112
+ [["fraudCardDetails"], "Card"],
113
+ [["fraudCardDetails", "isLostOrStolen"], "Card"],
114
+ [["fraudCardDetails", "lostOrStolenNoticedAt"], "Card"],
115
+ ])("sends a missing %j to %s", (path, step) => {
116
+ expect(getRejectionStep(incomplete(path), context)).toBe(step);
117
+ });
118
+ test("sends several missing fields to the earliest step", () => {
119
+ expect(getRejectionStep(incomplete(["fraudCardDetails"], ["transactionIds"], ["fraudDetails", "fraudsterChannels"]), context)).toBe("Transactions");
120
+ });
121
+ test("picks the earliest step after moving fields out of missing sub-steps", () => {
122
+ expect(getRejectionStep(incomplete(["fraudCardDetails"], ["fraudDetails", "fraudsterChannels"]), {
123
+ ...context,
124
+ detailsSteps: ["Card"],
125
+ })).toBe("Incident");
126
+ });
127
+ test("ignores fields the form can't fix when another one can be fixed", () => {
128
+ expect(getRejectionStep(incomplete(["fraudCardDetails"], ["fraudDetails", "hasFiledPoliceComplaint"]), context)).toBe("Card");
129
+ });
130
+ test("sends fraudster fields to the incident when the flow has no fraudster sub-step", () => {
131
+ expect(getRejectionStep(incomplete(["fraudDetails", "fraudsterChannels"]), {
132
+ ...context,
133
+ detailsSteps: ["Card"],
134
+ })).toBe("Incident");
135
+ });
136
+ test("sends card fields to the transactions when the flow has no card sub-step", () => {
137
+ expect(getRejectionStep(incomplete(["fraudCardDetails"]), {
138
+ ...context,
139
+ detailsSteps: ["Transfer"],
140
+ })).toBe("Transactions");
141
+ });
142
+ test.each([
143
+ [["fraudDetails", "hasFiledPoliceComplaint"]],
144
+ [["fraudCardDetails", "hasContactedMerchant"]],
145
+ [["fraudTransferDetails"]],
146
+ [["fraudTransferDetails", "hasContactedBankOrBeneficiary"]],
147
+ [["externalReference"]],
148
+ [["unknownField"]],
149
+ ])("rejects the report when only %j is missing", path => {
150
+ expect(getRejectionStep(incomplete(path), context)).toBe("Rejected");
151
+ });
152
+ test("rejects the report when no missing field is given", () => {
153
+ expect(getRejectionStep(incomplete(), context)).toBe("Rejected");
154
+ });
155
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { createFakeTransaction } from "../fraudReport/fakeApi";
3
+ import { getResumeStep } from "../fraudReport/resume";
4
+ const card = createFakeTransaction("card-1", "CardOutDebit");
5
+ const transfer = createFakeTransaction("transfer-1", "SepaCreditTransferOut");
6
+ const incident = {
7
+ reportedReason: "Unauthorized",
8
+ reportedTypology: "Other",
9
+ description: "Payments I didn't make",
10
+ };
11
+ describe("getResumeStep", () => {
12
+ test("opens the transactions step when none of the case's transactions is visible", () => {
13
+ expect(getResumeStep({ transactions: [], ...incident })).toBe("Transactions");
14
+ });
15
+ test("opens the transactions step when the draft doesn't hold every start transaction", () => {
16
+ const values = { transactions: [card], ...incident };
17
+ expect(getResumeStep(values, ["card-1", "transfer-1"])).toBe("Transactions");
18
+ expect(getResumeStep(values, ["card-1"])).toBe("Card");
19
+ expect(getResumeStep({ ...values, transactions: [card, transfer] }, ["transfer-1"])).toBe("Card");
20
+ });
21
+ test.each([
22
+ { name: "no answer", values: {} },
23
+ { name: "no reason", values: { ...incident, reportedReason: undefined } },
24
+ { name: "no type of fraud", values: { ...incident, reportedTypology: undefined } },
25
+ { name: "a blank description", values: { ...incident, description: " " } },
26
+ ])("opens the incident step with $name", ({ values }) => {
27
+ expect(getResumeStep({ transactions: [card], ...values })).toBe("Incident");
28
+ });
29
+ test("opens the card sub-step until one of its card answers is given", () => {
30
+ expect(getResumeStep({ transactions: [card], ...incident })).toBe("Card");
31
+ expect(getResumeStep({ transactions: [card], ...incident, isLostOrStolen: false })).toBe("Documents");
32
+ expect(getResumeStep({ transactions: [card], ...incident, hasContactedMerchant: true })).toBe("Documents");
33
+ });
34
+ test("opens the card sub-step when only the police complaint is answered", () => {
35
+ expect(getResumeStep({ transactions: [card], ...incident, hasFiledPoliceComplaint: true })).toBe("Card");
36
+ });
37
+ test("skips the transfer sub-step, which has no answer to give", () => {
38
+ expect(getResumeStep({ transactions: [transfer], ...incident })).toBe("Documents");
39
+ });
40
+ test.each([
41
+ { name: "only the shared information", values: { sharedInformationWithFraudster: ["None"] } },
42
+ { name: "only the channels", values: { fraudsterChannels: ["Phone"] } },
43
+ ])("skips the fraudster sub-step answered with $name", ({ values }) => {
44
+ expect(getResumeStep({
45
+ transactions: [transfer],
46
+ ...incident,
47
+ reportedReason: "Manipulated",
48
+ ...values,
49
+ })).toBe("Documents");
50
+ });
51
+ test.each([
52
+ { name: "no answer", values: {} },
53
+ { name: "empty lists", values: { fraudsterChannels: [], sharedInformationWithFraudster: [] } },
54
+ ])("opens the fraudster sub-step with $name", ({ values }) => {
55
+ expect(getResumeStep({
56
+ transactions: [transfer],
57
+ ...incident,
58
+ reportedReason: "Manipulated",
59
+ ...values,
60
+ })).toBe("Fraudster");
61
+ });
62
+ test("opens the first unanswered sub-step, in the order of the Details sub-steps", () => {
63
+ expect(getResumeStep({ transactions: [transfer, card], ...incident, reportedReason: "Manipulated" })).toBe("Card");
64
+ expect(getResumeStep({
65
+ transactions: [transfer, card],
66
+ ...incident,
67
+ reportedReason: "Manipulated",
68
+ isLostOrStolen: true,
69
+ })).toBe("Fraudster");
70
+ });
71
+ test("opens the documents step when every step is answered", () => {
72
+ expect(getResumeStep({
73
+ transactions: [transfer, card],
74
+ ...incident,
75
+ reportedReason: "Manipulated",
76
+ isLostOrStolen: true,
77
+ fraudsterChannels: ["Phone"],
78
+ sharedInformationWithFraudster: ["None"],
79
+ })).toBe("Documents");
80
+ });
81
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,102 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { getDetailsSteps, getFraudReportStepper } from "../fraudReport/stepper";
3
+ const getLabel = (step) => step.toUpperCase();
4
+ const card = { rail: "Card" };
5
+ const transfer = { rail: "Transfer" };
6
+ describe("getDetailsSteps", () => {
7
+ test.each([
8
+ { name: "nothing selected", transactions: [], reportedReason: undefined, steps: [] },
9
+ { name: "a card", transactions: [card], reportedReason: "Unauthorized", steps: ["Card"] },
10
+ {
11
+ name: "a transfer",
12
+ transactions: [transfer],
13
+ reportedReason: "Unauthorized",
14
+ steps: ["Transfer"],
15
+ },
16
+ {
17
+ name: "a transfer, with a fraudster",
18
+ transactions: [transfer],
19
+ reportedReason: "Manipulated",
20
+ steps: ["Transfer", "Fraudster"],
21
+ },
22
+ {
23
+ name: "a transfer and a card, with a fraudster",
24
+ transactions: [transfer, card],
25
+ reportedReason: "Manipulated",
26
+ steps: ["Card", "Transfer", "Fraudster"],
27
+ },
28
+ ])("goes through $steps for $name", ({ transactions, reportedReason, steps }) => {
29
+ expect(getDetailsSteps({ transactions: [...transactions], reportedReason })).toEqual(steps);
30
+ });
31
+ });
32
+ describe("getFraudReportStepper", () => {
33
+ test("lists the six steps, with one bar per Details sub-step", () => {
34
+ const stepper = getFraudReportStepper({
35
+ activeStep: "Victim",
36
+ detailsSteps: ["Card", "Transfer"],
37
+ getLabel,
38
+ });
39
+ expect(stepper.steps).toEqual([
40
+ { id: "Victim", label: "VICTIM" },
41
+ { id: "Transactions", label: "TRANSACTIONS" },
42
+ { id: "Incident", label: "INCIDENT" },
43
+ {
44
+ label: "DETAILS",
45
+ children: [
46
+ { id: "Card", label: "DETAILS" },
47
+ { id: "Transfer", label: "DETAILS" },
48
+ ],
49
+ },
50
+ { id: "Documents", label: "DOCUMENTS" },
51
+ { id: "Submitted", label: "SUBMITTED" },
52
+ ]);
53
+ });
54
+ test("draws Details as a single step when there is no sub-step", () => {
55
+ const stepper = getFraudReportStepper({ activeStep: "Victim", detailsSteps: [], getLabel });
56
+ expect(stepper.steps[3]).toEqual({ id: "Details", label: "DETAILS" });
57
+ });
58
+ test("orders the sub-steps for display and drops duplicates", () => {
59
+ const stepper = getFraudReportStepper({
60
+ activeStep: "Victim",
61
+ detailsSteps: ["Fraudster", "Card", "Card"],
62
+ getLabel,
63
+ });
64
+ expect(stepper.steps[3]).toEqual({
65
+ label: "DETAILS",
66
+ children: [
67
+ { id: "Card", label: "DETAILS" },
68
+ { id: "Fraudster", label: "DETAILS" },
69
+ ],
70
+ });
71
+ });
72
+ test("adds the active sub-step when the list misses it", () => {
73
+ const stepper = getFraudReportStepper({
74
+ activeStep: "Card",
75
+ detailsSteps: ["Transfer", "Fraudster"],
76
+ getLabel,
77
+ });
78
+ expect(stepper.steps[3]).toEqual({
79
+ label: "DETAILS",
80
+ children: [
81
+ { id: "Card", label: "DETAILS" },
82
+ { id: "Transfer", label: "DETAILS" },
83
+ { id: "Fraudster", label: "DETAILS" },
84
+ ],
85
+ });
86
+ });
87
+ test.each([
88
+ { activeStep: "Victim" },
89
+ { activeStep: "Incident" },
90
+ { activeStep: "Card" },
91
+ { activeStep: "Transfer" },
92
+ { activeStep: "Documents" },
93
+ { activeStep: "Submitted" },
94
+ ])("makes $activeStep the active step", ({ activeStep }) => {
95
+ const stepper = getFraudReportStepper({
96
+ activeStep,
97
+ detailsSteps: ["Card", "Transfer"],
98
+ getLabel,
99
+ });
100
+ expect(stepper.activeStepId).toBe(activeStep);
101
+ });
102
+ });