feat: resolve full postcodes from local DB before HTTP
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Postcode;
|
||||
use App\Services\ApiLogger;
|
||||
use App\Services\LocationResult;
|
||||
use App\Services\PostcodeService;
|
||||
@@ -171,3 +172,25 @@ it('returns null and does not throw on API failure', function (): void {
|
||||
|
||||
expect($result)->toBeNull();
|
||||
});
|
||||
|
||||
// --- Local DB (full postcode) ---
|
||||
|
||||
it('resolves a full postcode from local DB without calling HTTP', function (): void {
|
||||
Postcode::create([
|
||||
'postcode' => 'SW1A1AA',
|
||||
'outcode' => 'SW1A',
|
||||
'lat' => 51.501009,
|
||||
'lng' => -0.141588,
|
||||
]);
|
||||
|
||||
Http::fake(); // any HTTP call will be recorded
|
||||
|
||||
$result = $this->service->resolve('SW1A 1AA');
|
||||
|
||||
expect($result)->toBeInstanceOf(LocationResult::class)
|
||||
->and($result->displayName)->toBe('SW1A 1AA')
|
||||
->and($result->lat)->toBe(51.501009)
|
||||
->and($result->lng)->toBe(-0.141588);
|
||||
|
||||
Http::assertNothingSent();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user