-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated Discover to have acceptCoBranded flag for the range "622126-622925" #83
Conversation
@aloisdg All the tests pass in my local. Can you help me here? |
Alright, the code was not testing standard Discover card in co-branded case. Here is the generator: static member NextDiscover([<Optional; DefaultParameterValue(From16To19.Random)>] discoverLengthOption, [<Optional; DefaultParameterValue(true)>] acceptCoBranded: bool) =
let length =
match discoverLengthOption with
| From16To19.Random -> Cardizer.NextInRange 16 19
| _ -> int discoverLengthOption
let roll = Cardizer.next (if acceptCoBranded then 4 else 3)
let prefix =
match roll with
| 0 -> [ 6; 0; 1; 1 ]
| 1 -> [ 6; 5 ]
| 2 -> Cardizer.NextSeqInRange 644 649
| _ -> Cardizer.NextSeqInRange 622126 622925
Cardizer.GenerateCard prefix length and here is the testcases: [<Theory>]
[<InlineData(From16To19.Sixteen, 16)>]
[<InlineData(From16To19.Seventeen, 17)>]
[<InlineData(From16To19.Eighteen, 18)>]
[<InlineData(From16To19.Nineteen, 19)>]
let ``Should generate valid Discover`` length expectedLength =
let cardNotCobranded = Cardizer.NextDiscover(length, false)
let cardCobranded = Cardizer.NextDiscover(length, true)
let isPrefixValid (card: string) =
if card.StartsWith "65" || card.StartsWith "6011"
then true
else
let head = card.Substring(0, 3) |> int
(head >= 644 && head <= 649)
let headCobranded = cardCobranded.Substring(0, 6) |> int
let prefixCobranded = isPrefixValid cardCobranded || (headCobranded >= 622126 && headCobranded <= 622925)
let prefixNotCobranded = isPrefixValid cardNotCobranded
prefixCobranded |> should be True
prefixNotCobranded |> should be True
cardNotCobranded |> should haveLength expectedLength
cardNotCobranded |> luhn |> should be LuhnCheck
cardCobranded |> should haveLength expectedLength
cardCobranded |> luhn |> should be LuhnCheck |
Thanks :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to go
Fixes #80