feat: add StationTaggingService with supermarket detection
This commit is contained in:
68
tests/Unit/Services/StationTaggingServiceTest.php
Normal file
68
tests/Unit/Services/StationTaggingServiceTest.php
Normal 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');
|
||||
});
|
||||
Reference in New Issue
Block a user