@@ -6,12 +6,26 @@ use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExistingBusinessWizardTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function publicLocation(string $type, ?string $parent = null): string
|
||||
{
|
||||
$id = (string) Str::uuid();
|
||||
DB::table('geo_locations')->insert([
|
||||
'id' => $id, 'source_system' => 'cartografia-workbook',
|
||||
'external_id' => '964a187ad32ea553b9e112cd159caa90b900050c42b7329594a75bcd798a96ff:'.$id,
|
||||
'version_no' => 1, 'data_classification' => 'public', 'name' => 'Synthetic '.$type.' '.$id,
|
||||
'location_type' => $type, 'parent_id' => $parent, 'code' => $id,
|
||||
]);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function test_sector_migration_reverses_empty_and_refuses_data_loss(): void
|
||||
{
|
||||
$migration = require database_path('migrations/2026_09_29_200000_existing_business_form_sector.php');
|
||||
@@ -58,7 +72,8 @@ class ExistingBusinessWizardTest extends TestCase
|
||||
$this->putJson($url, [...$save, 'version_no' => 3, 'payload' => $payload, 'modality' => 'real_estate'])->assertOk();
|
||||
$this->postJson($url.'/transitions', [...$transition, 'version_no' => 4])->assertUnprocessable()->assertJsonValidationErrors('objects');
|
||||
$this->putJson($url, [...$save, 'version_no' => 4, 'payload' => $payload])->assertOk();
|
||||
$this->postJson($url.'/transitions', [...$transition, 'version_no' => 5, 'confirmation_code' => 'wrong'])->assertUnprocessable();
|
||||
$this->postJson($url.'/transitions', [...$transition, 'version_no' => 5, 'confirmation_code' => 'wrong'])
|
||||
->assertUnprocessable()->assertJsonValidationErrors('confirmation_code');
|
||||
$this->postJson($url.'/transitions', [...$transition, 'version_no' => 5])->assertOk()->assertJsonPath('status', 'submitted');
|
||||
$this->postJson($url.'/transitions', [...$transition, 'version_no' => 5])->assertConflict();
|
||||
$this->actingAs(User::factory()->create())->getJson($url)->assertForbidden();
|
||||
@@ -66,4 +81,87 @@ class ExistingBusinessWizardTest extends TestCase
|
||||
$raw = DB::table('existing_businesses')->where('id', $record['id'])->value('payload');
|
||||
$this->assertStringNotContainsString('synthetic@example.test', $raw);
|
||||
}
|
||||
|
||||
public function test_multiple_locations_require_distinct_public_paths_from_the_same_hierarchy(): void
|
||||
{
|
||||
config(['existing-business.enabled' => true]);
|
||||
$owner = User::factory()->create();
|
||||
$sector = DB::table('sectors')->insertGetId(['name' => 'Synthetic locations', 'slug' => 'synthetic-locations', 'is_active' => true]);
|
||||
$country = $this->publicLocation('country');
|
||||
$provinceA = $this->publicLocation('province', $country);
|
||||
$provinceB = $this->publicLocation('province', $country);
|
||||
$districtA = $this->publicLocation('district', $provinceA);
|
||||
$districtB = $this->publicLocation('district', $provinceB);
|
||||
$this->actingAs($owner);
|
||||
|
||||
$payload = [
|
||||
'title' => 'Synthetic multiple-location opportunity', 'wizard_version' => '2', 'wizard_step' => '8',
|
||||
'proponent_type' => 'organization', 'proponent_name' => 'Synthetic proponent', 'country' => 'MZ',
|
||||
'contact_name' => 'Synthetic contact', 'contact_email' => 'locations@example.test',
|
||||
'acting_capacity' => 'holder', 'legitimacy_declaration' => 'yes',
|
||||
'opportunity_type' => 'company_sale',
|
||||
'description' => 'Synthetic description with sufficient detail for review.',
|
||||
'project_stage' => 'study', 'availability' => 'available', 'value_status' => 'unknown',
|
||||
'geography_scope' => 'multiple', 'source_reference' => 'Synthetic source reference',
|
||||
'source_provider' => 'Synthetic information provider', 'source_date' => today()->toDateString(),
|
||||
'asset_deal_kind' => 'whole_business', 'confirm_information' => 'yes',
|
||||
'confirm_disclosure_authority' => 'yes', 'confirm_no_publication_guarantee' => 'yes',
|
||||
'locations_json' => json_encode([['province_id' => $provinceA]], JSON_THROW_ON_ERROR),
|
||||
];
|
||||
$id = $this->postJson('/api/v1/existing-business/listings', [
|
||||
'modality' => 'company_sale', 'classification' => 'confidential', 'reason' => 'Synthetic multiple-location draft',
|
||||
'sector_id' => $sector, 'payload' => $payload,
|
||||
])->assertCreated()->json('id');
|
||||
$url = '/api/v1/existing-business/listings/'.$id;
|
||||
$transition = ['action' => 'submitted', 'version_no' => 1, 'note' => 'Synthetic multiple-location submission',
|
||||
'review_consent' => true, 'confirmation_code' => DB::table('existing_businesses')->where('id', $id)->value('code')];
|
||||
|
||||
$this->postJson($url.'/transitions', $transition)->assertUnprocessable()->assertJsonValidationErrors('locations');
|
||||
$overlapping = [
|
||||
['province_id' => $provinceA],
|
||||
['province_id' => $provinceA, 'district_id' => $districtA],
|
||||
];
|
||||
$this->putJson($url, ['modality' => 'company_sale', 'classification' => 'confidential',
|
||||
'reason' => 'Synthetic overlapping location update', 'version_no' => 1, 'sector_id' => $sector,
|
||||
'payload' => [...$payload, 'locations_json' => json_encode($overlapping, JSON_THROW_ON_ERROR)]])->assertOk();
|
||||
$this->postJson($url.'/transitions', [...$transition, 'version_no' => 2])
|
||||
->assertUnprocessable()->assertJsonValidationErrors('locations_json');
|
||||
|
||||
$wrongParent = [
|
||||
['province_id' => $provinceA, 'district_id' => $districtA],
|
||||
['province_id' => $provinceA, 'district_id' => $districtB],
|
||||
];
|
||||
$this->putJson($url, ['modality' => 'company_sale', 'classification' => 'confidential',
|
||||
'reason' => 'Synthetic invalid hierarchy update', 'version_no' => 2, 'sector_id' => $sector,
|
||||
'payload' => [...$payload, 'locations_json' => json_encode($wrongParent, JSON_THROW_ON_ERROR)]])->assertOk();
|
||||
$this->postJson($url.'/transitions', [...$transition, 'version_no' => 3])
|
||||
->assertUnprocessable()->assertJsonValidationErrors('district_id');
|
||||
|
||||
$valid = [
|
||||
['province_id' => $provinceA, 'district_id' => $districtA],
|
||||
['province_id' => $provinceB, 'district_id' => $districtB],
|
||||
];
|
||||
$this->putJson($url, ['modality' => 'company_sale', 'classification' => 'confidential',
|
||||
'reason' => 'Synthetic distinct location update', 'version_no' => 3, 'sector_id' => $sector,
|
||||
'payload' => [...$payload, 'locations_json' => json_encode($valid, JSON_THROW_ON_ERROR)]])->assertOk();
|
||||
$this->postJson($url.'/transitions', [...$transition, 'version_no' => 4])
|
||||
->assertOk()->assertJsonPath('status', 'submitted');
|
||||
$this->getJson($url)->assertOk()->assertJsonPath('record.payload.locations_json', json_encode($valid, JSON_THROW_ON_ERROR));
|
||||
}
|
||||
|
||||
public function test_public_territory_search_matches_names_with_or_without_accents(): void
|
||||
{
|
||||
$country = $this->publicLocation('country');
|
||||
$province = $this->publicLocation('province', $country);
|
||||
DB::table('geo_locations')->where('id', $province)->update([
|
||||
'name' => 'Província de Mapúto', 'code' => 'MPT-ACCENT',
|
||||
]);
|
||||
|
||||
$this->getJson('/api/v1/investment/territory-options?type=province&q=maputo')
|
||||
->assertOk()->assertJsonPath('data.0.id', $province);
|
||||
$this->getJson('/api/v1/investment/territory-options?type=province&q=provincia')
|
||||
->assertOk()->assertJsonPath('data.0.id', $province);
|
||||
$this->getJson('/api/v1/investment/territory-options?type=province&q=Mapúto')
|
||||
->assertOk()->assertJsonPath('data.0.id', $province);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user