@@ -12,19 +12,42 @@ else {
1212}
1313
1414use_ok(' Geo::IPinfo' );
15+ use Test::Mock::LWP::Dispatch;
16+ use HTTP::Response;
1517
1618my $ip ;
1719
18- $ip = Geo::IPinfo-> new( $ENV {IPINFO_TOKEN } );
20+ # Set up mock responses
21+ $mock_ua -> map (
22+ qr { https://ipinfo\. io/resproxy/175\. 107\. 211\. 204} ,
23+ sub {
24+ my $response = HTTP::Response-> new(200);
25+ $response -> header(' Content-Type' => ' application/json' );
26+ $response -> content(' {"ip":"175.107.211.204","last_seen":"2025-01-20","percent_days_seen":0.85,"service":"example_service"}' );
27+ return $response ;
28+ }
29+ );
30+
31+ $mock_ua -> map (
32+ qr { https://ipinfo\. io/resproxy/8\. 8\. 8\. 8} ,
33+ sub {
34+ my $response = HTTP::Response-> new(200);
35+ $response -> header(' Content-Type' => ' application/json' );
36+ $response -> content(' {}' );
37+ return $response ;
38+ }
39+ );
40+
41+ $ip = Geo::IPinfo-> new(" test_token" );
1942isa_ok( $ip , " Geo::IPinfo" , ' $ip' );
2043
2144# Test resproxy with known residential proxy IP
2245my $resproxy = $ip -> resproxy(" 175.107.211.204" );
2346ok( $resproxy , " resproxy() returns data for known residential proxy IP" );
2447is( $resproxy -> {ip }, " 175.107.211.204" , " IP field is correct" );
25- ok( defined $resproxy -> {last_seen }, " last_seen field is defined " );
26- ok( defined $resproxy -> {percent_days_seen }, " percent_days_seen field is defined " );
27- ok( defined $resproxy -> {service }, " service field is defined " );
48+ is( $resproxy -> {last_seen }, " 2025-01-20 " , " last_seen field is correct " );
49+ is( $resproxy -> {percent_days_seen }, 0.85, " percent_days_seen field is correct " );
50+ is( $resproxy -> {service }, " example_service " , " service field is correct " );
2851
2952# Test resproxy with IP that returns empty response
3053my $empty_resproxy = $ip -> resproxy(" 8.8.8.8" );
0 commit comments