addressfinder 1.10.0 → 1.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,207 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe AddressFinder::Bulk do
4
- before do
5
- AddressFinder.configure do |af|
6
- af.api_key = 'XXX'
7
- af.api_secret = 'YYY'
8
- af.default_country = 'nz'
9
- af.timeout = 5
10
- af.retries = 5
11
- end
12
- end
13
-
14
- describe '#perform' do
15
- let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
16
- let(:net_http){ http.send(:net_http) }
17
-
18
- before do
19
- WebMock.allow_net_connect!(net_http_connect_on_start: true)
20
- allow(http).to receive(:sleep)
21
- end
22
-
23
- after do
24
- WebMock.disable_net_connect!
25
- end
26
-
27
- context "with 3 requests in the provided block" do
28
- let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
29
- let(:block){
30
- Proc.new do |proxy|
31
- proxy.verification(q: "1 Willis")
32
- proxy.verification(q: "2 Willis")
33
- proxy.verification(q: "3 Willis")
34
- end
35
- }
36
-
37
- it "uses 1 http connection" do
38
- expect(net_http).to receive(:do_start).once.and_call_original
39
- expect(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
40
- expect(net_http).to receive(:do_finish).once.and_call_original
41
- AddressFinder::Bulk.new(http: http, verification_version: 'v2', default_country: 'au', &block).perform
42
- end
43
-
44
- it "calls the correct class with v2 verification and au default" do
45
- allow(net_http).to receive(:do_start).once.and_call_original
46
- allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
47
- allow(net_http).to receive(:do_finish).once.and_call_original
48
- expect(AddressFinder::V2::Au::Verification).to receive(:new).exactly(3).times.and_call_original
49
- AddressFinder::Bulk.new(http: http, verification_version: 'v2', default_country: 'au', &block).perform
50
- end
51
-
52
- it "calls the correct class with v2 verification and nz default" do
53
- allow(net_http).to receive(:do_start).once.and_call_original
54
- allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
55
- allow(net_http).to receive(:do_finish).once.and_call_original
56
- expect(AddressFinder::Verification).to receive(:new).exactly(3).times.and_call_original
57
- AddressFinder::Bulk.new(http: http, verification_version: 'v2', default_country: 'nz', &block).perform
58
- end
59
-
60
- it "calls the correct class without a verification version" do
61
- allow(net_http).to receive(:do_start).once.and_call_original
62
- allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
63
- allow(net_http).to receive(:do_finish).once.and_call_original
64
- expect(AddressFinder::Verification).to receive(:new).exactly(3).times.and_call_original
65
- AddressFinder::Bulk.new(http: http, verification_version: nil, default_country: 'au', &block).perform
66
- end
67
-
68
- it "re-establishes the http connection and continues where we left off when a Net::OpenTimeout, Net::ReadTimeout or SocketError is raised" do
69
- expect(http).to receive(:re_establish_connection).exactly(3).times.and_call_original
70
- expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
71
- expect(net_http).to receive(:transport_request).once.and_return(response) # 1 Willis (success)
72
- expect(net_http).to receive(:transport_request).once.and_raise(Net::OpenTimeout) # 2 Willis (error)
73
- expect(net_http).to receive(:transport_request).once.and_raise(Net::ReadTimeout) # Retry 2 Willis (error)
74
- expect(net_http).to receive(:transport_request).once.and_raise(SocketError) # Retry 2 Willis (error)
75
- expect(net_http).to receive(:transport_request).exactly(2).and_return(response) # Retry 2 Willis (success) & 3 Willis (success)
76
- expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
77
- AddressFinder::Bulk.new(http: http, verification_version: 'v2', default_country: 'au', &block).perform
78
- end
79
- end
80
-
81
- context "with the deprecated cleanse method" do
82
- let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
83
- let(:block){
84
- Proc.new do |proxy|
85
- proxy.cleanse(q: "1 Willis")
86
- end
87
- }
88
-
89
- it "has the same behaviour as the verification method" do
90
- expect(net_http).to receive(:do_start).once.and_call_original
91
- expect(net_http).to receive(:transport_request).once.and_return(response)
92
- expect(net_http).to receive(:do_finish).once.and_call_original
93
- expect(AddressFinder::Verification).to receive(:new).exactly(1).times.and_call_original
94
- AddressFinder::Bulk.new(http: http, verification_version: nil, default_country: 'au', &block).perform
95
- end
96
- end
97
-
98
- context "with a country override and v2 in the config" do
99
- let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
100
- let(:block){
101
- Proc.new do |proxy|
102
- proxy.verification(q: "1 Willis", country: "au")
103
- end
104
- }
105
-
106
- it "has the same behaviour as the verification method" do
107
- expect(net_http).to receive(:do_start).once.and_call_original
108
- expect(net_http).to receive(:transport_request).once.and_return(response)
109
- expect(net_http).to receive(:do_finish).once.and_call_original
110
- expect(AddressFinder::V2::Au::Verification).to receive(:new).exactly(1).times.and_call_original
111
- AddressFinder::Bulk.new(http: http, verification_version: "v2", default_country: 'nz', &block).perform
112
- end
113
- end
114
-
115
- context "email verification with 3 requests in the provided block" do
116
- let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
117
- let(:block){
118
- Proc.new do |proxy|
119
- proxy.email_verification(email: "john.doe@addressfinder.com")
120
- proxy.email_verification(email: "jane.doe@addressfinder.com")
121
- proxy.email_verification(email: "tom.doe@addressfinder.com")
122
- end
123
- }
124
-
125
- it "uses 1 http connection" do
126
- expect(net_http).to receive(:do_start).once.and_call_original
127
- expect(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
128
- expect(net_http).to receive(:do_finish).once.and_call_original
129
- AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
130
- end
131
-
132
- it "calls the correct class with v1 verification and nz default" do
133
- allow(net_http).to receive(:do_start).once.and_call_original
134
- allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
135
- allow(net_http).to receive(:do_finish).once.and_call_original
136
- expect(AddressFinder::V1::Email::Verification).to receive(:new).exactly(3).times.and_call_original
137
- AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
138
- end
139
-
140
- it "calls the correct class without a verification version or default country" do
141
- allow(net_http).to receive(:do_start).once.and_call_original
142
- allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
143
- allow(net_http).to receive(:do_finish).once.and_call_original
144
- expect(AddressFinder::V1::Email::Verification).to receive(:new).exactly(3).times.and_call_original
145
- AddressFinder::Bulk.new(http: http, verification_version: nil, default_country: nil, &block).perform
146
- end
147
-
148
- it "re-establishes the http connection and continues where we left off when a Net::OpenTimeout, Net::ReadTimeout or SocketError is raised" do
149
- expect(http).to receive(:re_establish_connection).exactly(3).times.and_call_original
150
- expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
151
- expect(net_http).to receive(:transport_request).once.and_return(response) # john.doe@addressfinder.com (success)
152
- expect(net_http).to receive(:transport_request).once.and_raise(Net::OpenTimeout) # jane.doe@addressfinder.com (error)
153
- expect(net_http).to receive(:transport_request).once.and_raise(Net::ReadTimeout) # Retry jane.doe@addressfinder.com (error)
154
- expect(net_http).to receive(:transport_request).once.and_raise(SocketError) # Retry jane.doe@addressfinder.com (error)
155
- expect(net_http).to receive(:transport_request).exactly(2).and_return(response) # Retry jane.doe@addressfinder.com (success) & tom.doe@addressfinder.com (success)
156
- expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
157
- AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
158
- end
159
- end
160
-
161
- context "phone verification with 3 requests in the provided block" do
162
- let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
163
- let(:block){
164
- Proc.new do |proxy|
165
- proxy.phone_verification(phone_number: "+64274673830", default_country_code: "AU")
166
- proxy.phone_verification(phone_number: "1800 152 363", default_country_code: "AU")
167
- proxy.phone_verification(phone_number: "0274673830", default_country_code: "NZ")
168
- end
169
- }
170
-
171
- it "uses 1 http connection" do
172
- expect(net_http).to receive(:do_start).once.and_call_original
173
- expect(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
174
- expect(net_http).to receive(:do_finish).once.and_call_original
175
- AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
176
- end
177
-
178
- it "calls the correct class with v1 verification and nz default" do
179
- allow(net_http).to receive(:do_start).once.and_call_original
180
- allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
181
- allow(net_http).to receive(:do_finish).once.and_call_original
182
- expect(AddressFinder::V1::Phone::Verification).to receive(:new).exactly(3).times.and_call_original
183
- AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
184
- end
185
-
186
- it "calls the correct class without a verification version or default country" do
187
- allow(net_http).to receive(:do_start).once.and_call_original
188
- allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
189
- allow(net_http).to receive(:do_finish).once.and_call_original
190
- expect(AddressFinder::V1::Phone::Verification).to receive(:new).exactly(3).times.and_call_original
191
- AddressFinder::Bulk.new(http: http, verification_version: nil, default_country: nil, &block).perform
192
- end
193
-
194
- it "re-establishes the http connection and continues where we left off when a Net::OpenTimeout, Net::ReadTimeout or SocketError is raised" do
195
- expect(http).to receive(:re_establish_connection).exactly(3).times.and_call_original
196
- expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
197
- expect(net_http).to receive(:transport_request).once.and_return(response) # +64274673830 (success)
198
- expect(net_http).to receive(:transport_request).once.and_raise(Net::OpenTimeout) # 1800 152 363 (error)
199
- expect(net_http).to receive(:transport_request).once.and_raise(Net::ReadTimeout) # Retry 1800 152 363 (error)
200
- expect(net_http).to receive(:transport_request).once.and_raise(SocketError) # Retry 1800 152 363 (error)
201
- expect(net_http).to receive(:transport_request).exactly(2).and_return(response) # Retry 1800 152 363 (success) & 0274673830 (success)
202
- expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
203
- AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
204
- end
205
- end
206
- end
207
- end
@@ -1,79 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe AddressFinder::LocationInfo do
4
- before do
5
- AddressFinder.configure do |af|
6
- af.api_key = 'XXX'
7
- af.api_secret = 'YYY'
8
- af.default_country = 'au'
9
- end
10
- end
11
-
12
- describe '#build_request' do
13
- let(:locator){ AddressFinder::LocationInfo.new(params: args, http: http) }
14
- let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
15
-
16
- subject(:request_uri){ locator.send(:build_request) }
17
-
18
- context 'with a simple PXID' do
19
- let(:args){ {pxid: '123'} }
20
-
21
- it { expect(request_uri).to eq('/api/au/location/info.json?pxid=123&key=XXX&secret=YYY') }
22
- end
23
-
24
- context 'with a country override' do
25
- let(:args){ {pxid: '123', country: 'nz'} }
26
-
27
- it { expect(request_uri).to eq('/api/nz/location/info.json?pxid=123&key=XXX&secret=YYY') }
28
- end
29
-
30
- context 'with a key override' do
31
- let(:args){ {pxid: '123', key: 'AAA'} }
32
-
33
- it { expect(request_uri).to eq('/api/au/location/info.json?pxid=123&key=AAA&secret=YYY') }
34
- end
35
-
36
- context 'with a secret override' do
37
- let(:args){ {pxid: '123', secret: 'BBB'} }
38
-
39
- it { expect(request_uri).to eq('/api/au/location/info.json?pxid=123&secret=BBB&key=XXX') }
40
- end
41
-
42
- context 'with a domain given' do
43
- let(:args){ {pxid: '123', domain: 'testdomain.com'} }
44
-
45
- it { expect(request_uri).to eq('/api/au/location/info.json?pxid=123&domain=testdomain.com&key=XXX&secret=YYY') }
46
-
47
- context 'given in the AF configuration' do
48
-
49
- let(:args){ {pxid: '123'} }
50
-
51
- it 'should use the config domain if set' do
52
- AddressFinder.configuration.domain = 'anotherdomain.com'
53
- expect(request_uri).to eq('/api/au/location/info.json?pxid=123&domain=anotherdomain.com&key=XXX&secret=YYY')
54
- AddressFinder.configuration.domain = nil # set back to nil after
55
- end
56
- end
57
- end
58
- end
59
-
60
- describe '#build_result' do
61
- let(:locator){ AddressFinder::LocationInfo.new(params: {q: 'ignored'}, http: nil) }
62
-
63
- before do
64
- locator.send('response_body=', body)
65
- locator.send('response_status=', status)
66
- end
67
-
68
- subject(:result){ locator.send(:build_result) }
69
-
70
- context 'with a successful result' do
71
- let(:body){ '{"a":"Seaview Road, Glenfield, Auckland","city":"Auckland","suburb":"Glenfield","region":"Auckland Region","x":174.713938691835,"y":-36.7894885545157,"pxid":"1-.1.6.j.1F","street":"Seaview Road"}' }
72
- let(:status){ '200' }
73
-
74
- it { expect(result.class).to eq(AddressFinder::LocationInfo::Result) }
75
- it { expect(result.a).to eq("Seaview Road, Glenfield, Auckland") }
76
- it { expect(result.pxid).to eq("1-.1.6.j.1F") }
77
- end
78
- end
79
- end
@@ -1,93 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe AddressFinder::LocationSearch do
4
- before do
5
- AddressFinder.configure do |af|
6
- af.api_key = 'XXX'
7
- af.api_secret = 'YYY'
8
- af.default_country = 'nz'
9
- end
10
- end
11
-
12
- describe '#build_request' do
13
- let(:locator){ AddressFinder::LocationSearch.new(params: args, http: http) }
14
- let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
15
-
16
- subject(:request_uri){ locator.send(:build_request) }
17
-
18
- context 'with minimal arguments' do
19
- let(:args){ {q: 'willis'} }
20
-
21
- it { expect(request_uri).to eq('/api/nz/location.json?q=willis&key=XXX&secret=YYY') }
22
- end
23
-
24
- context 'with more arguments' do
25
- let(:args){ {q: 'willis st', street: 1, max: 10} }
26
-
27
- it { expect(request_uri).to eq('/api/nz/location.json?q=willis+st&street=1&max=10&key=XXX&secret=YYY') }
28
- end
29
-
30
- context 'with a country override' do
31
- let(:args){ {q: 'willis st', country: 'au'} }
32
-
33
- it { expect(request_uri).to eq('/api/au/location.json?q=willis+st&key=XXX&secret=YYY') }
34
- end
35
-
36
- context 'with a key override' do
37
- let(:args){ {q: 'willis st', key: 'AAA'} }
38
-
39
- it { expect(request_uri).to eq('/api/nz/location.json?q=willis+st&key=AAA&secret=YYY') }
40
- end
41
-
42
- context 'with a secret override' do
43
- let(:args){ {q: 'willis st', secret: 'BBB'} }
44
-
45
- it { expect(request_uri).to eq('/api/nz/location.json?q=willis+st&secret=BBB&key=XXX') }
46
- end
47
-
48
- context 'with a domain given' do
49
- let(:args){ {q: '123', domain: 'testdomain.com'} }
50
-
51
- it { expect(request_uri).to eq('/api/nz/location.json?q=123&domain=testdomain.com&key=XXX&secret=YYY') }
52
-
53
- context 'given in the AF configuration' do
54
-
55
- let(:args){ {q: '123'} }
56
-
57
- it 'should use the config domain if set' do
58
- AddressFinder.configuration.domain = 'anotherdomain.com'
59
- expect(request_uri).to eq('/api/nz/location.json?q=123&domain=anotherdomain.com&key=XXX&secret=YYY')
60
- AddressFinder.configuration.domain = nil # set back to nil after
61
- end
62
- end
63
- end
64
- end
65
-
66
- describe '#build_result' do
67
- let(:locator){ AddressFinder::LocationSearch.new(params: {q: 'ignored'}, http: nil) }
68
-
69
- before do
70
- locator.send('response_body=', body)
71
- locator.send('response_status=', status)
72
- locator.send(:build_result)
73
- end
74
-
75
- subject(:results){ locator.results }
76
-
77
- context 'with completions' do
78
- let(:body){ '{"completions":[{"a":"Willowbank","pxid":"1-.B.3l","v":0},{"a":"Willowby","pxid":"1-.3.4O","v":0}],"paid":true}' }
79
- let(:status){ '200' }
80
-
81
- it { expect(results.size).to eq(2) }
82
- it { expect(results.first.class).to eq(AddressFinder::LocationSearch::Result) }
83
- it { expect(results.first.a).to eq("Willowbank") }
84
- end
85
-
86
- context 'with no completions' do
87
- let(:body){ '{"completions":[],"paid":true}' }
88
- let(:status){ '200' }
89
-
90
- it { expect(results).to eq([]) }
91
- end
92
- end
93
- end
@@ -1,37 +0,0 @@
1
- require 'addressfinder/util'
2
-
3
- RSpec.describe AddressFinder::Util do
4
- describe '.encode_and_join_params' do
5
- subject { AddressFinder::Util.encode_and_join_params(params) }
6
-
7
- context 'with a question mark value' do
8
- let(:params){ {q:'?',format:'json',key:'XXX',secret:'YYY'} }
9
-
10
- it { is_expected.to eq('q=%3F&format=json&key=XXX&secret=YYY') }
11
- end
12
-
13
- context 'with an ampersand value' do
14
- let(:params){ {q:'&',format:'json',key:'XXX',secret:'YYY'} }
15
-
16
- it { is_expected.to eq('q=%26&format=json&key=XXX&secret=YYY') }
17
- end
18
-
19
- context 'with a normal address value' do
20
- let(:params){ {q:'12 high',format:'json',key:'XXX',secret:'YYY'} }
21
-
22
- it { is_expected.to eq('q=12+high&format=json&key=XXX&secret=YYY') }
23
- end
24
-
25
- context 'with a blank value' do
26
- let(:params){ {q:'',format:'json',key:'XXX',secret:'YYY'} }
27
-
28
- it { is_expected.to eq('q=&format=json&key=XXX&secret=YYY') }
29
- end
30
-
31
- context 'with a nil value' do
32
- let(:params){ {q:nil,format:'json',key:'XXX',secret:'YYY'} }
33
-
34
- it { is_expected.to eq('q=&format=json&key=XXX&secret=YYY') }
35
- end
36
- end
37
- end
@@ -1,148 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe AddressFinder::V1::Email::Verification do
4
- before do
5
- AddressFinder.configure do |af|
6
- af.api_key = "XXX"
7
- af.api_secret = "YYY"
8
- af.timeout = 5
9
- af.retries = 3
10
- end
11
- end
12
-
13
- let(:verification_module){ AddressFinder::V1::Email::Verification.new(**args) }
14
- let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
15
- let(:net_http){ http.send(:net_http) }
16
-
17
- describe "#execute_request" do
18
- let(:args){ {email: "john.doe@addressfinder.com", http: http} }
19
-
20
- before do
21
- WebMock.allow_net_connect!(net_http_connect_on_start: true)
22
- allow(http).to receive(:sleep)
23
- allow(verification_module).to receive(:request_uri).and_return("/test/path")
24
- expect(http).to_not receive(:re_establish_connection)
25
- end
26
-
27
- after do
28
- WebMock.disable_net_connect!
29
- end
30
-
31
- subject(:execute_request){ verification_module.send(:execute_request) }
32
-
33
- it "retries an errored request another time before succeeding" do
34
- expect(net_http).to receive(:do_start).twice.and_call_original
35
- expect(net_http).to receive(:transport_request).once.and_raise(Net::OpenTimeout)
36
- expect(net_http).to receive(:transport_request).once.and_return(double(:response, body: "OK", code: "200"))
37
- expect(net_http).to receive(:do_finish).twice.and_call_original
38
- execute_request
39
- end
40
-
41
- it "re-raises a Net::OpenTimeout error after 3 retries" do
42
- expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
43
- expect(net_http).to receive(:transport_request).exactly(4).times.and_raise(Net::OpenTimeout)
44
- expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
45
- expect{execute_request}.to raise_error(Net::OpenTimeout)
46
- end
47
-
48
- it "re-raises a Net::ReadTimeout error after 3 retries" do
49
- expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
50
- expect(net_http).to receive(:transport_request).exactly(4).times.and_raise(Net::ReadTimeout)
51
- expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
52
- expect{execute_request}.to raise_error(Net::ReadTimeout)
53
- end
54
-
55
- it "re-raises a SocketError error after 3 retries" do
56
- expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
57
- expect(net_http).to receive(:transport_request).exactly(4).times.and_raise(SocketError)
58
- expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
59
- expect{execute_request}.to raise_error(SocketError)
60
- end
61
- end
62
-
63
- describe "#build_request" do
64
- subject(:request_uri){ verification_module.send(:build_request) }
65
-
66
- context "with email argument" do
67
- let(:args){ {email: "john.doe@addressfinder.com", http: http} }
68
-
69
- it { expect(request_uri).to eq("/api/email/v1/verification?email=john.doe%40addressfinder.com&key=XXX&secret=YYY&format=json") }
70
- end
71
-
72
- context "with email and format arguments" do
73
- let(:args){ {email: "john.doe@addressfinder.com", format: "xml", http: http} }
74
-
75
- it { expect(request_uri).to eq("/api/email/v1/verification?email=john.doe%40addressfinder.com&format=xml&key=XXX&secret=YYY") }
76
- end
77
-
78
- context "with a reserved character in the email" do
79
- let(:args){ {email: "john=doe@addressfinder.com", http: http} }
80
-
81
- it { expect(request_uri).to eq("/api/email/v1/verification?email=john%3Ddoe%40addressfinder.com&key=XXX&secret=YYY&format=json") }
82
- end
83
-
84
- context "with a key override" do
85
- let(:args){ {email: "john.doe@addressfinder.com", key: "AAA", http: http} }
86
-
87
- it { expect(request_uri).to eq("/api/email/v1/verification?email=john.doe%40addressfinder.com&key=AAA&secret=YYY&format=json") }
88
- end
89
-
90
- context "with a secret override" do
91
- let(:args){ {email: "john.doe@addressfinder.com", secret: "BBB", http: http} }
92
-
93
- it { expect(request_uri).to eq("/api/email/v1/verification?email=john.doe%40addressfinder.com&secret=BBB&key=XXX&format=json") }
94
- end
95
-
96
- context "with a domain given" do
97
- let(:args){ {email: "john.doe@addressfinder.com", domain: "testdomain.com", http: http} }
98
-
99
- it { expect(request_uri).to eq("/api/email/v1/verification?email=john.doe%40addressfinder.com&domain=testdomain.com&key=XXX&secret=YYY&format=json") }
100
-
101
- context "given in the AF configuration" do
102
- let(:args){ {email: "john.doe@addressfinder.com", http: http} }
103
-
104
- it "should use the config domain if set" do
105
- AddressFinder.configuration.domain = "anotherdomain.com"
106
- expect(request_uri).to eq("/api/email/v1/verification?email=john.doe%40addressfinder.com&domain=anotherdomain.com&key=XXX&secret=YYY&format=json")
107
- AddressFinder.configuration.domain = nil # set back to nil after
108
- end
109
- end
110
- end
111
-
112
- context "with a all arguments included in request" do
113
- let(:args){ {email: "john.doe@addressfinder.com", domain: "mysite.com", key: "AAA", secret: "BBB", format: "json", http: http} }
114
-
115
- it { expect(request_uri).to eq("/api/email/v1/verification?email=john.doe%40addressfinder.com&domain=mysite.com&key=AAA&secret=BBB&format=json") }
116
- end
117
- end
118
-
119
- describe "#build_result" do
120
- let(:args){ {email: "ignored", http: nil} }
121
-
122
- before do
123
- verification_module.send("response_body=", body)
124
- verification_module.send("response_status=", status)
125
- end
126
-
127
- subject(:result){ verification_module.send(:build_result) }
128
-
129
- context "with a successful verification" do
130
- let(:body){ '{"email_account": "john.doe", "email_domain": "addressfinder.com", "is_verified": true, "success": true}' }
131
- let(:status){ "200" }
132
-
133
- it { expect(result.class).to eq(AddressFinder::V1::Email::Verification::Result) }
134
- it { expect(result.is_verified).to eq(true) }
135
- it { expect(result.email_account).to eq("john.doe") }
136
- end
137
-
138
- context "with an unsuccessful verification" do
139
- let(:body){ '{"email_account": "jane.doe", "email_domain": "addressfinder.com", "is_verified": false, "not_verified_reason": "The email account does not exist", "success": true}' }
140
- let(:status){ "200" }
141
-
142
- it { expect(result.class).to eq(AddressFinder::V1::Email::Verification::Result) }
143
- it { expect(result.is_verified).to eq(false) }
144
- it { expect(result.email_account).to eq("jane.doe") }
145
- it { expect(result.not_verified_reason).to eq("The email account does not exist") }
146
- end
147
- end
148
- end