Remove obsolete Livewire fuel search components and consolidate pricing tiers
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

- Delete unused Livewire Search test and fuel type select Blade component
- Move subscription webhook listener from EventServiceProvider to AppServiceProvider
- Add FUEL_TYPES global config to app layout for client-side use
- Add Billable trait to User model and include email_verified_at in fillable
- Implement monthly/annual cadence toggle with pricing display and smart CTA routing on homepage
- Update VerifyApiKeyMiddlewareTest to use e10 instead of petrol
- Refactor PollFuelPrices to auto-refresh stale stations based on last_seen_at
- Add incremental polling with cached timestamp and effective-start-timestamp param to FuelPriceService
- Normalize amenities/fuel_types from API objects to flat arrays, skip stations missing required fields
- Log response body on API failures in ApiLogger
- Default homepage sort to 'reliable' instead of 'price'
This commit is contained in:
Ovidiu U
2026-04-20 14:12:15 +01:00
parent aec547cd86
commit 5acb99c9e3
33 changed files with 739 additions and 391 deletions

View File

@@ -6,6 +6,7 @@ use App\Models\StationPriceCurrent;
use App\Services\ApiLogger;
use App\Services\FuelPriceService;
use App\Services\StationTaggingService;
use Carbon\CarbonInterface;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
@@ -310,3 +311,110 @@ it('stops pagination when an empty batch is returned', function (): void {
Http::assertSentCount(1);
});
it('caches the poll timestamp and sends it on subsequent polls', function (): void {
Cache::put('fuel_finder_access_token', 'tok', 3540);
Cache::forget('fuel_finder_last_price_poll_at');
Http::fake([
'*/pfs/fuel-prices*' => Http::response([]),
]);
$this->service->pollPrices();
expect(Cache::get('fuel_finder_last_price_poll_at'))->toBeInstanceOf(CarbonInterface::class);
$this->service->pollPrices();
Http::assertSent(fn ($request) => str_contains($request->url(), 'effective-start-timestamp='));
});
it('does not cache the poll timestamp when a batch errors', function (): void {
Cache::put('fuel_finder_access_token', 'tok', 3540);
Cache::forget('fuel_finder_last_price_poll_at');
Http::fake([
'*/pfs/fuel-prices*' => Http::response([], 500),
]);
$this->service->pollPrices();
expect(Cache::has('fuel_finder_last_price_poll_at'))->toBeFalse();
});
it('skips price rows for stations not present in the stations table', function (): void {
Cache::put('fuel_finder_access_token', 'tok', 3540);
Http::fake([
'*/pfs/fuel-prices*' => Http::sequence()
->push([[
'node_id' => 'unknown-station',
'fuel_prices' => [[
'fuel_type' => 'E10',
'price' => 142.9,
'price_last_updated' => '2026-04-04T10:00:00.000Z',
'price_change_effective_timestamp' => '2026-04-04T10:00:00.000Z',
]],
]])
->push([]),
]);
$inserted = $this->service->pollPrices();
expect($inserted)->toBe(0)
->and(StationPrice::count())->toBe(0)
->and(StationPriceCurrent::count())->toBe(0);
});
it('normalises amenities and fuel_types object payloads to flat arrays', function (): void {
$apiStations = [[
'node_id' => 'abc999',
'trading_name' => 'Shell Somewhere',
'brand_name' => 'Shell',
'is_same_trading_and_brand_name' => false,
'is_motorway_service_station' => false,
'is_supermarket_service_station' => false,
'temporary_closure' => false,
'permanent_closure' => false,
'location' => [
'postcode' => 'AB1 2CD',
'latitude' => 52.1,
'longitude' => -1.2,
],
'amenities' => [
'adblue_pumps' => true,
'car_wash' => false,
'customer_toilets' => true,
],
'fuel_types' => [
'E10' => true,
'E5' => true,
'B7_Standard' => true,
'B7_Premium' => false,
'B10' => false,
'HVO' => false,
],
]];
$this->service->upsertStations($apiStations);
$station = Station::find('abc999');
expect($station->amenities)->toBe(['adblue_pumps', 'customer_toilets'])
->and($station->fuel_types)->toBe(['E10', 'E5', 'B7_Standard']);
});
it('skips stations missing required fields', function (): void {
$apiStations = [
['node_id' => 'missing-loc', 'trading_name' => 'Bad Data'],
[
'node_id' => 'good',
'trading_name' => 'Good Station',
'location' => ['postcode' => 'AB1 2CD', 'latitude' => 52.0, 'longitude' => -1.0],
],
];
$this->service->upsertStations($apiStations);
expect(Station::find('missing-loc'))->toBeNull()
->and(Station::find('good'))->not->toBeNull();
});