@@ -14,6 +14,7 @@ use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Tests\Support\CleanScannerFixture;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -96,6 +97,38 @@ class OpportunityResourcesTest extends TestCase
|
||||
$this->assertDatabaseHas('opportunity_location_drafts', ['id' => $id, 'deleted_at' => null]);
|
||||
}
|
||||
|
||||
public function test_foreign_country_rejects_mozambican_hierarchy_without_changing_the_saved_draft(): void
|
||||
{
|
||||
[$user, $o] = $this->setupDraft();
|
||||
$province = (string) Str::uuid();
|
||||
$district = (string) Str::uuid();
|
||||
DB::table('geo_locations')->insert([
|
||||
['id' => $province, 'code' => $province, 'name' => 'Synthetic QA Mozambique province', 'location_type' => 'province', 'parent_id' => null, 'data_classification' => 'public'],
|
||||
['id' => $district, 'code' => $district, 'name' => 'Synthetic QA Mozambique district', 'location_type' => 'district', 'parent_id' => $province, 'data_classification' => 'public'],
|
||||
]);
|
||||
$payload = ['title' => 'Synthetic QA saved location', 'country_code' => 'MZ', 'province_id' => $province, 'district_id' => $district, 'role' => 'market'];
|
||||
$id = $this->postJson('/management/opportunities/'.$o->id.'/resources/locations', $this->payload($o, $payload))->assertCreated()->json('id');
|
||||
$before = DB::table('opportunity_location_drafts')->where('id', $id)->first();
|
||||
$auditBefore = DB::table('audit_events')->where('source_system', 'opportunity-resources')->count();
|
||||
|
||||
$input = [...$this->payload($o->fresh(), [...$payload, 'country_code' => 'PT']), 'version' => 1];
|
||||
$this->postJson('/management/opportunities/'.$o->id.'/resources/locations/'.$id, $input)
|
||||
->assertUnprocessable()->assertJsonValidationErrors('country_code');
|
||||
$after = DB::table('opportunity_location_drafts')->where('id', $id)->first();
|
||||
$this->assertSame($before->payload, $after->payload);
|
||||
$this->assertSame(1, $after->version);
|
||||
$this->assertSame($auditBefore, DB::table('audit_events')->where('source_system', 'opportunity-resources')->count());
|
||||
|
||||
$foreign = $this->postJson('/management/opportunities/'.$o->id.'/resources/locations',
|
||||
$this->payload($o->fresh(), ['title' => 'Synthetic QA foreign incomplete location', 'country_code' => 'PT', 'role' => 'market']))->assertCreated()->json('id');
|
||||
$saved = json_decode(DB::table('opportunity_location_drafts')->where('id', $foreign)->value('payload'), true);
|
||||
$this->assertSame('PT', $saved['country_code']);
|
||||
$this->assertEmpty($saved['province_id'] ?? null);
|
||||
$this->assertSame(0, DB::table('opportunity_locations')->count());
|
||||
$this->get('/management/opportunities/'.$o->id.'/resources')->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->where('assessment', fn ($issues) => collect($issues)->every(fn ($issue) => ! str_contains($issue, 'província') && ! str_contains($issue, 'distrito'))));
|
||||
}
|
||||
|
||||
public function test_invalid_upload_and_cross_opportunity_links_do_not_create_resources(): void
|
||||
{
|
||||
[$user,$o] = $this->setupDraft();
|
||||
|
||||
Reference in New Issue
Block a user