59 lines
3.0 KiB
PHP
59 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Opportunity;
|
|
use App\Models\User;
|
|
use App\Services\InvestorContext;
|
|
use App\Services\PortalProfileAdministration;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Str;
|
|
use Tests\TestCase;
|
|
|
|
/** Acceptance audit only: no change to the product's contracts or access rules. */
|
|
final class OfferInvestmentAcceptanceAuditTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private function prepare(): array
|
|
{
|
|
$this->withoutVite();
|
|
config(['portal.profile_access_enabled' => true]);
|
|
$owner = User::factory()->create();
|
|
app(PortalProfileAdministration::class)->insertGrant((string) Str::uuid(), User::factory()->create(), [
|
|
'user_id' => $owner->id, 'role' => 'promoter', 'organization_id' => null,
|
|
'opportunity_types' => ['business_sale'], 'source' => 'synthetic-acceptance-audit',
|
|
]);
|
|
$payload = ['creation_key' => (string) Str::uuid(), 'opportunity_category' => 'business_sale',
|
|
'title' => 'Synthetic acquisition acceptance', 'description' => 'Existing company description to reuse once in investment preparation.',
|
|
'private_offer' => ['price_mode' => 'amount', 'amount' => '120000.00', 'currency' => 'MZN',
|
|
'business' => ['revenue' => '60000.00', 'cash_flow' => '20000.00', 'currency' => 'MZN']],
|
|
'reason' => 'Synthetic final acceptance integration audit only.'];
|
|
$record = $this->actingAs($owner)->postJson('/minhas-oportunidades/ofertas/rascunhos', $payload)->assertCreated()->json('record');
|
|
|
|
return [$owner, $record, $payload];
|
|
}
|
|
|
|
public function test_saved_offer_reuses_its_description_in_the_existing_investment_context(): void
|
|
{
|
|
[$owner, $record, $payload] = $this->prepare();
|
|
$reference = app(InvestorContext::class)->reference('opportunity:'.$record['id']);
|
|
$this->assertSame('private', $reference['visibility']);
|
|
$this->assertSame($payload['title'], $reference['fields']['project_title']);
|
|
$this->assertSame($payload['description'], $reference['fields']['project_summary'] ?? null,
|
|
'Write once/read always: the existing description must not disappear at the investment-context boundary.');
|
|
}
|
|
|
|
public function test_native_context_options_do_not_disclose_another_owners_private_offer(): void
|
|
{
|
|
[$owner, $record, $payload] = $this->prepare();
|
|
$this->getJson('/minhas-oportunidades/ofertas/'.$record['id'])->assertOk()
|
|
->assertJsonPath('record.values.private_offer.business.revenue', '60000.00')
|
|
->assertJsonPath('record.values.private_offer.business.cash_flow', '20000.00');
|
|
$this->assertFalse(Opportunity::published()->whereKey($record['id'])->exists());
|
|
$this->actingAs(User::factory()->create());
|
|
$this->assertNotContains('opportunity:'.$record['id'], array_column(app(InvestorContext::class)->options(), 'key'));
|
|
$this->getJson('/minhas-oportunidades/ofertas/'.$record['id'])->assertForbidden();
|
|
}
|
|
}
|