Skip to content

Commit

Permalink
Merge pull request #136 from rhwilrForks/master
Browse files Browse the repository at this point in the history
Fix Kloudend (ipapi.co) integration with empty tokens
  • Loading branch information
stevebauman authored Feb 27, 2023
2 parents e2d38d0 + f7fcae2 commit 49f28e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Drivers/Kloudend.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function url($ip)
{
$token = config('location.kloudend.token', '');

return "https://ipapi.co/{$ip}/json".empty($token) ? '' : "?key={$token}";
return "https://ipapi.co/{$ip}/json".(empty($token) ? '' : "?key={$token}");
}

/**
Expand Down
File renamed without changes.
18 changes: 17 additions & 1 deletion tests/Kloudend.php → tests/KloudendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'postal' => '55555',
'latitude' => '50',
'longitude' => '50',
'timezone' => ['name' => 'America/Toronto'],
'timezone' => 'America/Toronto',
];

$driver
Expand Down Expand Up @@ -52,3 +52,19 @@
'driver' => get_class($driver),
]);
});

it('it can make requests with a token', function () {
config(['location.kloudend.token' => 'ABC1234']);

$driver = m::mock(Kloudend::class);
$driver->makePartial();

expect($driver->url('1.1.1.1'))->toEqual('https://ipapi.co/1.1.1.1/json?key=ABC1234');
});

it('it can make requests without a token', function () {
$driver = m::mock(Kloudend::class);
$driver->makePartial();

expect($driver->url('1.1.1.1'))->toEqual('https://ipapi.co/1.1.1.1/json');
});

0 comments on commit 49f28e5

Please sign in to comment.