Skip to content

Commit e8d1e44

Browse files
authored
Merge pull request #60 from ipinfo/fix-tests
Fix failing resproxy tests caused by data change
2 parents e22cfca + ce82dc0 commit e8d1e44

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ group :development do
1010
gem 'minitest-reporters'
1111
gem 'rake'
1212
gem 'rubocop'
13+
gem 'webmock'
1314
end

test/ipinfo_test.rb

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,41 @@ def test_lookup_ip4
177177
end
178178

179179
def test_resproxy
180-
ipinfo = IPinfo.create(ENV['IPINFO_TOKEN'])
180+
# Mock the resproxy API response (with any query params)
181+
stub_request(:get, /https:\/\/ipinfo\.io\/resproxy\/#{TEST_RESPROXY_IP}/)
182+
.to_return(
183+
status: 200,
184+
body: {
185+
ip: TEST_RESPROXY_IP,
186+
last_seen: '2025-01-20',
187+
percent_days_seen: 0.85,
188+
service: 'example_service'
189+
}.to_json,
190+
headers: { 'Content-Type' => 'application/json' }
191+
)
192+
193+
ipinfo = IPinfo.create('test_token')
181194

182195
# multiple checks for cache
183196
(0...5).each do |_|
184197
resp = ipinfo.resproxy(TEST_RESPROXY_IP)
185198
assert_equal(resp.ip, TEST_RESPROXY_IP)
186-
refute_nil(resp.last_seen)
187-
refute_nil(resp.percent_days_seen)
188-
refute_nil(resp.service)
199+
assert_equal(resp.last_seen, '2025-01-20')
200+
assert_equal(resp.percent_days_seen, 0.85)
201+
assert_equal(resp.service, 'example_service')
189202
end
190203
end
191204

192205
def test_resproxy_empty
193-
ipinfo = IPinfo.create(ENV['IPINFO_TOKEN'])
206+
# Mock the resproxy API response for non-residential proxy IP (with any query params)
207+
stub_request(:get, /https:\/\/ipinfo\.io\/resproxy\/#{TEST_IPV4}/)
208+
.to_return(
209+
status: 200,
210+
body: '{}',
211+
headers: { 'Content-Type' => 'application/json' }
212+
)
213+
214+
ipinfo = IPinfo.create('test_token')
194215

195216
resp = ipinfo.resproxy(TEST_IPV4)
196217
assert_equal(resp.all, {})

test/test_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
require 'minitest/autorun'
1010
require 'minitest/reporters'
11+
require 'webmock/minitest'
12+
13+
# Allow real network connections by default, but tests can disable this
14+
WebMock.allow_net_connect!
1115

1216
Minitest::Reporters.use!(
1317
Minitest::Reporters::SpecReporter.new

0 commit comments

Comments
 (0)