elixirs / faker

Faker is a pure Elixir library for generating fake data.
MIT License
1.04k stars 213 forks source link

Faker.Phone.EnUs.phone() produces invalid phone numbers #414

Open icecapp opened 2 years ago

icecapp commented 2 years ago

This is most likely known/expected, but un(der?)documented.

After investigating why my test suite started sporadically failing, I discovered that Faker.Phone.EnUs.phone() often produces invalid numbers.

to demonstrate:

def test_faker_us_phone_numbers()
    Faker.Phone.EnUs.phone() 
    |> ExPhoneNumber.parse("US")
    |> ExPhoneNumber.is_valid_number?
end
iex(24)> Auth.test_faker_us_phone_numbers()
914/967-0531 is valid: true
iex(25)> Auth.test_faker_us_phone_numbers()
6237465431 is valid: true
iex(26)> Auth.test_faker_us_phone_numbers()
232-341-9001 is valid: false
iex(27)> Auth.test_faker_us_phone_numbers()
368.551.0368 is valid: false
iex(28)> Auth.test_faker_us_phone_numbers()
6063538095 is valid: true
iex(29)> Auth.test_faker_us_phone_numbers()
974.733.0044 is valid: false
iex(30)> Auth.test_faker_us_phone_numbers()
(963) 718-4753 is valid: false
iex(31)> Auth.test_faker_us_phone_numbers()
(949) 625-0125 is valid: true
iex(32)> Auth.test_faker_us_phone_numbers()
253.921.0196 is valid: true

For example, it can produce (963) 718-4753 which will never exist.

I understand maintaining an area code map is work, so perhaps just warning that this can conflict with validation libraries that do keep up-to-date (or try, as even "368" in iex(27) just got added May 2021)

kristinabrueva commented 2 years ago

Hi @icecapp thank you for your bug report. @igas I'd like to take a look at this one.

igas commented 2 years ago

Thank you @Bruuu. Your help is much appreciated.