feat: derive outcode centroids from postcodes during import
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Outcode;
|
||||
use App\Models\Postcode;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
@@ -61,3 +62,23 @@ CSV;
|
||||
expect(Postcode::count())->toBe(1)
|
||||
->and(Postcode::find('BT11AA'))->toBeNull();
|
||||
});
|
||||
|
||||
it('derives outcode centroids as the average of member postcodes', function (): void {
|
||||
$csv = <<<'CSV'
|
||||
pcd,pcds,doterm,lat,long
|
||||
"PE71AA","PE7 1AA","",52.500000,-0.200000
|
||||
"PE71AB","PE7 1AB","",52.600000,-0.220000
|
||||
"M11AD","M1 1AD","",53.480957,-2.237428
|
||||
CSV;
|
||||
|
||||
$path = writeOnspdFixture($csv);
|
||||
|
||||
$this->artisan('postcodes:import', ['--file' => $path])->assertSuccessful();
|
||||
|
||||
$pe7 = Outcode::find('PE7');
|
||||
|
||||
expect($pe7)->not->toBeNull()
|
||||
->and(round((float) $pe7->lat, 6))->toBe(52.550000)
|
||||
->and(round((float) $pe7->lng, 6))->toBe(-0.210000)
|
||||
->and(Outcode::find('M1'))->not->toBeNull();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user