Files
Investidor-V2/tests/Feature/OpportunityPublicationScopeTest.php
nala 01405cbf8a
tests / ci (push) Canceled after 0s
oportunidades 5
2026-10-10 14:15:28 +02:00

35 lines
1.8 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Opportunity;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class OpportunityPublicationScopeTest extends TestCase
{
use RefreshDatabase;
public function test_approval_restricted_and_public_labels_follow_actual_catalog_policy(): void
{
$owner = User::factory()->create();
$id = DB::table('opportunities')->insertGetId(['reference' => 'QA-publication-scope', 'slug' => 'qa-publication-scope', 'status' => 'approved',
'owner_user_id' => $owner->id, 'workflow_context' => json_encode(['publication' => ['visibility' => 'public']])]);
$record = Opportunity::findOrFail($id);
$this->assertSame('unpublished', $record->publicationPresentation()['scope']);
$record->forceFill(['status' => 'published', 'published_at' => now(), 'workflow_context' => ['publication' => ['visibility' => 'internal']]])->save();
$this->assertSame('restricted', $record->publicationPresentation()['scope']);
$this->assertFalse($record->publicationPresentation()['public_catalog']);
$this->assertFalse(Opportunity::published()->whereKey($id)->exists());
$record->forceFill(['workflow_context' => ['publication' => ['visibility' => 'public']]])->save();
$this->assertTrue($record->publicationPresentation()['public_catalog']);
$this->assertSame('public', $record->publicationPresentation()['scope']);
$record->forceFill(['status' => 'suspended'])->save();
$this->assertSame('unpublished', $record->publicationPresentation()['scope']);
$record->forceFill(['status' => 'published', 'published_at' => now()->addDay()])->save();
$this->assertFalse($record->publicationPresentation()['public_catalog']);
}
}