withoutVite(); config(['portal.legacy_content_enabled' => false, 'portal.legacy_content_qa_enabled' => false, 'investor-path.enabled' => true, 'portal.profile_access_enabled' => true]); } private function sector(array $attributes = []): Sector { return Sector::create([...['name' => 'Sector sintético QA', 'slug' => 'qa-sector-'.Str::lower(Str::random(12)), 'short_description' => 'Exemplo isolado para a reposição.', 'is_active' => true, 'published_at' => now()->subDay()], ...$attributes]); } public function test_complete_catalogue_matches_public_sector_pages_including_sectors_without_guides(): void { $withoutGuide = $this->sector(); $this->assertArrayNotHasKey($withoutGuide->slug, SectorInvestment::CONTENT); $before = [DB::table('desk_cases')->count(), DB::table('opportunities')->count(), DB::table('portal_resources')->count()]; $props = $this->get('/sectores')->assertOk()->inertiaProps(); $this->assertSame(array_column($props['sectors'], 'id'), array_column(array_column($props['sectorDetails'], 'sector'), 'id')); foreach ($props['sectorDetails'] as $detail) { $single = $this->get('/sectores/'.$detail['sector']['slug'])->assertOk()->inertiaProps(); $this->assertSame($single['sector'], $detail['sector']); $this->assertSame($single['sectorEntry'], $detail['sectorEntry']); $this->assertSame($single['opportunities'], $detail['opportunities']); $this->assertIsArray($detail['sectorEntry']['articles']); $this->assertIsArray($detail['sectorEntry']['relations']); $this->assertIsArray($detail['sectorEntry']['locations']); } $entry = collect($props['sectorDetails'])->firstWhere('sector.id', $withoutGuide->id)['sectorEntry']; $this->assertSame([], $entry['articles']); $this->assertSame('/minhas-oportunidades/create?sector_id='.$withoutGuide->id, $entry['register_href']); $this->assertNotNull($entry['start_href']); $this->assertGuest(); $this->assertSame($before, [DB::table('desk_cases')->count(), DB::table('opportunities')->count(), DB::table('portal_resources')->count()]); } public function test_full_catalogue_preserves_publication_boundaries_and_private_tool_notices(): void { $public = $this->sector(); $unpublished = $this->sector(['published_at' => null]); $inactive = $this->sector(['is_active' => false]); $slugs = []; foreach (['published', 'draft', 'future'] as $state) { $slug = 'qa-sector-opportunity-'.Str::lower(Str::random(12)); $slugs[$state] = $slug; Opportunity::create(['sector_id' => $public->id, 'reference' => $slug, 'title' => $state, 'slug' => $slug, 'summary' => 'Conteúdo sintético de teste.', 'status' => $state === 'draft' ? 'draft' : 'published', 'published_at' => $state === 'future' ? now()->addDay() : now()->subDay()]); } config(['investor-path.enabled' => false, 'portal.profile_access_enabled' => false]); $props = $this->get('/sectores')->assertOk()->inertiaProps(); $ids = array_column(array_column($props['sectorDetails'], 'sector'), 'id'); $this->assertNotContains($unpublished->id, $ids); $this->assertNotContains($inactive->id, $ids); $detail = collect($props['sectorDetails'])->firstWhere('sector.id', $public->id); $this->assertSame([$slugs['published']], array_column($detail['opportunities'], 'slug')); $this->assertNull($detail['sectorEntry']['start_href']); $this->assertNull($detail['sectorEntry']['register_href']); $this->assertNotEmpty($detail['sectorEntry']['start_notice']); $this->assertNotEmpty($detail['sectorEntry']['register_notice']); $this->get('/sectores/'.$unpublished->slug)->assertNotFound(); $this->get('/sectores/'.$inactive->slug)->assertNotFound(); } }