@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.
- package/package.json +3 -3
- package/src/components/FraudReport/FraudReportLayout.d.ts +23 -0
- package/src/components/FraudReport/FraudReportLayout.js +35 -0
- package/src/components/FraudReport/IncidentStep.d.ts +7 -0
- package/src/components/FraudReport/IncidentStep.js +55 -0
- package/src/components/FraudReport/IntroStep.d.ts +5 -0
- package/src/components/FraudReport/IntroStep.js +28 -0
- package/src/components/FraudReport/TransactionsStep.d.ts +16 -0
- package/src/components/FraudReport/TransactionsStep.js +138 -0
- package/src/components/FraudReport/VictimStep.d.ts +9 -0
- package/src/components/FraudReport/VictimStep.js +55 -0
- package/src/components/InlineDatePicker.js +7 -6
- package/src/constants/__tests__/countries.test.js +32 -1
- package/src/constants/countries.d.ts +2 -1
- package/src/constants/countries.js +36 -2
- package/src/hooks/__tests__/useFraudReportFlow.test.d.ts +1 -0
- package/src/hooks/__tests__/useFraudReportFlow.test.js +979 -0
- package/src/hooks/useFraudReportFlow.d.ts +32 -0
- package/src/hooks/useFraudReportFlow.js +260 -0
- package/src/locales/de.json +76 -0
- package/src/locales/en.json +76 -0
- package/src/locales/es.json +76 -0
- package/src/locales/fi.json +76 -0
- package/src/locales/fr.json +76 -0
- package/src/locales/it.json +76 -0
- package/src/locales/nl.json +76 -0
- package/src/locales/pt.json +76 -0
- package/src/utils/__tests__/fraudReport.fakeApi.test.js +42 -13
- package/src/utils/__tests__/fraudReport.prefill.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.prefill.test.js +149 -0
- package/src/utils/__tests__/fraudReport.rejections.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.rejections.test.js +163 -0
- package/src/utils/__tests__/fraudReport.resume.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.resume.test.js +67 -0
- package/src/utils/__tests__/fraudReport.stepper.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.stepper.test.js +102 -0
- package/src/utils/__tests__/fraudReport.toInput.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.toInput.test.js +549 -0
- package/src/utils/__tests__/fraudReport.transactions.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.transactions.test.js +28 -0
- package/src/utils/__tests__/fraudReport.types.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.types.test.js +22 -0
- package/src/utils/__tests__/fraudReport.victim.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.victim.test.js +142 -0
- package/src/utils/__tests__/phone.test.js +60 -5
- package/src/utils/fraudReport/fakeApi.d.ts +7 -4
- package/src/utils/fraudReport/fakeApi.js +18 -5
- package/src/utils/fraudReport/prefill.d.ts +3 -0
- package/src/utils/fraudReport/prefill.js +14 -0
- package/src/utils/fraudReport/rail.d.ts +5 -0
- package/src/utils/fraudReport/rail.js +14 -0
- package/src/utils/fraudReport/rejections.d.ts +10 -0
- package/src/utils/fraudReport/rejections.js +53 -0
- package/src/utils/fraudReport/resume.d.ts +4 -0
- package/src/utils/fraudReport/resume.js +26 -0
- package/src/utils/fraudReport/stepper.d.ts +16 -0
- package/src/utils/fraudReport/stepper.js +21 -0
- package/src/utils/fraudReport/toInput.d.ts +30 -0
- package/src/utils/fraudReport/toInput.js +82 -0
- package/src/utils/fraudReport/transactions.d.ts +6 -0
- package/src/utils/fraudReport/transactions.js +7 -0
- package/src/utils/fraudReport/types.d.ts +8 -0
- package/src/utils/fraudReport/validation.d.ts +15 -0
- package/src/utils/fraudReport/validation.js +55 -0
- package/src/utils/fraudReport/victim.d.ts +30 -0
- package/src/utils/fraudReport/victim.js +28 -0
- package/src/utils/phone.d.ts +1 -0
- package/src/utils/phone.js +31 -4
|
@@ -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
|
-
|
|
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 = {
|
|
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: [
|
|
351
|
+
transactions: [createFakeTransaction("transfer-3", "SepaCreditTransferOut")],
|
|
325
352
|
};
|
|
326
353
|
const outsideCase = {
|
|
327
354
|
...seeded,
|
|
328
355
|
id: "case-2",
|
|
329
|
-
transactions: [
|
|
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: [
|
|
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: [
|
|
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
|
-
|
|
488
|
-
|
|
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
|
-
|
|
549
|
-
|
|
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
|
-
|
|
557
|
-
|
|
585
|
+
createFakeTransaction("transfer-3", "SepaCreditTransferOut"),
|
|
586
|
+
createFakeTransaction("transfer-4", "SepaCreditTransferOut"),
|
|
558
587
|
],
|
|
559
588
|
},
|
|
560
589
|
],
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
savedCase,
|
|
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
|
+
isLostOrStolen: true,
|
|
65
|
+
lostOrStolenNoticedAt: "2026-11-19",
|
|
66
|
+
externalReference: "ref-42",
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
test("leaves every field empty on a draft with only transactions", () => {
|
|
70
|
+
expect(toFormValues(draft({ transactions: [card1] }))).toEqual({ transactions: [card1] });
|
|
71
|
+
});
|
|
72
|
+
test("leaves the missing fields empty on a partial draft", () => {
|
|
73
|
+
expect(toFormValues(draft({
|
|
74
|
+
transactions: [card1],
|
|
75
|
+
fraudDetails: {
|
|
76
|
+
...fraudDetails,
|
|
77
|
+
discoveredAt: null,
|
|
78
|
+
discoveryDetails: null,
|
|
79
|
+
fraudsterChannels: [],
|
|
80
|
+
sharedInformationWithFraudster: [],
|
|
81
|
+
hasFiledPoliceComplaint: null,
|
|
82
|
+
},
|
|
83
|
+
fraudCardDetails: {
|
|
84
|
+
isLostOrStolen: false,
|
|
85
|
+
lostOrStolenNoticedAt: null,
|
|
86
|
+
hasContactedMerchant: null,
|
|
87
|
+
},
|
|
88
|
+
}))).toEqual({
|
|
89
|
+
transactions: [card1],
|
|
90
|
+
reportedReason: "Manipulated",
|
|
91
|
+
reportedTypology: "FakeAdvisor",
|
|
92
|
+
description: "A fake advisor called me",
|
|
93
|
+
fraudsterChannels: [],
|
|
94
|
+
sharedInformationWithFraudster: [],
|
|
95
|
+
isLostOrStolen: false,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
test("gives no victim when the case has none to show", () => {
|
|
99
|
+
expect(toFormValues(draft({ transactions: [transfer1], hasVictim: true })).victimAccountMembershipId).toBeUndefined();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe("toFormValues then toUpdateInput", () => {
|
|
103
|
+
test("sends back the stored details of a card-only draft", () => {
|
|
104
|
+
expect(roundTrip(draft({ transactions: [card1], fraudDetails, fraudCardDetails }))).toEqual({
|
|
105
|
+
disputeCaseId: "case-1",
|
|
106
|
+
fraudDetails,
|
|
107
|
+
fraudCardDetails,
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
test("sends back the stored details and victim of a transfer-only draft", () => {
|
|
111
|
+
expect(roundTrip(draft({
|
|
112
|
+
transactions: [transfer1],
|
|
113
|
+
fraudDetails,
|
|
114
|
+
victimAccountMembershipId: "membership-2",
|
|
115
|
+
hasVictim: true,
|
|
116
|
+
externalReference: "ref-42",
|
|
117
|
+
}))).toEqual({
|
|
118
|
+
disputeCaseId: "case-1",
|
|
119
|
+
fraudDetails,
|
|
120
|
+
victimAccountMembershipId: "membership-2",
|
|
121
|
+
externalReference: "ref-42",
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
test("sends back the stored details of a mixed draft", () => {
|
|
125
|
+
expect(roundTrip(fullDraft)).toEqual({
|
|
126
|
+
disputeCaseId: "case-1",
|
|
127
|
+
fraudDetails,
|
|
128
|
+
fraudCardDetails,
|
|
129
|
+
externalReference: "ref-42",
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
test("keeps the stored victim when the caller can't see it", () => {
|
|
133
|
+
expect(roundTrip(draft({ transactions: [transfer1], fraudDetails, hasVictim: true }))).toEqual({
|
|
134
|
+
disputeCaseId: "case-1",
|
|
135
|
+
fraudDetails,
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
test("sends empty fraudster lists back as null", () => {
|
|
139
|
+
const savedCase = draft({
|
|
140
|
+
transactions: [transfer1],
|
|
141
|
+
fraudDetails: { ...fraudDetails, fraudsterChannels: [], sharedInformationWithFraudster: [] },
|
|
142
|
+
});
|
|
143
|
+
expect(roundTrip(savedCase).fraudDetails).toEqual({
|
|
144
|
+
...fraudDetails,
|
|
145
|
+
fraudsterChannels: null,
|
|
146
|
+
sharedInformationWithFraudster: null,
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,163 @@
|
|
|
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 beforeDraft = {
|
|
90
|
+
hasDraft: false,
|
|
91
|
+
detailsSteps: fraudReportDetailsSteps,
|
|
92
|
+
};
|
|
93
|
+
const afterDraft = { ...beforeDraft, hasDraft: true };
|
|
94
|
+
describe("getRejectionStep", () => {
|
|
95
|
+
test.each(Object.values(rejections))("maps $__typename", rejection => {
|
|
96
|
+
expect(getRejectionStep(rejection, beforeDraft)).toBe(expectedSteps[rejection.__typename]);
|
|
97
|
+
});
|
|
98
|
+
test("shows the submitted screen when the case was submitted elsewhere", () => {
|
|
99
|
+
expect(getRejectionStep({ ...rejections.DisputeCaseWrongStatusRejection, currentStatus: "Submitted" }, afterDraft)).toBe("Submitted");
|
|
100
|
+
});
|
|
101
|
+
test("rejects the report when the victim isn't found once the draft exists", () => {
|
|
102
|
+
expect(getRejectionStep(rejections.AccountMembershipNotFoundRejection, afterDraft)).toBe("Rejected");
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe("getRejectionStep: incomplete", () => {
|
|
106
|
+
test.each([
|
|
107
|
+
[["victimAccountMembershipId"], "Victim"],
|
|
108
|
+
[["transactionIds"], "Transactions"],
|
|
109
|
+
[["fraudDetails"], "Incident"],
|
|
110
|
+
[["fraudDetails", "reportedReason"], "Incident"],
|
|
111
|
+
[["fraudDetails", "reportedTypology"], "Incident"],
|
|
112
|
+
[["fraudDetails", "description"], "Incident"],
|
|
113
|
+
[["fraudDetails", "discoveredAt"], "Incident"],
|
|
114
|
+
[["fraudDetails", "discoveryDetails"], "Incident"],
|
|
115
|
+
[["fraudDetails", "fraudsterChannels"], "Fraudster"],
|
|
116
|
+
[["fraudDetails", "sharedInformationWithFraudster"], "Fraudster"],
|
|
117
|
+
[["fraudCardDetails"], "Card"],
|
|
118
|
+
[["fraudCardDetails", "isLostOrStolen"], "Card"],
|
|
119
|
+
[["fraudCardDetails", "lostOrStolenNoticedAt"], "Card"],
|
|
120
|
+
])("sends a missing %j to %s", (path, step) => {
|
|
121
|
+
expect(getRejectionStep(incomplete(path), beforeDraft)).toBe(step);
|
|
122
|
+
});
|
|
123
|
+
test("sends several missing fields to the earliest step", () => {
|
|
124
|
+
expect(getRejectionStep(incomplete(["fraudCardDetails"], ["transactionIds"], ["fraudDetails", "fraudsterChannels"]), afterDraft)).toBe("Transactions");
|
|
125
|
+
});
|
|
126
|
+
test("picks the earliest step after moving fields out of missing sub-steps", () => {
|
|
127
|
+
expect(getRejectionStep(incomplete(["fraudCardDetails"], ["fraudDetails", "fraudsterChannels"]), {
|
|
128
|
+
...afterDraft,
|
|
129
|
+
detailsSteps: ["Card"],
|
|
130
|
+
})).toBe("Incident");
|
|
131
|
+
});
|
|
132
|
+
test("ignores fields the form can't fix when another one can be fixed", () => {
|
|
133
|
+
expect(getRejectionStep(incomplete(["victimAccountMembershipId"], ["fraudCardDetails"], ["fraudDetails", "hasFiledPoliceComplaint"]), afterDraft)).toBe("Card");
|
|
134
|
+
});
|
|
135
|
+
test("rejects the report when the victim is missing once the draft exists", () => {
|
|
136
|
+
expect(getRejectionStep(incomplete(["victimAccountMembershipId"]), afterDraft)).toBe("Rejected");
|
|
137
|
+
});
|
|
138
|
+
test("sends fraudster fields to the incident when the flow has no fraudster sub-step", () => {
|
|
139
|
+
expect(getRejectionStep(incomplete(["fraudDetails", "fraudsterChannels"]), {
|
|
140
|
+
...afterDraft,
|
|
141
|
+
detailsSteps: ["Card"],
|
|
142
|
+
})).toBe("Incident");
|
|
143
|
+
});
|
|
144
|
+
test("sends card fields to the transactions when the flow has no card sub-step", () => {
|
|
145
|
+
expect(getRejectionStep(incomplete(["fraudCardDetails"]), {
|
|
146
|
+
...afterDraft,
|
|
147
|
+
detailsSteps: ["Transfer"],
|
|
148
|
+
})).toBe("Transactions");
|
|
149
|
+
});
|
|
150
|
+
test.each([
|
|
151
|
+
[["fraudDetails", "hasFiledPoliceComplaint"]],
|
|
152
|
+
[["fraudCardDetails", "hasContactedMerchant"]],
|
|
153
|
+
[["fraudTransferDetails"]],
|
|
154
|
+
[["fraudTransferDetails", "hasContactedBankOrBeneficiary"]],
|
|
155
|
+
[["externalReference"]],
|
|
156
|
+
[["unknownField"]],
|
|
157
|
+
])("rejects the report when only %j is missing", path => {
|
|
158
|
+
expect(getRejectionStep(incomplete(path), afterDraft)).toBe("Rejected");
|
|
159
|
+
});
|
|
160
|
+
test("rejects the report when no missing field is given", () => {
|
|
161
|
+
expect(getRejectionStep(incomplete(), afterDraft)).toBe("Rejected");
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
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 lost or stolen is answered", () => {
|
|
30
|
+
expect(getResumeStep({ transactions: [card], ...incident })).toBe("Card");
|
|
31
|
+
expect(getResumeStep({ transactions: [card], ...incident, isLostOrStolen: false })).toBe("Documents");
|
|
32
|
+
});
|
|
33
|
+
test("skips the transfer sub-step, which has no answer to give", () => {
|
|
34
|
+
expect(getResumeStep({ transactions: [transfer], ...incident })).toBe("Documents");
|
|
35
|
+
});
|
|
36
|
+
test.each([
|
|
37
|
+
{ name: "no channel", values: { sharedInformationWithFraudster: ["None"] } },
|
|
38
|
+
{ name: "nothing shared", values: { fraudsterChannels: ["Phone"] } },
|
|
39
|
+
{ name: "empty lists", values: { fraudsterChannels: [], sharedInformationWithFraudster: [] } },
|
|
40
|
+
])("opens the fraudster sub-step with $name", ({ values }) => {
|
|
41
|
+
expect(getResumeStep({
|
|
42
|
+
transactions: [transfer],
|
|
43
|
+
...incident,
|
|
44
|
+
reportedReason: "Manipulated",
|
|
45
|
+
...values,
|
|
46
|
+
})).toBe("Fraudster");
|
|
47
|
+
});
|
|
48
|
+
test("opens the first unanswered sub-step, in the order of the Details sub-steps", () => {
|
|
49
|
+
expect(getResumeStep({ transactions: [transfer, card], ...incident, reportedReason: "Manipulated" })).toBe("Card");
|
|
50
|
+
expect(getResumeStep({
|
|
51
|
+
transactions: [transfer, card],
|
|
52
|
+
...incident,
|
|
53
|
+
reportedReason: "Manipulated",
|
|
54
|
+
isLostOrStolen: true,
|
|
55
|
+
})).toBe("Fraudster");
|
|
56
|
+
});
|
|
57
|
+
test("opens the documents step when every step is answered", () => {
|
|
58
|
+
expect(getResumeStep({
|
|
59
|
+
transactions: [transfer, card],
|
|
60
|
+
...incident,
|
|
61
|
+
reportedReason: "Manipulated",
|
|
62
|
+
isLostOrStolen: true,
|
|
63
|
+
fraudsterChannels: ["Phone"],
|
|
64
|
+
sharedInformationWithFraudster: ["None"],
|
|
65
|
+
})).toBe("Documents");
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|