feat: persist postcodes.io fallback results into local DB
This commit is contained in:
@@ -216,3 +216,48 @@ it('resolves an outcode from local DB without calling HTTP', function (): void {
|
||||
|
||||
Http::assertNothingSent();
|
||||
});
|
||||
|
||||
// --- HTTP fallback persistence ---
|
||||
|
||||
it('persists a full postcode resolved via HTTP fallback', function (): void {
|
||||
Http::fake([
|
||||
'*/postcodes/SW1A1AA' => Http::response([
|
||||
'status' => 200,
|
||||
'result' => [
|
||||
'postcode' => 'SW1A 1AA',
|
||||
'latitude' => 51.501009,
|
||||
'longitude' => -0.141588,
|
||||
],
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->service->resolve('SW1A 1AA');
|
||||
|
||||
$row = Postcode::find('SW1A1AA');
|
||||
|
||||
expect($row)->not->toBeNull()
|
||||
->and($row->outcode)->toBe('SW1A')
|
||||
->and((float) $row->lat)->toBe(51.501009)
|
||||
->and((float) $row->lng)->toBe(-0.141588);
|
||||
});
|
||||
|
||||
it('persists an outcode resolved via HTTP fallback', function (): void {
|
||||
Http::fake([
|
||||
'*/outcodes/PE7' => Http::response([
|
||||
'status' => 200,
|
||||
'result' => [
|
||||
'outcode' => 'PE7',
|
||||
'latitude' => 52.536397,
|
||||
'longitude' => -0.210181,
|
||||
],
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->service->resolve('PE7');
|
||||
|
||||
$row = Outcode::find('PE7');
|
||||
|
||||
expect($row)->not->toBeNull()
|
||||
->and((float) $row->lat)->toBe(52.536397)
|
||||
->and((float) $row->lng)->toBe(-0.210181);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user