fix: preserve territorial scope in catalogue CSV and record local visual QA
This commit is contained in:
@@ -46,6 +46,23 @@ class ProvinceSearchCompatibilityTest extends TestCase
|
||||
return ['/api/v1/investment/search?'.$query, '/api/v1/opportunities/search?'.$query];
|
||||
}
|
||||
|
||||
private function csvRows(string $csv): array
|
||||
{
|
||||
$stream = fopen('php://memory', 'w+');
|
||||
fwrite($stream, $csv);
|
||||
rewind($stream);
|
||||
$headers = fgetcsv($stream, null, ';', '"', '');
|
||||
$headers[0] = ltrim($headers[0], "\xEF\xBB\xBF");
|
||||
$this->assertSame(['Referência', 'Título', 'Sector', 'Província', 'Montante', 'Moeda', 'Maturidade', 'URL', 'Localização e âmbito'], $headers);
|
||||
$rows = [];
|
||||
while (($row = fgetcsv($stream, null, ';', '"', '')) !== false) {
|
||||
$rows[] = array_combine($headers, $row);
|
||||
}
|
||||
fclose($stream);
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function test_a_single_province_includes_all_lower_levels_and_linked_locations_in_both_apis(): void
|
||||
{
|
||||
$geo = app(InvestmentGeography::class);
|
||||
@@ -75,7 +92,14 @@ class ProvinceSearchCompatibilityTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($records as $record) {
|
||||
$csvRows = $this->csvRows($this->get('/api/v1/investment/export?'.http_build_query(['province_id' => $path[0]->id, 'q' => $prefix]))->assertOk()->streamedContent());
|
||||
$this->assertCount(5, $csvRows);
|
||||
$byReference = array_column($csvRows, null, 'Referência');
|
||||
foreach ($records as $index => $record) {
|
||||
$csvRow = $byReference[$record->reference];
|
||||
$this->assertSame($path[0]->name, $csvRow['Província']);
|
||||
$this->assertSame(implode(' / ', array_column(array_slice($path, 0, min($index + 1, 4)), 'name')), $csvRow['Localização e âmbito']);
|
||||
$this->assertSame($record->province, $record->fresh()->province);
|
||||
$this->assertNull($record->fresh()->district);
|
||||
$this->assertSame($record->primary_territory_id, $record->fresh()->primary_territory_id);
|
||||
}
|
||||
@@ -159,6 +183,13 @@ class ProvinceSearchCompatibilityTest extends TestCase
|
||||
foreach (Opportunity::whereIn('id', $expected)->get() as $row) {
|
||||
$this->assertStringContainsString($row->title, $csv);
|
||||
}
|
||||
$csvRows = $this->csvRows($csv);
|
||||
$this->assertCount(5, $csvRows);
|
||||
foreach ($csvRows as $row) {
|
||||
$this->assertStringContainsString('Maputo Província', $row['Província']);
|
||||
$this->assertStringContainsString('Maputo Cidade', $row['Província']);
|
||||
$this->assertStringContainsString('contexto provincial do corredor; distrito e posto administrativo não indicados', $row['Localização e âmbito']);
|
||||
}
|
||||
foreach ($this->requests(['sector' => 'turismo', 'province_id' => $provinceId]) as $url) {
|
||||
$response = $this->getJson($url)->assertOk();
|
||||
foreach ($response->json('data') as $row) {
|
||||
|
||||
Reference in New Issue
Block a user