@swan-io/shared-business 18.5.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.
- package/package.json +3 -3
- package/src/components/BirthdatePicker.d.ts +3 -1
- package/src/components/BirthdatePicker.js +2 -2
- package/src/components/FraudReport/CardDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/CardDetailsStep.js +46 -0
- package/src/components/FraudReport/FraudsterDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/FraudsterDetailsStep.js +56 -0
- package/src/components/FraudReport/IntroStep.js +5 -1
- package/src/components/FraudReport/TransactionPicker.d.ts +13 -0
- package/src/components/FraudReport/TransactionPicker.js +213 -0
- package/src/components/FraudReport/TransactionPickerFilters.d.ts +8 -0
- package/src/components/FraudReport/TransactionPickerFilters.js +213 -0
- package/src/components/FraudReport/TransactionRows.d.ts +8 -0
- package/src/components/FraudReport/TransactionRows.js +32 -0
- package/src/components/FraudReport/TransactionsStep.js +9 -27
- package/src/components/FraudReport/VictimStep.d.ts +3 -1
- package/src/components/FraudReport/VictimStep.js +38 -5
- package/src/components/LakeModal.js +1 -1
- package/src/hooks/__tests__/useFraudReportFlow.test.js +108 -20
- package/src/hooks/useFraudReportFlow.js +12 -7
- package/src/locales/de.json +62 -8
- package/src/locales/en.json +55 -1
- package/src/locales/es.json +55 -1
- package/src/locales/fi.json +55 -1
- package/src/locales/fr.json +55 -1
- package/src/locales/it.json +55 -1
- package/src/locales/nl.json +55 -1
- package/src/locales/pt.json +55 -1
- package/src/utils/__tests__/fraudReport.card.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.card.test.js +39 -0
- package/src/utils/__tests__/fraudReport.fraudster.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.fraudster.test.js +35 -0
- package/src/utils/__tests__/fraudReport.messages.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.messages.test.js +28 -0
- package/src/utils/__tests__/fraudReport.picker.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.picker.test.js +171 -0
- package/src/utils/__tests__/fraudReport.pickerFilters.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.pickerFilters.test.js +144 -0
- package/src/utils/__tests__/fraudReport.prefill.test.js +3 -1
- package/src/utils/__tests__/fraudReport.rejections.test.js +11 -19
- package/src/utils/__tests__/fraudReport.resume.test.js +17 -3
- package/src/utils/__tests__/fraudReport.toInput.test.js +84 -30
- package/src/utils/__tests__/fraudReport.transactions.test.js +11 -1
- package/src/utils/__tests__/fraudReport.victim.test.js +27 -1
- package/src/utils/__tests__/validation.test.js +69 -2
- package/src/utils/fraudReport/card.d.ts +11 -0
- package/src/utils/fraudReport/card.js +15 -0
- package/src/utils/fraudReport/fakeApi.js +1 -1
- package/src/utils/fraudReport/fraudster.d.ts +10 -0
- package/src/utils/fraudReport/fraudster.js +11 -0
- package/src/utils/fraudReport/messages.d.ts +4 -0
- package/src/utils/fraudReport/messages.js +7 -0
- package/src/utils/fraudReport/picker.d.ts +18 -0
- package/src/utils/fraudReport/picker.js +49 -0
- package/src/utils/fraudReport/pickerFilters.d.ts +26 -0
- package/src/utils/fraudReport/pickerFilters.js +62 -0
- package/src/utils/fraudReport/prefill.js +5 -3
- package/src/utils/fraudReport/rejections.d.ts +0 -1
- package/src/utils/fraudReport/rejections.js +2 -6
- package/src/utils/fraudReport/resume.js +3 -3
- package/src/utils/fraudReport/toInput.d.ts +5 -3
- package/src/utils/fraudReport/toInput.js +20 -22
- package/src/utils/fraudReport/transactions.d.ts +2 -0
- package/src/utils/fraudReport/transactions.js +4 -0
- package/src/utils/fraudReport/validation.d.ts +1 -1
- package/src/utils/fraudReport/validation.js +4 -0
- package/src/utils/fraudReport/victim.d.ts +11 -0
- package/src/utils/fraudReport/victim.js +9 -0
- package/src/utils/validation.d.ts +2 -0
- package/src/utils/validation.js +14 -7
|
@@ -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
|
+
});
|
|
@@ -45,7 +45,7 @@ const fullDraft = draft({
|
|
|
45
45
|
externalReference: "ref-42",
|
|
46
46
|
});
|
|
47
47
|
const roundTrip = (savedCase) => toUpdateInput({
|
|
48
|
-
savedCase,
|
|
48
|
+
disputeCaseId: savedCase.id,
|
|
49
49
|
values: toFormValues(savedCase),
|
|
50
50
|
savedTransactionIds: savedCase.transactions.map(({ id }) => id),
|
|
51
51
|
});
|
|
@@ -61,8 +61,10 @@ describe("toFormValues", () => {
|
|
|
61
61
|
discoveryDetails: "My bank app showed a payment I didn't make",
|
|
62
62
|
fraudsterChannels: ["Phone"],
|
|
63
63
|
sharedInformationWithFraudster: ["VerificationCode"],
|
|
64
|
+
hasFiledPoliceComplaint: true,
|
|
64
65
|
isLostOrStolen: true,
|
|
65
66
|
lostOrStolenNoticedAt: "2026-11-19",
|
|
67
|
+
hasContactedMerchant: false,
|
|
66
68
|
externalReference: "ref-42",
|
|
67
69
|
});
|
|
68
70
|
});
|
|
@@ -86,20 +86,15 @@ const incomplete = (...paths) => ({
|
|
|
86
86
|
message: "",
|
|
87
87
|
missingFields: paths.map(path => ({ path })),
|
|
88
88
|
});
|
|
89
|
-
const
|
|
90
|
-
hasDraft: false,
|
|
89
|
+
const context = {
|
|
91
90
|
detailsSteps: fraudReportDetailsSteps,
|
|
92
91
|
};
|
|
93
|
-
const afterDraft = { ...beforeDraft, hasDraft: true };
|
|
94
92
|
describe("getRejectionStep", () => {
|
|
95
93
|
test.each(Object.values(rejections))("maps $__typename", rejection => {
|
|
96
|
-
expect(getRejectionStep(rejection,
|
|
94
|
+
expect(getRejectionStep(rejection, context)).toBe(expectedSteps[rejection.__typename]);
|
|
97
95
|
});
|
|
98
96
|
test("shows the submitted screen when the case was submitted elsewhere", () => {
|
|
99
|
-
expect(getRejectionStep({ ...rejections.DisputeCaseWrongStatusRejection, currentStatus: "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");
|
|
97
|
+
expect(getRejectionStep({ ...rejections.DisputeCaseWrongStatusRejection, currentStatus: "Submitted" }, context)).toBe("Submitted");
|
|
103
98
|
});
|
|
104
99
|
});
|
|
105
100
|
describe("getRejectionStep: incomplete", () => {
|
|
@@ -118,32 +113,29 @@ describe("getRejectionStep: incomplete", () => {
|
|
|
118
113
|
[["fraudCardDetails", "isLostOrStolen"], "Card"],
|
|
119
114
|
[["fraudCardDetails", "lostOrStolenNoticedAt"], "Card"],
|
|
120
115
|
])("sends a missing %j to %s", (path, step) => {
|
|
121
|
-
expect(getRejectionStep(incomplete(path),
|
|
116
|
+
expect(getRejectionStep(incomplete(path), context)).toBe(step);
|
|
122
117
|
});
|
|
123
118
|
test("sends several missing fields to the earliest step", () => {
|
|
124
|
-
expect(getRejectionStep(incomplete(["fraudCardDetails"], ["transactionIds"], ["fraudDetails", "fraudsterChannels"]),
|
|
119
|
+
expect(getRejectionStep(incomplete(["fraudCardDetails"], ["transactionIds"], ["fraudDetails", "fraudsterChannels"]), context)).toBe("Transactions");
|
|
125
120
|
});
|
|
126
121
|
test("picks the earliest step after moving fields out of missing sub-steps", () => {
|
|
127
122
|
expect(getRejectionStep(incomplete(["fraudCardDetails"], ["fraudDetails", "fraudsterChannels"]), {
|
|
128
|
-
...
|
|
123
|
+
...context,
|
|
129
124
|
detailsSteps: ["Card"],
|
|
130
125
|
})).toBe("Incident");
|
|
131
126
|
});
|
|
132
127
|
test("ignores fields the form can't fix when another one can be fixed", () => {
|
|
133
|
-
expect(getRejectionStep(incomplete(["
|
|
134
|
-
});
|
|
135
|
-
test("rejects the report when the victim is missing once the draft exists", () => {
|
|
136
|
-
expect(getRejectionStep(incomplete(["victimAccountMembershipId"]), afterDraft)).toBe("Rejected");
|
|
128
|
+
expect(getRejectionStep(incomplete(["fraudCardDetails"], ["fraudDetails", "hasFiledPoliceComplaint"]), context)).toBe("Card");
|
|
137
129
|
});
|
|
138
130
|
test("sends fraudster fields to the incident when the flow has no fraudster sub-step", () => {
|
|
139
131
|
expect(getRejectionStep(incomplete(["fraudDetails", "fraudsterChannels"]), {
|
|
140
|
-
...
|
|
132
|
+
...context,
|
|
141
133
|
detailsSteps: ["Card"],
|
|
142
134
|
})).toBe("Incident");
|
|
143
135
|
});
|
|
144
136
|
test("sends card fields to the transactions when the flow has no card sub-step", () => {
|
|
145
137
|
expect(getRejectionStep(incomplete(["fraudCardDetails"]), {
|
|
146
|
-
...
|
|
138
|
+
...context,
|
|
147
139
|
detailsSteps: ["Transfer"],
|
|
148
140
|
})).toBe("Transactions");
|
|
149
141
|
});
|
|
@@ -155,9 +147,9 @@ describe("getRejectionStep: incomplete", () => {
|
|
|
155
147
|
[["externalReference"]],
|
|
156
148
|
[["unknownField"]],
|
|
157
149
|
])("rejects the report when only %j is missing", path => {
|
|
158
|
-
expect(getRejectionStep(incomplete(path),
|
|
150
|
+
expect(getRejectionStep(incomplete(path), context)).toBe("Rejected");
|
|
159
151
|
});
|
|
160
152
|
test("rejects the report when no missing field is given", () => {
|
|
161
|
-
expect(getRejectionStep(incomplete(),
|
|
153
|
+
expect(getRejectionStep(incomplete(), context)).toBe("Rejected");
|
|
162
154
|
});
|
|
163
155
|
});
|
|
@@ -26,16 +26,30 @@ describe("getResumeStep", () => {
|
|
|
26
26
|
])("opens the incident step with $name", ({ values }) => {
|
|
27
27
|
expect(getResumeStep({ transactions: [card], ...values })).toBe("Incident");
|
|
28
28
|
});
|
|
29
|
-
test("opens the card sub-step until
|
|
29
|
+
test("opens the card sub-step until one of its card answers is given", () => {
|
|
30
30
|
expect(getResumeStep({ transactions: [card], ...incident })).toBe("Card");
|
|
31
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");
|
|
32
36
|
});
|
|
33
37
|
test("skips the transfer sub-step, which has no answer to give", () => {
|
|
34
38
|
expect(getResumeStep({ transactions: [transfer], ...incident })).toBe("Documents");
|
|
35
39
|
});
|
|
36
40
|
test.each([
|
|
37
|
-
{ name: "
|
|
38
|
-
{ name: "
|
|
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: {} },
|
|
39
53
|
{ name: "empty lists", values: { fraudsterChannels: [], sharedInformationWithFraudster: [] } },
|
|
40
54
|
])("opens the fraudster sub-step with $name", ({ values }) => {
|
|
41
55
|
expect(getResumeStep({
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Option } from "@bloodyowl/boxed";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
3
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";
|
|
7
|
+
import { MAX_TRANSACTIONS } from "../fraudReport/transactions";
|
|
6
8
|
import { validateDescription, validateDiscoveryDetails, validateExternalReference, validateNotInFuture, validateSelected, validateSharedInformation, validateTransactionIds, } from "../fraudReport/validation";
|
|
7
9
|
const card1 = createFakeTransaction("card-1", "CardOutDebit");
|
|
8
10
|
const card2 = createFakeTransaction("card-2", "CardOutDebit");
|
|
@@ -91,6 +93,11 @@ 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
|
+
});
|
|
94
101
|
});
|
|
95
102
|
describe("validateSelected", () => {
|
|
96
103
|
test("requires a value", () => {
|
|
@@ -326,6 +333,21 @@ describe("toDraftInput", () => {
|
|
|
326
333
|
expect(toDraftInput({ ...incident, transactions: [card1] })).not.toHaveProperty("fraudCardDetails");
|
|
327
334
|
expect(toDraftInput({ ...incident, lostOrStolenNoticedAt: "", transactions: [card1] })).not.toHaveProperty("fraudCardDetails");
|
|
328
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
|
+
});
|
|
329
351
|
test("sends null for the card detail left empty", () => {
|
|
330
352
|
expect(toDraftInput({ isLostOrStolen: false, transactions: [card1] }).fraudCardDetails).toStrictEqual({
|
|
331
353
|
isLostOrStolen: false,
|
|
@@ -345,11 +367,11 @@ describe("toDraftInput", () => {
|
|
|
345
367
|
});
|
|
346
368
|
});
|
|
347
369
|
describe("toUpdateInput", () => {
|
|
348
|
-
const savedCase = { id: "case-1"
|
|
370
|
+
const savedCase = { id: "case-1" };
|
|
349
371
|
const disputeCaseId = savedCase.id;
|
|
350
372
|
test("sends the card details and no victim on a card-only case", () => {
|
|
351
373
|
expect(toUpdateInput({
|
|
352
|
-
savedCase,
|
|
374
|
+
disputeCaseId: savedCase.id,
|
|
353
375
|
values: { ...filled, transactions: [card1, card2] },
|
|
354
376
|
savedTransactionIds: ["card-1"],
|
|
355
377
|
})).toStrictEqual({
|
|
@@ -362,7 +384,7 @@ describe("toUpdateInput", () => {
|
|
|
362
384
|
});
|
|
363
385
|
test("sends the victim and no card details on a transfer-only case", () => {
|
|
364
386
|
expect(toUpdateInput({
|
|
365
|
-
savedCase,
|
|
387
|
+
disputeCaseId: savedCase.id,
|
|
366
388
|
values: { ...filled, transactions: [transfer1] },
|
|
367
389
|
savedTransactionIds: ["transfer-1", "card-1"],
|
|
368
390
|
})).toStrictEqual({
|
|
@@ -375,7 +397,7 @@ describe("toUpdateInput", () => {
|
|
|
375
397
|
});
|
|
376
398
|
test("sends the card details and no victim on a mixed case", () => {
|
|
377
399
|
expect(toUpdateInput({
|
|
378
|
-
savedCase,
|
|
400
|
+
disputeCaseId: savedCase.id,
|
|
379
401
|
values: { ...filled, transactions: [transfer1, card1] },
|
|
380
402
|
savedTransactionIds: ["transfer-1"],
|
|
381
403
|
})).toStrictEqual({
|
|
@@ -388,14 +410,14 @@ describe("toUpdateInput", () => {
|
|
|
388
410
|
});
|
|
389
411
|
test("never sends transfer details", () => {
|
|
390
412
|
expect(toUpdateInput({
|
|
391
|
-
savedCase,
|
|
413
|
+
disputeCaseId: savedCase.id,
|
|
392
414
|
values: { ...filled, transactions: [transfer1] },
|
|
393
415
|
savedTransactionIds: [],
|
|
394
416
|
})).not.toHaveProperty("fraudTransferDetails");
|
|
395
417
|
});
|
|
396
418
|
test("clears the fraudster answers once no fraudster convinced the user", () => {
|
|
397
419
|
expect(toUpdateInput({
|
|
398
|
-
savedCase,
|
|
420
|
+
disputeCaseId: savedCase.id,
|
|
399
421
|
values: { ...filled, reportedReason: "Unauthorized", transactions: [card1] },
|
|
400
422
|
savedTransactionIds: ["card-1"],
|
|
401
423
|
}).fraudDetails).toStrictEqual({
|
|
@@ -407,10 +429,14 @@ describe("toUpdateInput", () => {
|
|
|
407
429
|
});
|
|
408
430
|
test("leaves the transaction IDs out when the selection didn't change", () => {
|
|
409
431
|
expect(toUpdateInput({
|
|
410
|
-
savedCase,
|
|
432
|
+
disputeCaseId: savedCase.id,
|
|
411
433
|
values: { ...incident, transactions: [card1, transfer1] },
|
|
412
434
|
savedTransactionIds: ["transfer-1", "card-1"],
|
|
413
|
-
})).toStrictEqual({
|
|
435
|
+
})).toStrictEqual({
|
|
436
|
+
disputeCaseId,
|
|
437
|
+
fraudDetails: expect.any(Object),
|
|
438
|
+
fraudCardDetails: expect.any(Object),
|
|
439
|
+
});
|
|
414
440
|
});
|
|
415
441
|
test.each([
|
|
416
442
|
["a transaction was added", [card1, card2], ["card-1"]],
|
|
@@ -418,49 +444,63 @@ describe("toUpdateInput", () => {
|
|
|
418
444
|
["a transaction was swapped", [card1, transfer1], ["card-1", "card-2"]],
|
|
419
445
|
["a transaction is there twice", [card1, card1], ["card-1", "card-2"]],
|
|
420
446
|
])("sends the whole selection when %s", (_, transactions, savedTransactionIds) => {
|
|
421
|
-
expect(toUpdateInput({ savedCase, values: { transactions }, savedTransactionIds })).toStrictEqual({
|
|
447
|
+
expect(toUpdateInput({ disputeCaseId: savedCase.id, values: { transactions }, savedTransactionIds })).toStrictEqual({
|
|
448
|
+
disputeCaseId,
|
|
449
|
+
transactionIds: transactions.map(({ id }) => id),
|
|
450
|
+
fraudCardDetails: expect.any(Object),
|
|
451
|
+
});
|
|
422
452
|
});
|
|
423
453
|
test("leaves every group out when nothing is filled", () => {
|
|
424
454
|
expect(toUpdateInput({
|
|
425
|
-
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,
|
|
426
463
|
values: { transactions: [card1] },
|
|
427
464
|
savedTransactionIds: ["card-1"],
|
|
428
|
-
})).toStrictEqual({
|
|
465
|
+
})).toStrictEqual({
|
|
466
|
+
disputeCaseId,
|
|
467
|
+
fraudCardDetails: {
|
|
468
|
+
isLostOrStolen: null,
|
|
469
|
+
lostOrStolenNoticedAt: null,
|
|
470
|
+
hasContactedMerchant: null,
|
|
471
|
+
},
|
|
472
|
+
});
|
|
429
473
|
});
|
|
430
474
|
test("clears the external reference when it was emptied", () => {
|
|
431
475
|
expect(toUpdateInput({
|
|
432
|
-
savedCase,
|
|
433
|
-
values: { externalReference: "", transactions: [
|
|
434
|
-
savedTransactionIds: ["
|
|
476
|
+
disputeCaseId: savedCase.id,
|
|
477
|
+
values: { externalReference: "", transactions: [transfer1] },
|
|
478
|
+
savedTransactionIds: ["transfer-1"],
|
|
435
479
|
})).toStrictEqual({ disputeCaseId, externalReference: null });
|
|
436
480
|
});
|
|
437
481
|
test("keeps the stored external reference when the form has none", () => {
|
|
438
482
|
expect(toUpdateInput({
|
|
439
|
-
savedCase,
|
|
483
|
+
disputeCaseId: savedCase.id,
|
|
440
484
|
values: { ...incident, transactions: [card1] },
|
|
441
485
|
savedTransactionIds: ["card-1"],
|
|
442
486
|
})).not.toHaveProperty("externalReference");
|
|
443
487
|
});
|
|
444
488
|
test("holds the card details and the victim back while no transaction is selected", () => {
|
|
445
489
|
expect(toUpdateInput({
|
|
446
|
-
savedCase,
|
|
490
|
+
disputeCaseId: savedCase.id,
|
|
447
491
|
values: { ...filled, transactions: [] },
|
|
448
492
|
savedTransactionIds: [],
|
|
449
493
|
})).toStrictEqual({ disputeCaseId, fraudDetails, externalReference: "REF-42" });
|
|
450
494
|
});
|
|
451
|
-
test("sends
|
|
495
|
+
test("sends the actions taken from the form", () => {
|
|
452
496
|
var _a, _b;
|
|
453
497
|
const input = toUpdateInput({
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
fraudDetails: { ...fraudDetails, hasFiledPoliceComplaint: true },
|
|
457
|
-
fraudCardDetails: { ...fraudCardDetails, hasContactedMerchant: false },
|
|
458
|
-
},
|
|
459
|
-
values: { ...filled, transactions: [card1] },
|
|
498
|
+
disputeCaseId: savedCase.id,
|
|
499
|
+
values: { ...filled, hasContactedMerchant: true, transactions: [card1] },
|
|
460
500
|
savedTransactionIds: ["card-1"],
|
|
461
501
|
});
|
|
462
|
-
expect((_a = input.fraudDetails) === null || _a === void 0 ? void 0 : _a.hasFiledPoliceComplaint).
|
|
463
|
-
expect((_b = input.fraudCardDetails) === null || _b === void 0 ? void 0 : _b.hasContactedMerchant).toBe(
|
|
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);
|
|
464
504
|
});
|
|
465
505
|
});
|
|
466
506
|
describe("inputs sent to the API", () => {
|
|
@@ -504,7 +544,7 @@ describe("inputs sent to the API", () => {
|
|
|
504
544
|
const api = createApi();
|
|
505
545
|
const savedCase = getCase(await api.draft(toDraftInput({ ...filled, transactions: [card1] })));
|
|
506
546
|
const updated = getCase(await api.update(toUpdateInput({
|
|
507
|
-
savedCase,
|
|
547
|
+
disputeCaseId: savedCase.id,
|
|
508
548
|
values: { ...filled, transactions: [transfer1] },
|
|
509
549
|
savedTransactionIds: ["card-1"],
|
|
510
550
|
})));
|
|
@@ -516,7 +556,7 @@ describe("inputs sent to the API", () => {
|
|
|
516
556
|
const api = createApi();
|
|
517
557
|
const savedCase = getCase(await api.draft(toDraftInput({ ...filled, transactions: [transfer1] })));
|
|
518
558
|
const updated = getCase(await api.update(toUpdateInput({
|
|
519
|
-
savedCase,
|
|
559
|
+
disputeCaseId: savedCase.id,
|
|
520
560
|
values: { ...filled, transactions: [card1] },
|
|
521
561
|
savedTransactionIds: ["transfer-1"],
|
|
522
562
|
})));
|
|
@@ -524,7 +564,21 @@ describe("inputs sent to the API", () => {
|
|
|
524
564
|
expect(updated.fraudCardDetails).toMatchObject({ isLostOrStolen: true });
|
|
525
565
|
expect(updated.victimAccountMembershipId).toBe("member-2");
|
|
526
566
|
});
|
|
527
|
-
test("an update
|
|
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 () => {
|
|
528
582
|
var _a;
|
|
529
583
|
const api = createApi();
|
|
530
584
|
const savedCase = getCase(await api.draft({
|
|
@@ -534,8 +588,8 @@ describe("inputs sent to the API", () => {
|
|
|
534
588
|
fraudTransferDetails: { hasContactedBankOrBeneficiary: true },
|
|
535
589
|
}));
|
|
536
590
|
const updated = getCase(await api.update(toUpdateInput({
|
|
537
|
-
savedCase,
|
|
538
|
-
values: { ...filled, transactions: [card1, transfer1] },
|
|
591
|
+
disputeCaseId: savedCase.id,
|
|
592
|
+
values: { ...toFormValues(savedCase), ...filled, transactions: [card1, transfer1] },
|
|
539
593
|
savedTransactionIds: ["card-1", "transfer-1"],
|
|
540
594
|
})));
|
|
541
595
|
expect((_a = updated.fraudDetails) === null || _a === void 0 ? void 0 : _a.hasFiledPoliceComplaint).toBe(true);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test } from "vitest";
|
|
2
2
|
import { createFakeTransaction } from "../fraudReport/fakeApi";
|
|
3
|
-
import { getTransactionsTotal, removeDuplicateTransactions } from "../fraudReport/transactions";
|
|
3
|
+
import { getTransactionsOverLimit, getTransactionsTotal, MAX_TRANSACTIONS, removeDuplicateTransactions, } from "../fraudReport/transactions";
|
|
4
4
|
const withAmount = (value, currency = "EUR") => createFakeTransaction(`card-${value}`, "CardOutDebit", { amount: { value, currency } });
|
|
5
5
|
describe("getTransactionsTotal", () => {
|
|
6
6
|
test("adds the amounts without rounding drift", () => {
|
|
@@ -26,3 +26,13 @@ describe("removeDuplicateTransactions", () => {
|
|
|
26
26
|
expect(removeDuplicateTransactions([card, transfer, { ...card, counterparty: "Lidl" }])).toEqual([card, transfer]);
|
|
27
27
|
});
|
|
28
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
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Option } from "@bloodyowl/boxed";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { createFakeTransaction } from "../fraudReport/fakeApi";
|
|
4
|
+
import { getInitialVictimChoice, getOtherAccountMemberships, getSelectedAccountMembershipId, getVictimAccountMembershipId, getVictimChange, } from "../fraudReport/victim";
|
|
4
5
|
const julia = { id: "member-1", name: "Julia Fox" };
|
|
5
6
|
const nicolas = { id: "member-2", name: "Nicolas Saison" };
|
|
6
7
|
const ada = { id: "member-3", name: "Ada Lovelace" };
|
|
@@ -140,3 +141,28 @@ describe("getVictimAccountMembershipId", () => {
|
|
|
140
141
|
}).toUndefined()).toBe(victim);
|
|
141
142
|
});
|
|
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
|
+
});
|