feat: resolve full postcodes from local DB before HTTP

This commit is contained in:
Ovidiu U
2026-04-22 12:09:19 +01:00
parent 55c81fab7b
commit 9fa9ea7835
2 changed files with 53 additions and 1 deletions

View File

@@ -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();
});