feat: add StationTaggingService with supermarket detection

This commit is contained in:
Ovidiu U
2026-04-03 18:49:34 +01:00
parent 7f153fb08d
commit 80a8a9f93b
3 changed files with 107 additions and 7 deletions

View File

@@ -0,0 +1,68 @@
<?php
use App\Models\Station;
use App\Services\StationTaggingService;
beforeEach(function (): void {
$this->service = new StationTaggingService();
});
it('marks tesco station as supermarket and normalises brand', function (): void {
$station = new Station([
'trading_name' => 'TESCO EXTRA',
'is_supermarket' => false,
]);
$this->service->tag($station);
expect($station->is_supermarket)->toBeTrue()
->and($station->brand_name)->toBe('Tesco');
});
it('marks asda station as supermarket', function (): void {
$station = new Station([
'trading_name' => 'Asda Petrol Station',
'is_supermarket' => false,
]);
$this->service->tag($station);
expect($station->is_supermarket)->toBeTrue()
->and($station->brand_name)->toBe('Asda');
});
it('does not mark independent station as supermarket', function (): void {
$station = new Station([
'trading_name' => 'Village Garage',
'is_supermarket' => false,
]);
$this->service->tag($station);
expect($station->is_supermarket)->toBeFalse();
});
it('handles case insensitive matching', function (): void {
$station = new Station([
'trading_name' => 'morrisons petrol',
'is_supermarket' => false,
]);
$this->service->tag($station);
expect($station->is_supermarket)->toBeTrue()
->and($station->brand_name)->toBe('Morrisons');
});
it('does not overwrite brand_name for non-supermarket stations', function (): void {
$station = new Station([
'trading_name' => 'Shell Garage',
'brand_name' => 'Shell',
'is_supermarket' => false,
]);
$this->service->tag($station);
expect($station->is_supermarket)->toBeFalse()
->and($station->brand_name)->toBe('Shell');
});