refactor: scope postcode cache to place names, DB is authoritative for postcodes
This commit is contained in:
@@ -134,23 +134,41 @@ it('returns null when place name yields no results', function (): void {
|
||||
|
||||
// --- Caching ---
|
||||
|
||||
it('caches a successful resolution for 30 days', function (): void {
|
||||
it('caches a successful place resolution for 30 days', function (): void {
|
||||
Http::fake([
|
||||
'*/outcodes/PE7' => Http::response([
|
||||
'*/places*' => Http::response([
|
||||
'status' => 200,
|
||||
'result' => [[
|
||||
'name_1' => 'Manchester',
|
||||
'latitude' => 53.480957,
|
||||
'longitude' => -2.237428,
|
||||
]],
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->service->resolve('Manchester');
|
||||
$this->service->resolve('Manchester');
|
||||
|
||||
Http::assertSentCount(1);
|
||||
expect(Cache::get('place:manchester'))->toBeInstanceOf(LocationResult::class);
|
||||
});
|
||||
|
||||
it('does not cache postcode resolutions in the Cache store (DB is the cache)', function (): void {
|
||||
Http::fake([
|
||||
'*/postcodes/SW1A1AA' => Http::response([
|
||||
'status' => 200,
|
||||
'result' => [
|
||||
'outcode' => 'PE7',
|
||||
'latitude' => 52.536397,
|
||||
'longitude' => -0.210181,
|
||||
'postcode' => 'SW1A 1AA',
|
||||
'latitude' => 51.501009,
|
||||
'longitude' => -0.141588,
|
||||
],
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->service->resolve('PE7');
|
||||
$this->service->resolve('PE7');
|
||||
$this->service->resolve('SW1A 1AA');
|
||||
|
||||
Http::assertSentCount(1);
|
||||
expect(Cache::get('postcode:pe7'))->toBeInstanceOf(LocationResult::class);
|
||||
expect(Cache::get('postcode:sw1a1aa'))->toBeNull()
|
||||
->and(Postcode::find('SW1A1AA'))->not->toBeNull();
|
||||
});
|
||||
|
||||
it('does not cache failed lookups', function (): void {
|
||||
|
||||
Reference in New Issue
Block a user