@swan-io/shared-business 18.6.0 → 18.7.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/FileInput.js +25 -10
- package/src/components/FileTile.d.ts +4 -3
- package/src/components/FileTile.js +14 -7
- package/src/components/FilesUploader.js +12 -4
- package/src/components/FraudReport/DocumentsStep.d.ts +13 -0
- package/src/components/FraudReport/DocumentsStep.js +49 -0
- package/src/components/FraudReport/FraudReportLayout.d.ts +2 -1
- package/src/components/FraudReport/FraudReportLayout.js +2 -2
- package/src/components/FraudReport/TransferDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/TransferDetailsStep.js +25 -0
- package/src/components/SupportingDocumentCollection.d.ts +1 -0
- package/src/components/SupportingDocumentCollection.js +13 -14
- package/src/hooks/__tests__/useFilesUploader.test.d.ts +1 -0
- package/src/hooks/__tests__/useFilesUploader.test.js +101 -0
- package/src/hooks/useFilesUploader.d.ts +2 -1
- package/src/hooks/useFilesUploader.js +28 -9
- package/src/locales/de.json +22 -0
- package/src/locales/en.json +22 -0
- package/src/locales/es.json +22 -0
- package/src/locales/fi.json +22 -0
- package/src/locales/fr.json +22 -0
- package/src/locales/it.json +22 -0
- package/src/locales/nl.json +22 -0
- package/src/locales/pt.json +22 -0
- package/src/utils/SwanFile.d.ts +2 -0
- package/src/utils/__tests__/fraudReport.documents.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.documents.test.js +61 -0
- package/src/utils/__tests__/fraudReport.picker.test.js +25 -10
- package/src/utils/__tests__/fraudReport.prefill.test.js +4 -0
- package/src/utils/__tests__/fraudReport.resume.test.js +2 -1
- package/src/utils/__tests__/fraudReport.toInput.test.js +81 -15
- package/src/utils/__tests__/fraudReport.transfer.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.transfer.test.js +31 -0
- package/src/utils/__tests__/validation.test.js +12 -5
- package/src/utils/fraudReport/documents.d.ts +9 -0
- package/src/utils/fraudReport/documents.js +18 -0
- package/src/utils/fraudReport/picker.d.ts +1 -0
- package/src/utils/fraudReport/picker.js +5 -4
- package/src/utils/fraudReport/prefill.d.ts +1 -1
- package/src/utils/fraudReport/prefill.js +2 -1
- package/src/utils/fraudReport/resume.js +1 -1
- package/src/utils/fraudReport/toInput.d.ts +1 -0
- package/src/utils/fraudReport/toInput.js +23 -4
- package/src/utils/fraudReport/transfer.d.ts +6 -0
- package/src/utils/fraudReport/transfer.js +8 -0
- package/src/utils/fraudReport/types.d.ts +1 -1
- package/src/utils/validation.js +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { getGroupFiles, setGroupFiles } from "../fraudReport/documents";
|
|
3
|
+
const file = (id) => ({
|
|
4
|
+
id,
|
|
5
|
+
name: `${id}.pdf`,
|
|
6
|
+
statusInfo: { status: "Uploaded" },
|
|
7
|
+
});
|
|
8
|
+
const document = (id, purpose) => ({
|
|
9
|
+
purpose,
|
|
10
|
+
file: file(id),
|
|
11
|
+
});
|
|
12
|
+
const documents = [
|
|
13
|
+
document("police", "PoliceReport"),
|
|
14
|
+
document("evidence", "FraudEvidence"),
|
|
15
|
+
document("correspondence", "DisputeCorrespondence"),
|
|
16
|
+
document("other", "Other"),
|
|
17
|
+
];
|
|
18
|
+
describe("getGroupFiles", () => {
|
|
19
|
+
test("lists the police reports in the police report group", () => {
|
|
20
|
+
expect(getGroupFiles(documents, "PoliceReport")).toEqual([file("police")]);
|
|
21
|
+
});
|
|
22
|
+
test("lists every other purpose in the other documents group", () => {
|
|
23
|
+
expect(getGroupFiles(documents, "OtherDocuments")).toEqual([
|
|
24
|
+
file("evidence"),
|
|
25
|
+
file("correspondence"),
|
|
26
|
+
file("other"),
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe("setGroupFiles", () => {
|
|
31
|
+
test("gives a new file the purpose its group uploads with", () => {
|
|
32
|
+
expect(setGroupFiles([], "PoliceReport", [file("new")])).toEqual([
|
|
33
|
+
document("new", "PoliceReport"),
|
|
34
|
+
]);
|
|
35
|
+
expect(setGroupFiles([], "OtherDocuments", [file("new")])).toEqual([
|
|
36
|
+
document("new", "FraudEvidence"),
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
test("keeps the purpose of a file already in the group", () => {
|
|
40
|
+
expect(setGroupFiles(documents, "OtherDocuments", [file("correspondence"), file("other")])).toEqual([
|
|
41
|
+
document("police", "PoliceReport"),
|
|
42
|
+
document("correspondence", "DisputeCorrespondence"),
|
|
43
|
+
document("other", "Other"),
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
test("keeps the other group's documents when a group changes", () => {
|
|
47
|
+
expect(setGroupFiles(documents, "PoliceReport", [])).toEqual([
|
|
48
|
+
document("evidence", "FraudEvidence"),
|
|
49
|
+
document("correspondence", "DisputeCorrespondence"),
|
|
50
|
+
document("other", "Other"),
|
|
51
|
+
]);
|
|
52
|
+
});
|
|
53
|
+
test("keeps the file's new status", () => {
|
|
54
|
+
const uploading = {
|
|
55
|
+
id: "new",
|
|
56
|
+
name: "new.pdf",
|
|
57
|
+
statusInfo: { status: "Uploading", progress: 0.5 },
|
|
58
|
+
};
|
|
59
|
+
expect(setGroupFiles([{ purpose: "PoliceReport", file: uploading }], "PoliceReport", [file("new")])).toEqual([document("new", "PoliceReport")]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -8,12 +8,12 @@ const instant = createFakeTransaction("transfer-instant", "SepaInstantCreditTran
|
|
|
8
8
|
const international = createFakeTransaction("transfer-international", "InternationalCreditTransferOut");
|
|
9
9
|
const internal = createFakeTransaction("transfer-internal", "InternalCreditTransferOut");
|
|
10
10
|
const rows = [
|
|
11
|
-
{ transaction: victimCard, cardAccountMembershipId: "member-victim" },
|
|
12
|
-
{ transaction: otherCard, cardAccountMembershipId: "member-other" },
|
|
13
|
-
{ transaction: sepa, cardAccountMembershipId: null },
|
|
14
|
-
{ transaction: instant, cardAccountMembershipId: null },
|
|
15
|
-
{ transaction: international, cardAccountMembershipId: null },
|
|
16
|
-
{ transaction: internal, cardAccountMembershipId: null },
|
|
11
|
+
{ transaction: victimCard, cardAccountMembershipId: "member-victim", alreadyReported: false },
|
|
12
|
+
{ transaction: otherCard, cardAccountMembershipId: "member-other", alreadyReported: false },
|
|
13
|
+
{ transaction: sepa, cardAccountMembershipId: null, alreadyReported: false },
|
|
14
|
+
{ transaction: instant, cardAccountMembershipId: null, alreadyReported: false },
|
|
15
|
+
{ transaction: international, cardAccountMembershipId: null, alreadyReported: false },
|
|
16
|
+
{ transaction: internal, cardAccountMembershipId: null, alreadyReported: false },
|
|
17
17
|
];
|
|
18
18
|
describe("getPickerTransactions", () => {
|
|
19
19
|
test("lists a card transaction only when its card belongs to the victim", () => {
|
|
@@ -39,15 +39,30 @@ describe("getPickerTransactions", () => {
|
|
|
39
39
|
]);
|
|
40
40
|
});
|
|
41
41
|
test("leaves out a card transaction whose card has no known account membership", () => {
|
|
42
|
-
expect(getPickerTransactions([{ transaction: victimCard, cardAccountMembershipId: null }], "member-victim")).toEqual([]);
|
|
42
|
+
expect(getPickerTransactions([{ transaction: victimCard, cardAccountMembershipId: null, alreadyReported: false }], "member-victim")).toEqual([]);
|
|
43
43
|
});
|
|
44
44
|
test("keeps the order of the rows and removes duplicates", () => {
|
|
45
45
|
expect(getPickerTransactions([
|
|
46
|
-
{ transaction: sepa, cardAccountMembershipId: null },
|
|
47
|
-
{
|
|
48
|
-
|
|
46
|
+
{ transaction: sepa, cardAccountMembershipId: null, alreadyReported: false },
|
|
47
|
+
{
|
|
48
|
+
transaction: victimCard,
|
|
49
|
+
cardAccountMembershipId: "member-victim",
|
|
50
|
+
alreadyReported: false,
|
|
51
|
+
},
|
|
52
|
+
{ transaction: sepa, cardAccountMembershipId: null, alreadyReported: false },
|
|
49
53
|
], "member-victim")).toEqual([sepa, victimCard]);
|
|
50
54
|
});
|
|
55
|
+
test("leaves out a transaction already in a submitted case", () => {
|
|
56
|
+
expect(getPickerTransactions([
|
|
57
|
+
{ transaction: sepa, cardAccountMembershipId: null, alreadyReported: true },
|
|
58
|
+
{
|
|
59
|
+
transaction: victimCard,
|
|
60
|
+
cardAccountMembershipId: "member-victim",
|
|
61
|
+
alreadyReported: true,
|
|
62
|
+
},
|
|
63
|
+
{ transaction: instant, cardAccountMembershipId: null, alreadyReported: false },
|
|
64
|
+
], "member-victim")).toEqual([instant]);
|
|
65
|
+
});
|
|
51
66
|
});
|
|
52
67
|
describe("toggleTransaction", () => {
|
|
53
68
|
test("adds a transaction that isn't selected, after the others", () => {
|
|
@@ -65,6 +65,7 @@ describe("toFormValues", () => {
|
|
|
65
65
|
isLostOrStolen: true,
|
|
66
66
|
lostOrStolenNoticedAt: "2026-11-19",
|
|
67
67
|
hasContactedMerchant: false,
|
|
68
|
+
hasContactedBankOrBeneficiary: true,
|
|
68
69
|
externalReference: "ref-42",
|
|
69
70
|
});
|
|
70
71
|
});
|
|
@@ -119,6 +120,7 @@ describe("toFormValues then toUpdateInput", () => {
|
|
|
119
120
|
}))).toEqual({
|
|
120
121
|
disputeCaseId: "case-1",
|
|
121
122
|
fraudDetails,
|
|
123
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: null },
|
|
122
124
|
victimAccountMembershipId: "membership-2",
|
|
123
125
|
externalReference: "ref-42",
|
|
124
126
|
});
|
|
@@ -128,6 +130,7 @@ describe("toFormValues then toUpdateInput", () => {
|
|
|
128
130
|
disputeCaseId: "case-1",
|
|
129
131
|
fraudDetails,
|
|
130
132
|
fraudCardDetails,
|
|
133
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: true },
|
|
131
134
|
externalReference: "ref-42",
|
|
132
135
|
});
|
|
133
136
|
});
|
|
@@ -135,6 +138,7 @@ describe("toFormValues then toUpdateInput", () => {
|
|
|
135
138
|
expect(roundTrip(draft({ transactions: [transfer1], fraudDetails, hasVictim: true }))).toEqual({
|
|
136
139
|
disputeCaseId: "case-1",
|
|
137
140
|
fraudDetails,
|
|
141
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: null },
|
|
138
142
|
});
|
|
139
143
|
});
|
|
140
144
|
test("sends empty fraudster lists back as null", () => {
|
|
@@ -34,8 +34,9 @@ describe("getResumeStep", () => {
|
|
|
34
34
|
test("opens the card sub-step when only the police complaint is answered", () => {
|
|
35
35
|
expect(getResumeStep({ transactions: [card], ...incident, hasFiledPoliceComplaint: true })).toBe("Card");
|
|
36
36
|
});
|
|
37
|
-
test("skips the transfer sub-step,
|
|
37
|
+
test("skips the transfer sub-step, answered or not", () => {
|
|
38
38
|
expect(getResumeStep({ transactions: [transfer], ...incident })).toBe("Documents");
|
|
39
|
+
expect(getResumeStep({ transactions: [transfer], ...incident, hasContactedBankOrBeneficiary: true })).toBe("Documents");
|
|
39
40
|
});
|
|
40
41
|
test.each([
|
|
41
42
|
{ name: "only the shared information", values: { sharedInformationWithFraudster: ["None"] } },
|
|
@@ -289,10 +289,18 @@ describe("toDraftInput", () => {
|
|
|
289
289
|
externalReference: "REF-42",
|
|
290
290
|
});
|
|
291
291
|
});
|
|
292
|
-
test("
|
|
292
|
+
test("leaves the transfer details out until they are answered", () => {
|
|
293
293
|
expect(toDraftInput({ ...filled, transactions: [transfer1] })).not.toHaveProperty("fraudTransferDetails");
|
|
294
294
|
expect(toDraftInput({ ...filled, transactions: [transfer1, card1] })).not.toHaveProperty("fraudTransferDetails");
|
|
295
295
|
});
|
|
296
|
+
test("sends the transfer details once answered, only on a case with transfers", () => {
|
|
297
|
+
const answered = { ...filled, hasContactedBankOrBeneficiary: true };
|
|
298
|
+
expect(toDraftInput({ ...answered, transactions: [transfer1] }).fraudTransferDetails).toEqual({
|
|
299
|
+
hasContactedBankOrBeneficiary: true,
|
|
300
|
+
});
|
|
301
|
+
expect(toDraftInput({ ...answered, transactions: [transfer1, card1] }).fraudTransferDetails).toEqual({ hasContactedBankOrBeneficiary: true });
|
|
302
|
+
expect(toDraftInput({ ...answered, transactions: [card1] })).not.toHaveProperty("fraudTransferDetails");
|
|
303
|
+
});
|
|
296
304
|
test("leaves the victim out of a transfer-only case until one is picked", () => {
|
|
297
305
|
expect(toDraftInput({ ...incident, transactions: [transfer1] })).not.toHaveProperty("victimAccountMembershipId");
|
|
298
306
|
});
|
|
@@ -369,6 +377,11 @@ describe("toDraftInput", () => {
|
|
|
369
377
|
describe("toUpdateInput", () => {
|
|
370
378
|
const savedCase = { id: "case-1" };
|
|
371
379
|
const disputeCaseId = savedCase.id;
|
|
380
|
+
const cardGroups = { fraudCardDetails: expect.any(Object) };
|
|
381
|
+
const mixedGroups = {
|
|
382
|
+
...cardGroups,
|
|
383
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: null },
|
|
384
|
+
};
|
|
372
385
|
test("sends the card details and no victim on a card-only case", () => {
|
|
373
386
|
expect(toUpdateInput({
|
|
374
387
|
disputeCaseId: savedCase.id,
|
|
@@ -391,6 +404,7 @@ describe("toUpdateInput", () => {
|
|
|
391
404
|
disputeCaseId,
|
|
392
405
|
transactionIds: ["transfer-1"],
|
|
393
406
|
fraudDetails,
|
|
407
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: null },
|
|
394
408
|
victimAccountMembershipId: "member-1",
|
|
395
409
|
externalReference: "REF-42",
|
|
396
410
|
});
|
|
@@ -405,14 +419,28 @@ describe("toUpdateInput", () => {
|
|
|
405
419
|
transactionIds: ["transfer-1", "card-1"],
|
|
406
420
|
fraudDetails,
|
|
407
421
|
fraudCardDetails,
|
|
422
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: null },
|
|
408
423
|
externalReference: "REF-42",
|
|
409
424
|
});
|
|
410
425
|
});
|
|
411
|
-
test("
|
|
426
|
+
test("sends the transfer details from the form on a case with transfers", () => {
|
|
427
|
+
const values = { ...filled, hasContactedBankOrBeneficiary: true };
|
|
412
428
|
expect(toUpdateInput({
|
|
413
429
|
disputeCaseId: savedCase.id,
|
|
414
|
-
values: { ...
|
|
415
|
-
savedTransactionIds: [],
|
|
430
|
+
values: { ...values, transactions: [transfer1] },
|
|
431
|
+
savedTransactionIds: ["transfer-1"],
|
|
432
|
+
}).fraudTransferDetails).toStrictEqual({ hasContactedBankOrBeneficiary: true });
|
|
433
|
+
expect(toUpdateInput({
|
|
434
|
+
disputeCaseId: savedCase.id,
|
|
435
|
+
values: { ...values, transactions: [transfer1, card1] },
|
|
436
|
+
savedTransactionIds: ["transfer-1", "card-1"],
|
|
437
|
+
}).fraudTransferDetails).toStrictEqual({ hasContactedBankOrBeneficiary: true });
|
|
438
|
+
});
|
|
439
|
+
test("never sends transfer details on a card-only case", () => {
|
|
440
|
+
expect(toUpdateInput({
|
|
441
|
+
disputeCaseId: savedCase.id,
|
|
442
|
+
values: { ...filled, hasContactedBankOrBeneficiary: true, transactions: [card1] },
|
|
443
|
+
savedTransactionIds: ["card-1"],
|
|
416
444
|
})).not.toHaveProperty("fraudTransferDetails");
|
|
417
445
|
});
|
|
418
446
|
test("clears the fraudster answers once no fraudster convinced the user", () => {
|
|
@@ -436,26 +464,30 @@ describe("toUpdateInput", () => {
|
|
|
436
464
|
disputeCaseId,
|
|
437
465
|
fraudDetails: expect.any(Object),
|
|
438
466
|
fraudCardDetails: expect.any(Object),
|
|
467
|
+
fraudTransferDetails: expect.any(Object),
|
|
439
468
|
});
|
|
440
469
|
});
|
|
441
470
|
test.each([
|
|
442
|
-
["a transaction was added", [card1, card2], ["card-1"]],
|
|
443
|
-
["a transaction was removed", [card1], ["card-1", "card-2"]],
|
|
444
|
-
["a transaction was swapped", [card1, transfer1], ["card-1", "card-2"]],
|
|
445
|
-
["a transaction is there twice", [card1, card1], ["card-1", "card-2"]],
|
|
446
|
-
])("sends the whole selection when %s", (_, transactions, savedTransactionIds) => {
|
|
471
|
+
["a transaction was added", [card1, card2], ["card-1"], cardGroups],
|
|
472
|
+
["a transaction was removed", [card1], ["card-1", "card-2"], cardGroups],
|
|
473
|
+
["a transaction was swapped", [card1, transfer1], ["card-1", "card-2"], mixedGroups],
|
|
474
|
+
["a transaction is there twice", [card1, card1], ["card-1", "card-2"], cardGroups],
|
|
475
|
+
])("sends the whole selection when %s", (_, transactions, savedTransactionIds, groups) => {
|
|
447
476
|
expect(toUpdateInput({ disputeCaseId: savedCase.id, values: { transactions }, savedTransactionIds })).toStrictEqual({
|
|
448
477
|
disputeCaseId,
|
|
449
478
|
transactionIds: transactions.map(({ id }) => id),
|
|
450
|
-
|
|
479
|
+
...groups,
|
|
451
480
|
});
|
|
452
481
|
});
|
|
453
|
-
test("
|
|
482
|
+
test("sends the transfer details even when empty, so removed answers are cleared", () => {
|
|
454
483
|
expect(toUpdateInput({
|
|
455
484
|
disputeCaseId: savedCase.id,
|
|
456
485
|
values: { transactions: [transfer1] },
|
|
457
486
|
savedTransactionIds: ["transfer-1"],
|
|
458
|
-
})).toStrictEqual({
|
|
487
|
+
})).toStrictEqual({
|
|
488
|
+
disputeCaseId,
|
|
489
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: null },
|
|
490
|
+
});
|
|
459
491
|
});
|
|
460
492
|
test("sends the card details even when empty, so removed answers are cleared", () => {
|
|
461
493
|
expect(toUpdateInput({
|
|
@@ -474,9 +506,17 @@ describe("toUpdateInput", () => {
|
|
|
474
506
|
test("clears the external reference when it was emptied", () => {
|
|
475
507
|
expect(toUpdateInput({
|
|
476
508
|
disputeCaseId: savedCase.id,
|
|
477
|
-
values: { externalReference: "", transactions: [
|
|
478
|
-
savedTransactionIds: ["
|
|
479
|
-
})).toStrictEqual({
|
|
509
|
+
values: { externalReference: "", transactions: [card1] },
|
|
510
|
+
savedTransactionIds: ["card-1"],
|
|
511
|
+
})).toStrictEqual({
|
|
512
|
+
disputeCaseId,
|
|
513
|
+
fraudCardDetails: {
|
|
514
|
+
isLostOrStolen: null,
|
|
515
|
+
lostOrStolenNoticedAt: null,
|
|
516
|
+
hasContactedMerchant: null,
|
|
517
|
+
},
|
|
518
|
+
externalReference: null,
|
|
519
|
+
});
|
|
480
520
|
});
|
|
481
521
|
test("keeps the stored external reference when the form has none", () => {
|
|
482
522
|
expect(toUpdateInput({
|
|
@@ -578,6 +618,32 @@ describe("inputs sent to the API", () => {
|
|
|
578
618
|
})));
|
|
579
619
|
expect((_a = updated.fraudCardDetails) === null || _a === void 0 ? void 0 : _a.hasContactedMerchant).toBeNull();
|
|
580
620
|
});
|
|
621
|
+
test("a transfer answer is accepted and stored, and not sent once only cards are left", async () => {
|
|
622
|
+
const api = createApi();
|
|
623
|
+
const values = { ...filled, hasContactedBankOrBeneficiary: true };
|
|
624
|
+
const savedCase = getCase(await api.draft(toDraftInput({ ...values, transactions: [transfer1, card1] })));
|
|
625
|
+
expect(savedCase.fraudTransferDetails).toStrictEqual({ hasContactedBankOrBeneficiary: true });
|
|
626
|
+
const updated = getCase(await api.update(toUpdateInput({
|
|
627
|
+
disputeCaseId: savedCase.id,
|
|
628
|
+
values: { ...values, transactions: [card1] },
|
|
629
|
+
savedTransactionIds: ["transfer-1", "card-1"],
|
|
630
|
+
})));
|
|
631
|
+
expect(updated.fraudTransferDetails).toBeNull();
|
|
632
|
+
});
|
|
633
|
+
test("an update clears a transfer action the user removed", async () => {
|
|
634
|
+
var _a;
|
|
635
|
+
const api = createApi();
|
|
636
|
+
const savedCase = getCase(await api.draft({
|
|
637
|
+
transactionIds: ["transfer-1"],
|
|
638
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: true },
|
|
639
|
+
}));
|
|
640
|
+
const updated = getCase(await api.update(toUpdateInput({
|
|
641
|
+
disputeCaseId: savedCase.id,
|
|
642
|
+
values: { ...toFormValues(savedCase), hasContactedBankOrBeneficiary: undefined },
|
|
643
|
+
savedTransactionIds: ["transfer-1"],
|
|
644
|
+
})));
|
|
645
|
+
expect((_a = updated.fraudTransferDetails) === null || _a === void 0 ? void 0 : _a.hasContactedBankOrBeneficiary).toBeNull();
|
|
646
|
+
});
|
|
581
647
|
test("an update keeps the details another client stored on a resumed draft", async () => {
|
|
582
648
|
var _a;
|
|
583
649
|
const api = createApi();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { getTransferActions, toTransferValues } from "../fraudReport/transfer";
|
|
3
|
+
describe("getTransferActions", () => {
|
|
4
|
+
test("selects the actions answered yes", () => {
|
|
5
|
+
expect(getTransferActions({ hasContactedBankOrBeneficiary: true, hasFiledPoliceComplaint: true })).toEqual(["BankOrBeneficiary", "Police"]);
|
|
6
|
+
});
|
|
7
|
+
test("selects nothing for actions answered no or not answered", () => {
|
|
8
|
+
expect(getTransferActions({
|
|
9
|
+
hasContactedBankOrBeneficiary: false,
|
|
10
|
+
hasFiledPoliceComplaint: undefined,
|
|
11
|
+
})).toEqual([]);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
describe("toTransferValues", () => {
|
|
15
|
+
test("sends the selected actions as yes", () => {
|
|
16
|
+
expect(toTransferValues(["BankOrBeneficiary", "Police"])).toEqual({
|
|
17
|
+
hasContactedBankOrBeneficiary: true,
|
|
18
|
+
hasFiledPoliceComplaint: true,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
test("leaves an unselected action empty instead of sending false", () => {
|
|
22
|
+
expect(toTransferValues(["Police"])).toEqual({
|
|
23
|
+
hasContactedBankOrBeneficiary: undefined,
|
|
24
|
+
hasFiledPoliceComplaint: true,
|
|
25
|
+
});
|
|
26
|
+
expect(toTransferValues([])).toEqual({
|
|
27
|
+
hasContactedBankOrBeneficiary: undefined,
|
|
28
|
+
hasFiledPoliceComplaint: undefined,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -132,13 +132,20 @@ describe("validateIndividualTaxNumber", () => {
|
|
|
132
132
|
});
|
|
133
133
|
describe("FIN (Finland)", () => {
|
|
134
134
|
const validator = validateIndividualTaxNumber("FIN");
|
|
135
|
-
test("accepts
|
|
136
|
-
expect(validator("
|
|
137
|
-
expect(validator("
|
|
135
|
+
test("accepts personal identity codes with their separator", () => {
|
|
136
|
+
expect(validator("131052-308T")).toBeUndefined();
|
|
137
|
+
expect(validator("131052+308T")).toBeUndefined();
|
|
138
|
+
expect(validator("131052A308T")).toBeUndefined();
|
|
139
|
+
expect(validator("010594Y9032")).toBeUndefined();
|
|
140
|
+
expect(validator("131052-308t")).toBeUndefined();
|
|
138
141
|
});
|
|
139
142
|
test("rejects invalid formats", () => {
|
|
140
|
-
expect(validator("
|
|
141
|
-
expect(validator("
|
|
143
|
+
expect(validator("131052308T")).toBeDefined();
|
|
144
|
+
expect(validator("12345678901")).toBeDefined();
|
|
145
|
+
expect(validator("131052G308T")).toBeDefined();
|
|
146
|
+
expect(validator("131052-308G")).toBeDefined();
|
|
147
|
+
expect(validator("131052-3089T")).toBeDefined();
|
|
148
|
+
expect(validator("3368725-9")).toBeDefined();
|
|
142
149
|
});
|
|
143
150
|
});
|
|
144
151
|
describe("FRA (France)", () => {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Document } from "../../components/SupportingDocumentCollection";
|
|
2
|
+
import type { SwanFile } from "../SwanFile";
|
|
3
|
+
import type { FraudReportDocumentPurpose } from "./types";
|
|
4
|
+
export type FraudReportDocument = Document<FraudReportDocumentPurpose>;
|
|
5
|
+
export type FraudReportDocumentGroup = "PoliceReport" | "OtherDocuments";
|
|
6
|
+
export declare const fraudReportDocumentGroups: FraudReportDocumentGroup[];
|
|
7
|
+
export declare const getUploadPurpose: (group: FraudReportDocumentGroup) => FraudReportDocumentPurpose;
|
|
8
|
+
export declare const getGroupFiles: (documents: FraudReportDocument[], group: FraudReportDocumentGroup) => SwanFile[];
|
|
9
|
+
export declare const setGroupFiles: (documents: FraudReportDocument[], group: FraudReportDocumentGroup, files: SwanFile[]) => FraudReportDocument[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const fraudReportDocumentGroups = [
|
|
2
|
+
"PoliceReport",
|
|
3
|
+
"OtherDocuments",
|
|
4
|
+
];
|
|
5
|
+
const uploadPurposes = {
|
|
6
|
+
PoliceReport: "PoliceReport",
|
|
7
|
+
OtherDocuments: "FraudEvidence",
|
|
8
|
+
};
|
|
9
|
+
export const getUploadPurpose = (group) => uploadPurposes[group];
|
|
10
|
+
const getGroup = (purpose) => purpose === "PoliceReport" ? "PoliceReport" : "OtherDocuments";
|
|
11
|
+
export const getGroupFiles = (documents, group) => documents.filter(({ purpose }) => getGroup(purpose) === group).map(({ file }) => file);
|
|
12
|
+
export const setGroupFiles = (documents, group, files) => [
|
|
13
|
+
...documents.filter(({ purpose }) => getGroup(purpose) !== group),
|
|
14
|
+
...files.map(file => { var _a; var _b; return ({
|
|
15
|
+
file,
|
|
16
|
+
purpose: (_b = (_a = documents.find(document => document.file.id === file.id)) === null || _a === void 0 ? void 0 : _a.purpose) !== null && _b !== void 0 ? _b : uploadPurposes[group],
|
|
17
|
+
}); }),
|
|
18
|
+
];
|
|
@@ -2,6 +2,7 @@ import type { FraudReportTransaction } from "./types";
|
|
|
2
2
|
export type FraudReportPickerRow = {
|
|
3
3
|
transaction: FraudReportTransaction;
|
|
4
4
|
cardAccountMembershipId: string | null;
|
|
5
|
+
alreadyReported: boolean;
|
|
5
6
|
};
|
|
6
7
|
export declare const getPickerTransactions: (rows: FraudReportPickerRow[], victimAccountMembershipId: string | undefined) => FraudReportTransaction[];
|
|
7
8
|
export declare const toggleTransaction: (selected: FraudReportTransaction[], transaction: FraudReportTransaction) => FraudReportTransaction[];
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { match } from "ts-pattern";
|
|
2
2
|
import { removeDuplicateTransactions } from "./transactions";
|
|
3
3
|
export const getPickerTransactions = (rows, victimAccountMembershipId) => removeDuplicateTransactions(rows
|
|
4
|
-
.filter(({ transaction, cardAccountMembershipId }) =>
|
|
5
|
-
.
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
.filter(({ transaction, cardAccountMembershipId, alreadyReported }) => !alreadyReported &&
|
|
5
|
+
match(transaction.rail)
|
|
6
|
+
.with("Card", () => cardAccountMembershipId === victimAccountMembershipId)
|
|
7
|
+
.with("Transfer", () => true)
|
|
8
|
+
.exhaustive())
|
|
8
9
|
.map(({ transaction }) => transaction));
|
|
9
10
|
const isSelected = (selected, { id }) => selected.some(item => item.id === id);
|
|
10
11
|
export const toggleTransaction = (selected, transaction) => isSelected(selected, transaction)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { FraudReportFormValues } from "./toInput";
|
|
2
2
|
import type { FraudReportCase } from "./types";
|
|
3
|
-
export declare const toFormValues: ({ transactions, fraudDetails, fraudCardDetails, victimAccountMembershipId, externalReference, }: Pick<FraudReportCase, "transactions" | "fraudDetails" | "fraudCardDetails" | "victimAccountMembershipId" | "externalReference">) => FraudReportFormValues;
|
|
3
|
+
export declare const toFormValues: ({ transactions, fraudDetails, fraudCardDetails, fraudTransferDetails, victimAccountMembershipId, externalReference, }: Pick<FraudReportCase, "transactions" | "fraudDetails" | "fraudCardDetails" | "fraudTransferDetails" | "victimAccountMembershipId" | "externalReference">) => FraudReportFormValues;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const toFormValues = ({ transactions, fraudDetails, fraudCardDetails, victimAccountMembershipId, externalReference, }) => { var _a, _b, _c, _d, _e, _f; return ({
|
|
1
|
+
export const toFormValues = ({ transactions, fraudDetails, fraudCardDetails, fraudTransferDetails, victimAccountMembershipId, externalReference, }) => { var _a, _b, _c, _d, _e, _f, _g; return ({
|
|
2
2
|
transactions,
|
|
3
3
|
victimAccountMembershipId: victimAccountMembershipId !== null && victimAccountMembershipId !== void 0 ? victimAccountMembershipId : undefined,
|
|
4
4
|
reportedReason: fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.reportedReason,
|
|
@@ -12,5 +12,6 @@ export const toFormValues = ({ transactions, fraudDetails, fraudCardDetails, vic
|
|
|
12
12
|
isLostOrStolen: (_d = fraudCardDetails === null || fraudCardDetails === void 0 ? void 0 : fraudCardDetails.isLostOrStolen) !== null && _d !== void 0 ? _d : undefined,
|
|
13
13
|
lostOrStolenNoticedAt: (_e = fraudCardDetails === null || fraudCardDetails === void 0 ? void 0 : fraudCardDetails.lostOrStolenNoticedAt) !== null && _e !== void 0 ? _e : undefined,
|
|
14
14
|
hasContactedMerchant: (_f = fraudCardDetails === null || fraudCardDetails === void 0 ? void 0 : fraudCardDetails.hasContactedMerchant) !== null && _f !== void 0 ? _f : undefined,
|
|
15
|
+
hasContactedBankOrBeneficiary: (_g = fraudTransferDetails === null || fraudTransferDetails === void 0 ? void 0 : fraudTransferDetails.hasContactedBankOrBeneficiary) !== null && _g !== void 0 ? _g : undefined,
|
|
15
16
|
externalReference: externalReference !== null && externalReference !== void 0 ? externalReference : undefined,
|
|
16
17
|
}); };
|
|
@@ -4,7 +4,7 @@ import { getDetailsSteps } from "./stepper";
|
|
|
4
4
|
import { toFilledList, toRequiredFraudDetails, toTransactionIds, } from "./toInput";
|
|
5
5
|
const isDetailsStepAnswered = (step, values) => match(step)
|
|
6
6
|
.with("Card", () => values.isLostOrStolen != null || values.hasContactedMerchant != null)
|
|
7
|
-
//
|
|
7
|
+
// Its only answer has no "No", so an empty one can't tell skipped from seen
|
|
8
8
|
.with("Transfer", () => true)
|
|
9
9
|
.with("Fraudster", () => toFilledList(values.fraudsterChannels).isSome() ||
|
|
10
10
|
toFilledList(values.sharedInformationWithFraudster).isSome())
|
|
@@ -14,6 +14,7 @@ export type FraudReportFormValues = {
|
|
|
14
14
|
isLostOrStolen?: boolean;
|
|
15
15
|
lostOrStolenNoticedAt?: string;
|
|
16
16
|
hasContactedMerchant?: boolean;
|
|
17
|
+
hasContactedBankOrBeneficiary?: boolean;
|
|
17
18
|
externalReference?: string;
|
|
18
19
|
};
|
|
19
20
|
export declare const toFilled: (value: string | undefined) => Option<string>;
|
|
@@ -34,19 +34,38 @@ const toFraudCardDetails = (values, { sendEmpty }) => {
|
|
|
34
34
|
? Option.Some(details)
|
|
35
35
|
: Option.None();
|
|
36
36
|
};
|
|
37
|
+
const toFraudTransferDetails = (values, { sendEmpty }) => {
|
|
38
|
+
var _a;
|
|
39
|
+
const details = {
|
|
40
|
+
hasContactedBankOrBeneficiary: (_a = values.hasContactedBankOrBeneficiary) !== null && _a !== void 0 ? _a : null,
|
|
41
|
+
};
|
|
42
|
+
return sendEmpty || Object.values(details).some(value => value !== null)
|
|
43
|
+
? Option.Some(details)
|
|
44
|
+
: Option.None();
|
|
45
|
+
};
|
|
37
46
|
const toDetails = (values, { isUpdate }) => {
|
|
38
47
|
const fraudDetails = toFraudDetails(values)
|
|
39
48
|
.map(value => ({ fraudDetails: value }))
|
|
40
49
|
.toUndefined();
|
|
50
|
+
const fraudCardDetails = toFraudCardDetails(values, { sendEmpty: isUpdate })
|
|
51
|
+
.map(value => ({ fraudCardDetails: value }))
|
|
52
|
+
.toUndefined();
|
|
53
|
+
const fraudTransferDetails = toFraudTransferDetails(values, { sendEmpty: isUpdate })
|
|
54
|
+
.map(value => ({ fraudTransferDetails: value }))
|
|
55
|
+
.toUndefined();
|
|
41
56
|
return match(getCaseRail(values.transactions))
|
|
42
|
-
.with(Option.P.Some(
|
|
57
|
+
.with(Option.P.Some("CardOnly"), () => ({
|
|
43
58
|
...fraudDetails,
|
|
44
|
-
...
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
...fraudCardDetails,
|
|
60
|
+
}))
|
|
61
|
+
.with(Option.P.Some("Mixed"), () => ({
|
|
62
|
+
...fraudDetails,
|
|
63
|
+
...fraudCardDetails,
|
|
64
|
+
...fraudTransferDetails,
|
|
47
65
|
}))
|
|
48
66
|
.with(Option.P.Some("TransferOnly"), () => ({
|
|
49
67
|
...fraudDetails,
|
|
68
|
+
...fraudTransferDetails,
|
|
50
69
|
...toFilled(values.victimAccountMembershipId)
|
|
51
70
|
.map(value => ({ victimAccountMembershipId: value }))
|
|
52
71
|
.toUndefined(),
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FraudReportFormValues } from "./toInput";
|
|
2
|
+
export type TransferAction = "BankOrBeneficiary" | "Police";
|
|
3
|
+
type TransferValues = Pick<FraudReportFormValues, "hasContactedBankOrBeneficiary" | "hasFiledPoliceComplaint">;
|
|
4
|
+
export declare const getTransferActions: ({ hasContactedBankOrBeneficiary, hasFiledPoliceComplaint, }: TransferValues) => TransferAction[];
|
|
5
|
+
export declare const toTransferValues: (actions: TransferAction[]) => TransferValues;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const getTransferActions = ({ hasContactedBankOrBeneficiary, hasFiledPoliceComplaint, }) => [
|
|
2
|
+
...(hasContactedBankOrBeneficiary === true ? ["BankOrBeneficiary"] : []),
|
|
3
|
+
...(hasFiledPoliceComplaint === true ? ["Police"] : []),
|
|
4
|
+
];
|
|
5
|
+
export const toTransferValues = (actions) => ({
|
|
6
|
+
hasContactedBankOrBeneficiary: actions.includes("BankOrBeneficiary") ? true : undefined,
|
|
7
|
+
hasFiledPoliceComplaint: actions.includes("Police") ? true : undefined,
|
|
8
|
+
});
|
|
@@ -4,7 +4,7 @@ export type FraudsterChannel = "Email" | "Sms" | "Phone" | "Website" | "Applicat
|
|
|
4
4
|
export type SharedInformationWithFraudster = "SwanPasscode" | "PartnerPassword" | "VerificationCode" | "PersonalInformation" | "CardDetails" | "BankDetails" | "Other" | "None";
|
|
5
5
|
export type DisputeCaseStatus = "Draft" | "Expired" | "Canceled" | "Submitted";
|
|
6
6
|
export type DisputeCaseTransactionNotReportableReason = "TransactionTypeNotReportable" | "TransactionStatusNotReportable";
|
|
7
|
-
export type FraudReportDocumentPurpose = "PoliceReport" | "FraudEvidence" | "DisputeCorrespondence" | "
|
|
7
|
+
export type FraudReportDocumentPurpose = "PoliceReport" | "FraudEvidence" | "DisputeCorrespondence" | "Other";
|
|
8
8
|
export type SupportingDocumentCollectionStatus = "WaitingForDocument" | "PendingReview" | "Approved" | "Canceled" | "Rejected";
|
|
9
9
|
export type FraudDetailsInput = {
|
|
10
10
|
reportedReason: FraudReason;
|
package/src/utils/validation.js
CHANGED
|
@@ -48,7 +48,7 @@ const TAX_NUMBER_REGEX = {
|
|
|
48
48
|
message: t("common.form.help.nbCharacters", { nbCharacters: "9" }),
|
|
49
49
|
},
|
|
50
50
|
FIN: {
|
|
51
|
-
pattern:
|
|
51
|
+
pattern: /^\d{6}[-+A-FU-Y]\d{3}[0-9A-FHJ-NPR-Y]$/i,
|
|
52
52
|
message: t("common.form.help.nbCharacters", { nbCharacters: "11" }),
|
|
53
53
|
},
|
|
54
54
|
FRA: {
|