commons_yellowme 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +12 -0
  5. data/Gemfile.lock +234 -0
  6. data/bin/test +5 -0
  7. data/commons.gemspec +43 -0
  8. data/lib/commons/version.rb +1 -1
  9. data/spec/commons/authentication/authenticate_by_jwt_spec.rb +37 -0
  10. data/spec/commons/authentication/json_web_token_spec.rb +41 -0
  11. data/spec/commons/concerns/attributes/sex_spec.rb +24 -0
  12. data/spec/commons/concerns/extensions/deleted_spec.rb +42 -0
  13. data/spec/commons/concerns/guard/capitalizable_spec.rb +13 -0
  14. data/spec/commons/concerns/validations/undestroyable_spec.rb +9 -0
  15. data/spec/commons/errors/bad_request_spec.rb +62 -0
  16. data/spec/commons/errors/conflict_spec.rb +62 -0
  17. data/spec/commons/errors/forbidden_spec.rb +62 -0
  18. data/spec/commons/errors/internal_server_error_spec.rb +62 -0
  19. data/spec/commons/errors/invalid_resource_spec.rb +62 -0
  20. data/spec/commons/errors/maintenance_mode_spec.rb +49 -0
  21. data/spec/commons/errors/missing_parameter_spec.rb +49 -0
  22. data/spec/commons/errors/not_unique_spec.rb +62 -0
  23. data/spec/commons/errors/payment_required_spec.rb +62 -0
  24. data/spec/commons/errors/precondition_failed_spec.rb +62 -0
  25. data/spec/commons/errors/resource_not_found_spec.rb +49 -0
  26. data/spec/commons/errors/route_not_found_spec.rb +49 -0
  27. data/spec/commons/errors/unauthorized_spec.rb +62 -0
  28. data/spec/commons/errors/unprocessable_entity_spec.rb +62 -0
  29. data/spec/commons/formatter/e164_phone_spec.rb +155 -0
  30. data/spec/commons/formatter/regex_constants_spec.rb +102 -0
  31. data/spec/commons/formatter/string_utils_spec.rb +19 -0
  32. data/spec/commons/repositories/base_repository_spec.rb +504 -0
  33. data/spec/commons/repositories/catalogs/base_catalog_spec.rb +55 -0
  34. data/spec/commons/serializers/bad_request_spec.rb +46 -0
  35. data/spec/commons/serializers/conflict_spec.rb +46 -0
  36. data/spec/commons/serializers/forbidden_spec.rb +46 -0
  37. data/spec/commons/serializers/internal_server_error_spec.rb +46 -0
  38. data/spec/commons/serializers/invalid_resource_spec.rb +46 -0
  39. data/spec/commons/serializers/maintenance_mode_spec.rb +46 -0
  40. data/spec/commons/serializers/missing_parameter_spec.rb +44 -0
  41. data/spec/commons/serializers/not_unique_spec.rb +46 -0
  42. data/spec/commons/serializers/payment_required_spec.rb +46 -0
  43. data/spec/commons/serializers/precondition_failed_spec.rb +46 -0
  44. data/spec/commons/serializers/route_not_found_spec.rb +46 -0
  45. data/spec/commons/serializers/unauthorized_spec.rb +46 -0
  46. data/spec/commons/serializers/unprocessable_entity_spec.rb +46 -0
  47. data/spec/commons/shared-examples/user_spec.rb +18 -0
  48. data/spec/dummy/.ruby-version +1 -0
  49. data/spec/dummy/Rakefile +6 -0
  50. data/spec/dummy/app/assets/config/manifest.js +2 -0
  51. data/spec/dummy/app/assets/images/.keep +0 -0
  52. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  53. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  54. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  55. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  56. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  57. data/spec/dummy/app/controllers/miscellaneous_controller.rb +13 -0
  58. data/spec/dummy/app/errors/default_handling.rb +35 -0
  59. data/spec/dummy/app/errors/error_notifier.rb +12 -0
  60. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  61. data/spec/dummy/app/javascript/packs/application.js +15 -0
  62. data/spec/dummy/app/jobs/application_job.rb +7 -0
  63. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  64. data/spec/dummy/app/models/application_record.rb +3 -0
  65. data/spec/dummy/app/models/catalogs/application_parameter.rb +6 -0
  66. data/spec/dummy/app/models/concerns/.keep +0 -0
  67. data/spec/dummy/app/models/employee.rb +3 -0
  68. data/spec/dummy/app/models/user.rb +16 -0
  69. data/spec/dummy/app/repositories/catalogs/application_parameter_repository.rb +4 -0
  70. data/spec/dummy/app/repositories/employee_repository.rb +2 -0
  71. data/spec/dummy/app/repositories/user_repository.rb +2 -0
  72. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  73. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  74. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  75. data/spec/dummy/bin/rails +4 -0
  76. data/spec/dummy/bin/rake +4 -0
  77. data/spec/dummy/bin/setup +33 -0
  78. data/spec/dummy/config.ru +5 -0
  79. data/spec/dummy/config/application.rb +29 -0
  80. data/spec/dummy/config/boot.rb +5 -0
  81. data/spec/dummy/config/cable.yml +10 -0
  82. data/spec/dummy/config/database.yml +25 -0
  83. data/spec/dummy/config/environment.rb +5 -0
  84. data/spec/dummy/config/environments/development.rb +62 -0
  85. data/spec/dummy/config/environments/production.rb +112 -0
  86. data/spec/dummy/config/environments/test.rb +48 -0
  87. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  88. data/spec/dummy/config/initializers/assets.rb +12 -0
  89. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  90. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  91. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  92. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  93. data/spec/dummy/config/initializers/inflections.rb +16 -0
  94. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  95. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  96. data/spec/dummy/config/locales/en.yml +33 -0
  97. data/spec/dummy/config/puma.rb +38 -0
  98. data/spec/dummy/config/routes.rb +9 -0
  99. data/spec/dummy/config/spring.rb +6 -0
  100. data/spec/dummy/config/storage.yml +34 -0
  101. data/spec/dummy/db/migrate/20191212233443_create_user.rb +13 -0
  102. data/spec/dummy/db/migrate/20191213072543_create_application_parameters.rb +8 -0
  103. data/spec/dummy/db/migrate/20200101204534_create_employee.rb +8 -0
  104. data/spec/dummy/db/schema.rb +35 -0
  105. data/spec/dummy/lib/assets/.keep +0 -0
  106. data/spec/dummy/log/.keep +0 -0
  107. data/spec/dummy/public/404.html +67 -0
  108. data/spec/dummy/public/422.html +67 -0
  109. data/spec/dummy/public/500.html +66 -0
  110. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  111. data/spec/dummy/public/apple-touch-icon.png +0 -0
  112. data/spec/dummy/public/favicon.ico +0 -0
  113. data/spec/factories/catalogs/application_parameters.rb +6 -0
  114. data/spec/factories/employees.rb +6 -0
  115. data/spec/factories/users.rb +7 -0
  116. data/spec/rails_helper.rb +68 -0
  117. data/spec/spec_helper.rb +104 -0
  118. data/spec/support/.DS_Store +0 -0
  119. data/spec/support/shared-examples/capitalizable.rb +16 -0
  120. data/spec/support/shared-examples/deletable.rb +39 -0
  121. data/spec/support/shared-examples/dimorphic.rb +28 -0
  122. data/spec/support/shared-examples/stripable.rb +17 -0
  123. data/spec/support/shared-examples/undestroyable.rb +8 -0
  124. metadata +240 -3
@@ -0,0 +1,62 @@
1
+ describe Commons::Errors::PaymentRequired do
2
+ describe 'handle_error' do
3
+ context 'works with no message or validation_errors' do
4
+ it do
5
+ expect do
6
+ raise described_class
7
+ end.to raise_error(described_class)
8
+ end
9
+ end
10
+
11
+ context 'default values works ok' do
12
+ subject { described_class.new }
13
+
14
+ it do
15
+ expect do
16
+ raise subject
17
+ end.to raise_error(described_class)
18
+ end
19
+ it { expect(subject.detail).to eq I18n.t('status_code.IER4009_payment_required.detail') }
20
+ end
21
+
22
+ context 'works with message but no validation_errors' do
23
+ let(:message) { 'my totally non-existent message' }
24
+
25
+ subject { described_class.new(message) }
26
+
27
+ it do
28
+ expect do
29
+ raise subject
30
+ end.to raise_error(described_class)
31
+ end
32
+ it { expect(subject.message).to eq message }
33
+ end
34
+
35
+ context 'works with message & validation_errors' do
36
+ let(:message) { 'my totally non-existent message' }
37
+ let(:detail) { { errors: 'my totally non-existent error' } }
38
+
39
+ subject { described_class.new(message, nil, detail: detail) }
40
+
41
+ it do
42
+ expect do
43
+ raise subject
44
+ end.to raise_error(described_class)
45
+ end
46
+ it { expect(subject.detail).to eq detail }
47
+ end
48
+
49
+ context 'works with message & backtrace' do
50
+ let(:message) { 'my totally non-existent message' }
51
+
52
+ subject { described_class.new(message, [message]) }
53
+
54
+ it do
55
+ expect do
56
+ raise subject
57
+ end.to raise_error(described_class)
58
+ end
59
+ it { expect(subject.backtrace).to eq [message] }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,62 @@
1
+ describe Commons::Errors::PreconditionFailed do
2
+ describe 'handle_error' do
3
+ context 'works with no message or validation_errors' do
4
+ it do
5
+ expect do
6
+ raise described_class
7
+ end.to raise_error(described_class)
8
+ end
9
+ end
10
+
11
+ context 'default values works ok' do
12
+ subject { described_class.new }
13
+
14
+ it do
15
+ expect do
16
+ raise subject
17
+ end.to raise_error(described_class)
18
+ end
19
+ it { expect(subject.detail).to eq I18n.t('status_code.IER4010_precondition_failed.detail') }
20
+ end
21
+
22
+ context 'works with message but no validation_errors' do
23
+ let(:message) { 'my totally non-existent message' }
24
+
25
+ subject { described_class.new(message) }
26
+
27
+ it do
28
+ expect do
29
+ raise subject
30
+ end.to raise_error(described_class)
31
+ end
32
+ it { expect(subject.message).to eq message }
33
+ end
34
+
35
+ context 'works with message & validation_errors' do
36
+ let(:message) { 'my totally non-existent message' }
37
+ let(:detail) { { errors: 'my totally non-existent error' } }
38
+
39
+ subject { described_class.new(message, nil, detail: detail) }
40
+
41
+ it do
42
+ expect do
43
+ raise subject
44
+ end.to raise_error(described_class)
45
+ end
46
+ it { expect(subject.detail).to eq detail }
47
+ end
48
+
49
+ context 'works with message & backtrace' do
50
+ let(:message) { 'my totally non-existent message' }
51
+
52
+ subject { described_class.new(message, [message]) }
53
+
54
+ it do
55
+ expect do
56
+ raise subject
57
+ end.to raise_error(described_class)
58
+ end
59
+ it { expect(subject.backtrace).to eq [message] }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,49 @@
1
+ describe Commons::Errors::ResourceNotFound do
2
+ describe 'handle_error' do
3
+ context 'works with no message or validation_errors' do
4
+ it do
5
+ expect do
6
+ raise described_class
7
+ end.to raise_error(described_class)
8
+ end
9
+ end
10
+
11
+ context 'default values works ok' do
12
+ subject { described_class.new }
13
+
14
+ it do
15
+ expect do
16
+ raise subject
17
+ end.to raise_error(described_class)
18
+ end
19
+ it { expect(subject.detail).to eq I18n.t('status_code.IER4011_resource_not_found.detail') }
20
+ end
21
+
22
+ context 'works with message but no validation_errors' do
23
+ let(:message) { 'my totally non-existent message' }
24
+
25
+ subject { described_class.new(message) }
26
+
27
+ it do
28
+ expect do
29
+ raise subject
30
+ end.to raise_error(described_class)
31
+ end
32
+ it { expect(subject.message).to eq message }
33
+ end
34
+
35
+ context 'works with message & validation_errors' do
36
+ let(:message) { 'my totally non-existent message' }
37
+ let(:detail) { { errors: 'my totally non-existent error' } }
38
+
39
+ subject { described_class.new(message, detail: detail) }
40
+
41
+ it do
42
+ expect do
43
+ raise subject
44
+ end.to raise_error(described_class)
45
+ end
46
+ it { expect(subject.detail).to eq detail }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,49 @@
1
+ describe Commons::Errors::RouteNotFound do
2
+ describe 'handle_error' do
3
+ context 'works with no message or validation_errors' do
4
+ it do
5
+ expect do
6
+ raise described_class
7
+ end.to raise_error(described_class)
8
+ end
9
+ end
10
+
11
+ context 'default values works ok' do
12
+ subject { described_class.new }
13
+
14
+ it do
15
+ expect do
16
+ raise subject
17
+ end.to raise_error(described_class)
18
+ end
19
+ it { expect(subject.detail).to eq I18n.t('status_code.IER4001_route_not_found.detail') }
20
+ end
21
+
22
+ context 'works with message but no validation_errors' do
23
+ let(:message) { 'my totally non-existent message' }
24
+
25
+ subject { described_class.new(message) }
26
+
27
+ it do
28
+ expect do
29
+ raise subject
30
+ end.to raise_error(described_class)
31
+ end
32
+ it { expect(subject.message).to eq message }
33
+ end
34
+
35
+ context 'works with message & validation_errors' do
36
+ let(:message) { 'my totally non-existent message' }
37
+ let(:detail) { { errors: 'my totally non-existent error' } }
38
+
39
+ subject { described_class.new(message, detail: detail) }
40
+
41
+ it do
42
+ expect do
43
+ raise subject
44
+ end.to raise_error(described_class)
45
+ end
46
+ it { expect(subject.detail).to eq detail }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,62 @@
1
+ describe Commons::Errors::Unauthorized do
2
+ describe 'handle_error' do
3
+ context 'works with no message or validation_errors' do
4
+ it do
5
+ expect do
6
+ raise described_class
7
+ end.to raise_error(described_class)
8
+ end
9
+ end
10
+
11
+ context 'default values works ok' do
12
+ subject { described_class.new }
13
+
14
+ it do
15
+ expect do
16
+ raise subject
17
+ end.to raise_error(described_class)
18
+ end
19
+ it { expect(subject.detail).to eq I18n.t('status_code.IER4002_unauthorized.detail') }
20
+ end
21
+
22
+ context 'works with message but no validation_errors' do
23
+ let(:message) { 'my totally non-existent message' }
24
+
25
+ subject { described_class.new(message) }
26
+
27
+ it do
28
+ expect do
29
+ raise subject
30
+ end.to raise_error(described_class)
31
+ end
32
+ it { expect(subject.message).to eq message }
33
+ end
34
+
35
+ context 'works with message & validation_errors' do
36
+ let(:message) { 'my totally non-existent message' }
37
+ let(:detail) { { errors: 'my totally non-existent error' } }
38
+
39
+ subject { described_class.new(message, nil, detail: detail) }
40
+
41
+ it do
42
+ expect do
43
+ raise subject
44
+ end.to raise_error(described_class)
45
+ end
46
+ it { expect(subject.detail).to eq detail }
47
+ end
48
+
49
+ context 'works with message & backtrace' do
50
+ let(:message) { 'my totally non-existent message' }
51
+
52
+ subject { described_class.new(message, [message]) }
53
+
54
+ it do
55
+ expect do
56
+ raise subject
57
+ end.to raise_error(described_class)
58
+ end
59
+ it { expect(subject.backtrace).to eq [message] }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,62 @@
1
+ describe Commons::Errors::UnprocessableEntity do
2
+ describe 'handle_error' do
3
+ context 'works with no message or validation_errors' do
4
+ it do
5
+ expect do
6
+ raise described_class
7
+ end.to raise_error(described_class)
8
+ end
9
+ end
10
+
11
+ context 'default values works ok' do
12
+ subject { described_class.new }
13
+
14
+ it do
15
+ expect do
16
+ raise subject
17
+ end.to raise_error(described_class)
18
+ end
19
+ it { expect(subject.detail).to eq I18n.t('status_code.IER4222_unprocessable_entity.detail') }
20
+ end
21
+
22
+ context 'works with message but no validation_errors' do
23
+ let(:message) { 'my totally non-existent message' }
24
+
25
+ subject { described_class.new(message) }
26
+
27
+ it do
28
+ expect do
29
+ raise subject
30
+ end.to raise_error(described_class)
31
+ end
32
+ it { expect(subject.message).to eq message }
33
+ end
34
+
35
+ context 'works with message & validation_errors' do
36
+ let(:message) { 'my totally non-existent message' }
37
+ let(:detail) { { errors: 'my totally non-existent error' } }
38
+
39
+ subject { described_class.new(message, nil, detail: detail) }
40
+
41
+ it do
42
+ expect do
43
+ raise subject
44
+ end.to raise_error(described_class)
45
+ end
46
+ it { expect(subject.detail).to eq detail }
47
+ end
48
+
49
+ context 'works with message & backtrace' do
50
+ let(:message) { 'my totally non-existent message' }
51
+
52
+ subject { described_class.new(message, [message]) }
53
+
54
+ it do
55
+ expect do
56
+ raise subject
57
+ end.to raise_error(described_class)
58
+ end
59
+ it { expect(subject.backtrace).to eq [message] }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,155 @@
1
+ def phone_list
2
+ [
3
+ { phone: '+1 (415) 555-3695', format: '+14155553695', custom_format: nil },
4
+ { phone: '5345 8120', format: "+5353458120", custom_format: nil },
5
+ { phone: '898 5754', format: nil, custom_format: nil }, # local
6
+ { phone: '208 516 7431', format: nil, custom_format: nil }, # USA pero sin +1
7
+ { phone: '+57 301 2665494', format: '+573012665494', custom_format: nil }, # Colombia
8
+ { phone: '+54 9 342 429 8094', format: '+5493424298094', custom_format: nil }, # Argentina móvil
9
+ { phone: '+1 712-269-8405', format: '+17122698405', custom_format: nil },
10
+ { phone: '+52 998 260 0303', format: '+529982600303', custom_format: '+529982600303' },
11
+ { phone: '+52 998 260 0550', format: '+529982600550', custom_format: '+529982600550' },
12
+ { phone: '999 227 4887', format: '+529992274887', custom_format: '+529992274887' },
13
+ { phone: '998 260 0550', format: '+529982600550', custom_format: '+529982600550' },
14
+ { phone: '998 260 0303', format: '+529982600303', custom_format: '+529982600303' },
15
+ # El siguiente número es USA pero sin +1 pasa todas las validaciones, es un falso positivo
16
+ { phone: '712-269-8405', format: '+527122698405', custom_format: '+527122698405' },
17
+ { phone: '999 926 3252', format: '+529999263252', custom_format: '+529999263252' }, # MX local
18
+ { phone: '998-898-5754', format: '+529988985754', custom_format: '+529988985754' },
19
+ { phone: '722.196.0105', format: '+527221960105', custom_format: '+527221960105' },
20
+ # Número de USA pero sin (+)
21
+ { phone: '1832 928 5078', format: '+528329285078', custom_format: nil },
22
+ { phone: '+1 (972) 3636278', format: '+19723636278', custom_format: nil },
23
+ { phone: '+ 1 (832) 928 5078', format: '+18329285078', custom_format: nil },
24
+ { phone: '8880178769', format: '+528880178769', custom_format: '+528880178769' },
25
+ { phone: '+5218880178769', format: '+528880178769', custom_format: '+528880178769' },
26
+ ]
27
+ end
28
+
29
+ RSpec.describe Commons::Formatter::E164Phone do
30
+ describe 'valid for México' do
31
+ phone_list.each do |testCase|
32
+ context "number #{testCase[:phone]}" do
33
+ formatter = Commons::Formatter::E164Phone.new(testCase[:phone])
34
+ formatted_phone = formatter.format
35
+ it { expect(formatted_phone).to eq testCase[:format] }
36
+ end
37
+ end
38
+ end
39
+
40
+ context 'with valid phone numbers' do
41
+ test_cases = [
42
+ { phone: '(999)1485541', result: '+529991485541' },
43
+ { phone: '+5219991485541', result: '+529991485541' },
44
+ { phone: '999 1 48 55 41', result: '+529991485541' },
45
+ { phone: '999-1-48-55-41', result: '+529991485541' },
46
+ { phone: '+529991485541', result: '+529991485541' },
47
+ { phone: '019991485541', result: '+529991485541' },
48
+ { phone: '019991485541', result: '+529991485541' },
49
+ ]
50
+
51
+ test_cases.each do |test_case|
52
+ context "number #{test_case[:phone]}" do
53
+ subject { Commons::Formatter::E164Phone.new(test_case[:phone]) }
54
+
55
+ it { expect(subject.format).to eq test_case[:result] }
56
+ end
57
+ end
58
+ end
59
+
60
+ context 'invalid phone numbers' do
61
+ test_cases = [
62
+ { phone: ')' },
63
+ { phone: '()' },
64
+ { phone: '' },
65
+ ]
66
+
67
+ test_cases.each do |test_case|
68
+ context "number #{test_case[:phone]}" do
69
+ subject { Commons::Formatter::E164Phone.new(test_case[:phone]) }
70
+
71
+ it { expect(subject.format).to be_nil }
72
+ end
73
+ end
74
+ end
75
+
76
+ context 'format_national works ok!' do
77
+ test_cases = [
78
+ { phone: '9991485541', result: '9991485541' },
79
+ { phone: '(999)1485541', result: '9991485541' },
80
+ { phone: '+5219991485541', result: '9991485541' },
81
+ { phone: '999 1 48 55 41', result: '9991485541' },
82
+ { phone: '999-1-48-55-41', result: '9991485541' },
83
+ { phone: '+529991485541', result: '9991485541' },
84
+ { phone: '019991485541', result: '9991485541' },
85
+ { phone: '019991485541', result: '9991485541' },
86
+ ]
87
+
88
+ test_cases.each do |test_case|
89
+ context "number #{test_case[:phone]}" do
90
+ subject { Commons::Formatter::E164Phone.new(test_case[:phone]) }
91
+
92
+ it { expect(subject.format_national).to eq test_case[:result] }
93
+ end
94
+ end
95
+ end
96
+
97
+ context 'format_extension works ok!' do
98
+ test_cases = [
99
+ { phone: '+5219991485541', result: '52' },
100
+ { phone: '+529991485541', result: '52' },
101
+ { phone: '+1 (972) 3636278', result: '1' },
102
+ { phone: '+ 1 (832) 928 5078', result: '1' },
103
+ { phone: '+57 301 2665494', result: '57' },
104
+ { phone: '+54 9 342 429 8094', result: '54' },
105
+ ]
106
+
107
+ test_cases.each do |test_case|
108
+ context "number #{test_case[:phone]}" do
109
+ subject { Commons::Formatter::E164Phone.new(test_case[:phone]) }
110
+
111
+ it { expect(subject.country_code).to eq test_case[:result] }
112
+ end
113
+ end
114
+ end
115
+
116
+ describe 'canonical_phone' do
117
+ context 'matches valid phones' do
118
+ test_cases = [
119
+ { phone: '+5219991485541', result: '9991485541' },
120
+ { phone: '+529991485541', result: '9991485541' },
121
+ { phone: '9723636278', result: '9723636278' },
122
+ { phone: ' (832) 928 5078', result: '8329285078' },
123
+ { phone: '+52 301 2665494', result: '3012665494' },
124
+ { phone: '+52 342 429 8094', result: '3424298094' },
125
+ ]
126
+
127
+ test_cases.each do |test_case|
128
+ context "number #{test_case[:phone]}" do
129
+ subject { Commons::Formatter::E164Phone.canonical_phone(test_case[:phone]) }
130
+
131
+ it { expect(subject).to eq test_case[:result] }
132
+ end
133
+ end
134
+ end
135
+
136
+ context 'do not match invalid phones' do
137
+ test_cases = [
138
+ '+52219991485541',
139
+ '+5229991485541',
140
+ '+1 (972) 3636278',
141
+ '+ 1 (832) 928 5078',
142
+ '+57 301 2665494',
143
+ '+54 9 342 429 8094',
144
+ ]
145
+
146
+ test_cases.each do |test_case|
147
+ context "number #{test_case}" do
148
+ subject { Commons::Formatter::E164Phone.canonical_phone(test_case) }
149
+
150
+ it { expect(subject).to be_nil }
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end