feat: add postcodes:import command for loading ONSPD CSV
This commit is contained in:
31
tests/Feature/Console/ImportPostcodesTest.php
Normal file
31
tests/Feature/Console/ImportPostcodesTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Postcode;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
function writeOnspdFixture(string $contents): string
|
||||
{
|
||||
$path = tempnam(sys_get_temp_dir(), 'onspd_').'.csv';
|
||||
file_put_contents($path, $contents);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
it('imports active postcodes from an ONSPD CSV', function (): void {
|
||||
$csv = <<<'CSV'
|
||||
pcd,pcds,doterm,lat,long
|
||||
"SW1A1AA","SW1A 1AA","",51.501009,-0.141588
|
||||
"M11AD","M1 1AD",,53.480957,-2.237428
|
||||
CSV;
|
||||
|
||||
$path = writeOnspdFixture($csv);
|
||||
|
||||
$this->artisan('postcodes:import', ['--file' => $path])
|
||||
->assertSuccessful();
|
||||
|
||||
expect(Postcode::count())->toBe(2)
|
||||
->and(Postcode::find('SW1A1AA')->outcode)->toBe('SW1A')
|
||||
->and(Postcode::find('M11AD')->outcode)->toBe('M1');
|
||||
});
|
||||
Reference in New Issue
Block a user