iban-ex/test/iban_ex_parser_test.exs

173 lines
5.3 KiB
Elixir

defmodule IbanExParserTest do
alias IbanEx.{Country, Iban, Parser}
use ExUnit.Case, async: true
@ibans [
"AL47212110090000000235698741",
"AD1200012030200359100100",
"AT611904300234573201",
"AZ21NABZ00000000137010001944",
"BH67BMAG00001299123456",
"BE68539007547034",
"BA391290079401028494",
"BR1800360305000010009795493C1",
"BG80BNBG96611020345678",
"CR05015202001026284066",
"HR1210010051863000160",
"CY17002001280000001200527600",
"CZ6508000000192000145399",
"DK5000400440116243",
"DO28BAGR00000001212453611324",
"EG380019000500000000263180002",
"SV62CENR00000000000000700025",
"EE382200221020145685",
"FO6264600001631634",
"FI2112345600000785",
"FR1420041010050500013M02606",
"GE29NB0000000101904917",
"DE89370400440532013000",
"GI75NWBK000000007099453",
"GR1601101250000000012300695",
"GL8964710001000206",
"GT82TRAJ01020000001210029690",
"HU42117730161111101800000000",
"IS140159260076545510730339",
"IE29AIBK93115212345678",
"IL620108000000099999999",
"IT60X0542811101000000123456",
"JO94CBJO0010000000000131000302",
"KZ86125KZT5004100100",
"XK051212012345678906",
"KW81CBKU0000000000001234560101",
"LV80BANK0000435195001",
"LB62099900000001001901229114",
"LI21088100002324013AA",
"LT121000011101001000",
"LU280019400644750000",
"MK07250120000058984",
"MT84MALT011000012345MTLCAST001S",
"MR1300020001010000123456753",
"MC5811222000010123456789030",
"ME25505000012345678951",
"NL91ABNA0417164300",
"NO9386011117947",
"PK36SCBL0000001123456702",
"PL61109010140000071219812874",
"PT50000201231234567890154",
"QA58DOHB00001234567890ABCDEFG",
"MD24AG000225100013104168",
"RO49AAAA1B31007593840000",
"SM86U0322509800000000270100",
"SA0380000000608010167519",
"RS35260005601001611379",
"SK3112000000198742637541",
"SI56263300012039086",
"ES9121000418450200051332",
"SE4550000000058398257466",
"CH9300762011623852957",
"TL380080012345678910157",
"TR330006100519786457841326",
"UA213223130000026007233566001",
"AE070331234567890123456",
"GB29NWBK60161331926819",
"VA59001123000012345678",
"VG96VPVG0000012345678901"
]
test "parsing valid IBANs from available countries returns {:ok, %IbanEx.Iban{}}" do
Enum.all?(@ibans, fn iban ->
iban_country =
iban
|> String.upcase()
|> String.slice(0..1)
result =
case {Country.is_country_code_supported?(iban_country), Parser.parse(iban)} do
{true, {:ok, %Iban{}}} ->
true
_ ->
false
end
assert(result, iban)
end)
end
test "parsing invalid IBANs from unavailable countries returns {:error, :unsupported_country_code}" do
invalid_ibans =
[
# Fake country codes
"SD3112000000198742637541",
"SU56263300012039086",
"ZZ9121000418450200051332",
"FU4550000000058398257466",
"GF9300762011623852957",
"FX380080012345678910157",
"RT330006100519786457841326",
"UL213223130000026007233566001",
"AP070331234567890123456",
"FF29NWBK60161331926819",
"VV59001123000012345678",
"GV96VPVG0000012345678901",
# Unsupported now by library
"AA0096VPVG0000012345",
"AO213223130000026",
"AX00213223130000026007",
"BF3112000000198742637541375",
"BI31120000001987",
"BJ31120000001987426375413750",
"BL3112000000198742637541375",
"BY31120000001987426375413754",
"CF3112000000198742637541375",
"CG3112000000198742637541375",
"CI31120000001987426375413750",
"CM3112000000198742637541375",
"CV31120000001987426375413",
"DJ3112000000198742637541375",
"DZ3112000000198742637541",
"GA3112000000198742637541375",
"GF3112000000198742637541375",
"GP3112000000198742637541375",
"GQ3112000000198742637541375",
"GW31120000001987426375413",
"HN31120000001987426375413759",
"IQ311200000019874263754",
"IR311200000019874263754137",
"KM3112000000198742637541375",
"LC311200000019874263754",
"MA31120000001987426375413750",
"MF3112000000198742637541375",
"MG3112000000198742637541375",
"ML31120000001987426375413750",
"MQ3112000000198742637541375",
"MU3112000000198742637541375000",
"MZ31120000001987426375413",
"NC3112000000198742637541375",
"NE31120000001987426375413750",
"NI311200000019874263754137500000",
"PF3112000000198742637541375",
"PM3112000000198742637541375",
"PS311200000019874263754137500",
"RE3112000000198742637541375",
"SC311200000019874263754137500000",
"SN31120000001987426375413750",
"ST31120000001987426375413",
"TD3112000000198742637541375",
"TF3112000000198742637541375",
"TG31120000001987426375413750",
"TN3112000000198742637541",
"WF3112000000198742637541375",
"YT3112000000198742637541375"
]
Enum.all?(
invalid_ibans,
&assert(
match?({:error, :unsupported_country_code}, Parser.parse(&1)),
"expected #{&1} to match {:error, :unsupported_country_code}"
)
)
end
end