Files
Investidor-V2/tests/Unit/InvestmentConsumerScopeTest.php
T

40 lines
1.6 KiB
PHP

<?php
namespace Tests\Unit;
use App\Services\InvestmentConsumerScope;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Tests\TestCase;
class InvestmentConsumerScopeTest extends TestCase
{
public function test_an_explicit_opportunity_cannot_be_silently_discarded_when_the_dossier_has_no_choices(): void
{
$context = ['fields' => ['project_title' => 'Synthetic QA dossier'], 'selection' => [], 'opportunity_choices' => []];
try {
app(InvestmentConsumerScope::class)->context($context, 'opportunity:99999999');
$this->fail('An explicit opportunity outside the dossier must be rejected instead of becoming general context.');
} catch (HttpException $error) {
$this->assertSame(422, $error->getStatusCode());
$this->assertSame([], $context['opportunity_choices']);
$this->assertSame('Synthetic QA dossier', $context['fields']['project_title']);
}
}
public function test_general_context_without_an_opportunity_preserves_an_empty_dossier(): void
{
$context = ['fields' => ['project_title' => 'Synthetic QA dossier'], 'selection' => []];
$this->assertSame($context, app(InvestmentConsumerScope::class)->context($context, null));
}
public function test_an_explicit_opportunity_outside_existing_choices_is_rejected(): void
{
$context = ['fields' => [], 'selection' => [], 'opportunity_choices' => [['opportunity' => ['key' => 'opportunity:1']]]];
$this->expectException(HttpException::class);
app(InvestmentConsumerScope::class)->context($context, 'opportunity:2');
}
}