Files
Investidor-V2/tests/Feature/ExistingBusinessWizardTest.php
T
nala 3dc7c5c649
tests / ci (push) Canceled after 0s
commit 30/9
2026-09-30 09:05:43 +02:00

70 lines
4.9 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;
class ExistingBusinessWizardTest extends TestCase
{
use RefreshDatabase;
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');
$migration->down();
$this->assertFalse(Schema::hasColumn('existing_businesses', 'sector_id'));
$migration->up();
$this->assertTrue(Schema::hasColumn('existing_businesses', 'sector_id'));
config(['existing-business.enabled' => true]);
$sector = DB::table('sectors')->insertGetId(['name' => 'Synthetic', 'slug' => 'rollback-synthetic', 'is_active' => true]);
$this->actingAs(User::factory()->create())->postJson('/api/v1/existing-business/listings', [
'modality' => 'company_sale', 'classification' => 'confidential', 'reason' => 'Synthetic rollback check',
'sector_id' => $sector, 'payload' => ['title' => 'Synthetic rollback'],
])->assertCreated();
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Sector associations exist');
$migration->down();
}
public function test_draft_resume_validation_concurrency_confirmation_and_private_submission(): void
{
config(['existing-business.enabled' => true]);
$owner = User::factory()->create();
$sector = DB::table('sectors')->insertGetId(['name' => 'Synthetic', 'slug' => 'wizard-synthetic', 'is_active' => true]);
$this->actingAs($owner);
$draft = ['modality' => 'company_sale', 'classification' => 'confidential', 'reason' => 'Synthetic form draft', 'payload' => ['title' => 'Synthetic wizard', 'wizard_version' => '1', 'wizard_step' => '1']];
$record = $this->postJson('/api/v1/existing-business/listings', $draft)->assertCreated()->json();
$url = '/api/v1/existing-business/listings/'.$record['id'];
$transition = ['action' => 'submitted', 'version_no' => 1, 'note' => 'Synthetic submission request', 'review_consent' => true, 'confirmation_code' => $record['code']];
$this->postJson($url.'/transitions', $transition)->assertUnprocessable();
$payload = [...$draft['payload'], 'wizard_step' => '8', 'proponent_type' => 'person', 'proponent_name' => 'Synthetic owner',
'tax_identifier' => 'SYNTHETIC', 'contact_email' => 'synthetic@example.test', 'country' => 'MZ', 'acting_capacity' => 'representative',
'declared_holder' => 'Synthetic holder', 'legitimacy_declaration' => 'yes', 'location_notes' => 'Synthetic private location',
'description' => 'Synthetic description long enough for review.', 'source_reference' => 'Synthetic source reference',
'valid_until' => today()->addMonth()->toDateString(), 'asking_value' => '1234.50', 'currency' => 'MZN', 'value_nature' => 'asking'];
$save = [...$draft, 'version_no' => 1, 'sector_id' => $sector, 'payload' => $payload];
$this->putJson($url, [...$save, 'payload' => [...$payload, 'equity_percentage' => '101']])->assertUnprocessable();
$this->putJson($url, $save)->assertOk()->assertJsonPath('version_no', 2);
$this->getJson($url)->assertOk()->assertJsonPath('record.payload.wizard_step', '8')->assertJsonPath('record.sector_id', $sector);
$this->putJson($url, $save)->assertConflict();
$this->postJson($url.'/transitions', [...$transition, 'version_no' => 2])->assertUnprocessable()->assertJsonValidationErrors('mandate_reference');
$payload['mandate_reference'] = 'Synthetic mandate reference';
$payload['mandate_valid_until'] = today()->addMonth()->toDateString();
$this->putJson($url, [...$save, 'version_no' => 2, 'payload' => $payload])->assertOk();
$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])->assertOk()->assertJsonPath('status', 'submitted');
$this->postJson($url.'/transitions', [...$transition, 'version_no' => 5])->assertConflict();
$this->actingAs(User::factory()->create())->getJson($url)->assertForbidden();
$this->assertDatabaseCount('existing_business_reviews', 1);
$raw = DB::table('existing_businesses')->where('id', $record['id'])->value('payload');
$this->assertStringNotContainsString('synthetic@example.test', $raw);
}
}