@@ -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 , { } )
0 commit comments