1- import { isValidSwissIbanNumber , isValidSwissSocialInsuranceNumber , formatSwissIbanNumber } from "./swissStandards" ;
1+ import { isValidSwissIbanNumber , isValidSwissSocialInsuranceNumber , tryParseSwissIbanNumber } from "./swissStandards" ;
22
33describe ( "Swiss standards test" , ( ) => {
44 test . each ( [
@@ -12,7 +12,7 @@ describe("Swiss standards test", () => {
1212 [ "ch93 0076 2011 6238 5295 7" , false ] ,
1313 [ "c93 0076 2011 6238 5295 7" , false ] ,
1414 [ "DE93 0076 2011 6238 5295 7" , false ] ,
15- ] ) ( "check if the swiss IBAN number is valid or not" , ( iBanNumberToCheck , expected ) => {
15+ ] ) ( "check if the Swiss IBAN number is valid or not" , ( iBanNumberToCheck , expected ) => {
1616 expect ( isValidSwissIbanNumber ( iBanNumberToCheck ) ) . toBe ( expected ) ;
1717 } ) ;
1818
@@ -25,7 +25,7 @@ describe("Swiss standards test", () => {
2525 [ "DE34 0076 2ABC 123D EF45 3" , false ] ,
2626 [ "CH34 0076 2ABC 123D EF45 \n6" , false ] ,
2727 [ "CH34 0076 2ABC 123D EF45 !" , false ] ,
28- ] ) ( "check if the siwss IBAN number with letters is valid or not" , ( iBanNumberToCheck , expected ) => {
28+ ] ) ( "check if the Swiss IBAN number with letters is valid or not" , ( iBanNumberToCheck , expected ) => {
2929 expect ( isValidSwissIbanNumber ( iBanNumberToCheck ) ) . toBe ( expected ) ;
3030 } ) ;
3131
@@ -45,18 +45,44 @@ describe("Swiss standards test", () => {
4545 } ) ;
4646
4747 test . each ( [
48- [ null as unknown as string , null , false ] ,
49- [ undefined as unknown as string , undefined , false ] ,
50- [ "CH9300762011623852957" , "CH93 0076 2011 6238 5295 7" , true ] ,
51- [ "ch9300762011623852957" , "CH93 0076 2011 6238 5295 7" , true ] ,
52- [ "ch9301234567891011127" , "CH93 0123 4567 8910 1112 7" , false ] ,
53- [ "DE93 00 76 2011 62385295 7" , "DE93 00 76 2011 62385295 7" , false ] ,
54- [ "D 93 00 76 2011 62385295 7" , "D 93 00 76 2011 62385295 7" , false ] ,
55- [ "Ch 93 0076 20 1 162385 295 7" , "CH93 0076 2011 6238 5295 7" , true ] ,
56- ] ) ( "Check if the IBAN number gets formatted correctly" , ( unformattedIbanNumber , expectedIbanNumber , expectedIsValid ) => {
57- const result = formatSwissIbanNumber ( unformattedIbanNumber ) ;
58-
59- expect ( result . ibanNumber ) . toBe ( expectedIbanNumber ) ;
60- expect ( result . isValidSwissIbanNumber ) . toBe ( expectedIsValid ) ;
48+ [ null as unknown as string , { isValid : false , iban : undefined , ibanFormatted : undefined } ] ,
49+ [ undefined as unknown as string , { isValid : false , iban : undefined , ibanFormatted : undefined } ] ,
50+ [ "" , { isValid : false , iban : undefined , ibanFormatted : undefined } ] ,
51+ [ "CH94 0076 2011 6238 5295 7" , { isValid : false , iban : undefined , ibanFormatted : undefined } ] ,
52+ [ "CH1000000ABC123DEF456" , { isValid : false , iban : undefined , ibanFormatted : undefined } ] ,
53+ [
54+ "CH9300762011623852957" ,
55+ {
56+ isValid : true ,
57+ iban : "CH9300762011623852957" ,
58+ ibanFormatted : "CH93 0076 2011 6238 5295 7" ,
59+ } ,
60+ ] ,
61+ [
62+ "CH3400762ABC123DEF456" ,
63+ {
64+ isValid : true ,
65+ iban : "CH3400762ABC123DEF456" ,
66+ ibanFormatted : "CH34 0076 2ABC 123D EF45 6" ,
67+ } ,
68+ ] ,
69+ [
70+ "CH93 0076 2011 6238 5295 7" ,
71+ {
72+ isValid : true ,
73+ iban : "CH9300762011623852957" ,
74+ ibanFormatted : "CH93 0076 2011 6238 5295 7" ,
75+ } ,
76+ ] ,
77+ [
78+ "CH34 0076 2ABC 123D EF45 6" ,
79+ {
80+ isValid : true ,
81+ iban : "CH3400762ABC123DEF456" ,
82+ ibanFormatted : "CH34 0076 2ABC 123D EF45 6" ,
83+ } ,
84+ ] ,
85+ ] ) ( "check if the Swiss IBAN number gets parsed correctly" , ( unformattedSwissIbanNumber , expected ) => {
86+ expect ( tryParseSwissIbanNumber ( unformattedSwissIbanNumber ) ) . toEqual ( expected ) ;
6187 } ) ;
6288} ) ;
0 commit comments