-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2259 from internetee/2239-validate-contact-phone-…
…number Improved phone number validation
- Loading branch information
Showing
9 changed files
with
117 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module PhoneFormatHelperTest | ||
# https://en.wikipedia.org/wiki/E.164 | ||
def assert_phone_format(contact) | ||
contact.phone = '+.1' | ||
assert contact.invalid? | ||
|
||
contact.phone = '+123.' | ||
assert contact.invalid? | ||
|
||
contact.phone = '+1.123456789123456' | ||
assert contact.invalid? | ||
|
||
contact.phone = '+134.1234567891234' | ||
assert contact.invalid? | ||
|
||
contact.phone = '+000.1' | ||
assert contact.invalid? | ||
|
||
contact.phone = '+123.0' | ||
assert contact.invalid? | ||
|
||
contact.phone = '+1.2' | ||
assert contact.valid? | ||
|
||
contact.phone = '+123.4' | ||
assert contact.valid? | ||
|
||
contact.phone = '+1.12345678912345' | ||
assert contact.valid? | ||
|
||
contact.phone = '+134.123456789123' | ||
assert contact.valid? | ||
|
||
contact.phone = '+134.00000000' | ||
assert contact.invalid? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'test_helper' | ||
require 'helpers/phone_format_helper_test' | ||
|
||
class DeppContactTest < ActiveSupport::TestCase | ||
include PhoneFormatHelperTest | ||
|
||
setup do | ||
@depp_contact = Depp::Contact.new | ||
end | ||
|
||
def test_validates_phone_format | ||
assert_phone_format(@depp_contact) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'application_system_test_case' | ||
|
||
class RegistrarAreaContactTest < ApplicationSystemTestCase | ||
setup do | ||
@registrar = registrars(:bestnames) | ||
@contact = contacts(:john) | ||
sign_in users(:api_bestnames) | ||
end | ||
|
||
def test_creates_contact_with_invalid_phone | ||
visit registrar_contacts_path | ||
click_on 'New' | ||
|
||
fill_in 'Ident', with: @contact.ident | ||
fill_in 'Name', with: @contact.name | ||
fill_in 'E-mail', with: @contact.email | ||
fill_in 'Phone', with: '372' | ||
click_on 'Create' | ||
|
||
assert_text 'Phone number must be in +XXX.YYYYYYY format' | ||
end | ||
|
||
def test_updates_contact_with_invalid_phone | ||
depp_contact = Depp::Contact.new( | ||
id: @contact.id, | ||
name: @contact.name, | ||
code: @contact.code, | ||
email: @contact.email, | ||
phone: @contact.phone, | ||
ident: @contact.ident, | ||
ident_type: @contact.ident_type, | ||
ident_country_code: @contact.ident_country_code) | ||
|
||
Spy.on(Depp::Contact, :find_by_id).and_return(depp_contact) | ||
|
||
visit edit_registrar_contact_path(depp_contact.code) | ||
|
||
assert_text "Edit: #{depp_contact.name}" | ||
|
||
fill_in 'Phone', with: '372' | ||
click_on 'Save' | ||
|
||
assert_text 'Phone number must be in +XXX.YYYYYYY format' | ||
end | ||
end |