forked from neolution-ch/javascript-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswissStandards.spec.ts
More file actions
61 lines (57 loc) · 3.1 KB
/
swissStandards.spec.ts
File metadata and controls
61 lines (57 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { isValidSwissIbanNumber, isValidSwissSocialInsuranceNumber, tryParseSwissIbanNumber } from "./swissStandards";
describe("Swiss standards test", () => {
test.each([
[null as unknown as string, false],
[undefined as unknown as string, false],
["CH9300762011623852957", true],
["CH93 0076 2011 6238 5295 7", true],
["CH930076 20116238 5295 7", false],
["CH93-0076-2011-6238-5295-7", false],
["CH93 0000 0000 0000 0000 1", false],
["ch93 0076 2011 6238 5295 7", false],
["c93 0076 2011 6238 5295 7", false],
["DE93 0076 2011 6238 5295 7", false],
])("check if the Swiss IBAN number is valid or not", (iBanNumberToCheck, expected) => {
expect(isValidSwissIbanNumber(iBanNumberToCheck)).toBe(expected);
});
test.each([
[null as unknown as string, false],
[undefined as unknown as string, false],
["CH3400762ABC123DEF456", true],
["CH34 0076 2ABC 123D EF45 6", true],
["Some random string", false],
["DE34 0076 2ABC 123D EF45 3", false],
["CH34 0076 2ABC 123D EF45 \n6", false],
["CH34 0076 2ABC 123D EF45 !", false],
])("check if the Swiss IBAN number with letters is valid or not", (iBanNumberToCheck, expected) => {
expect(isValidSwissIbanNumber(iBanNumberToCheck)).toBe(expected);
});
test.each([
[null as unknown as string, false],
[undefined as unknown as string, false],
["7561234567891", false],
["7569217076985", true],
["756.92170769.85", false],
["756.9217.0769.85", true],
["756..9217.0769.85", false],
["756.1234.5678.91", false],
["test756.9217.0769.85", false],
["7.56..9217...0769.85", false],
])("check if the social insurance number is valid or not", (swissSocialInsuranceNumber, expected) => {
expect(isValidSwissSocialInsuranceNumber(swissSocialInsuranceNumber)).toBe(expected);
});
test.each([
[null as unknown as string, { isValid: false, iban: undefined, ibanFormatted: undefined }],
[undefined as unknown as string, { isValid: false, iban: undefined, ibanFormatted: undefined }],
["", { isValid: false, iban: undefined, ibanFormatted: undefined }],
["CH94 0076 2011 6238 5295 7", { isValid: false, iban: undefined, ibanFormatted: undefined }],
["CH1000000ABC123DEF456", { isValid: false, iban: undefined, ibanFormatted: undefined }],
["CH93-0076,2011.6238\n5295\n7", { isValid: true, iban: "CH9300762011623852957", ibanFormatted: "CH93 0076 2011 6238 5295 7" }],
["CH9300762011623852957", { isValid: true, iban: "CH9300762011623852957", ibanFormatted: "CH93 0076 2011 6238 5295 7" }],
["CH3400762ABC123DEF456", { isValid: true, iban: "CH3400762ABC123DEF456", ibanFormatted: "CH34 0076 2ABC 123D EF45 6" }],
["CH93 0076 2011 6238 5295 7", { isValid: true, iban: "CH9300762011623852957", ibanFormatted: "CH93 0076 2011 6238 5295 7" }],
["CH34 0076 2ABC 123D EF45 6", { isValid: true, iban: "CH3400762ABC123DEF456", ibanFormatted: "CH34 0076 2ABC 123D EF45 6" }],
])("check if the Swiss IBAN number gets parsed correctly", (unformattedSwissIbanNumber, expected) => {
expect(tryParseSwissIbanNumber(unformattedSwissIbanNumber)).toEqual(expected);
});
});