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->assertArrayNotHasKey('sectorDetails', $props); $ids = array_column($props['sectors'], 'id'); $this->assertSame($ids, array_values(array_unique($ids))); foreach ($props['sectors'] as $card) { $this->assertSame(\App\Services\SectorOrganization::href($card['slug']), $card['url']); $this->assertStringNotContainsString('#', $card['url']); $single = $this->get($card['url'])->assertOk()->inertiaProps(); $this->assertSame('sector', $single['section']); $this->assertSame($card['id'], $single['sector']['id']); $this->assertArrayNotHasKey('sectorDetails', $single); $this->assertArrayNotHasKey('sectors', $single); $this->assertIsArray($single['sectorEntry']['articles']); $this->assertIsArray($single['sectorEntry']['relations']); $this->assertIsArray($single['sectorEntry']['locations']); } $entry = $this->get('/sectores/'.$withoutGuide->slug)->assertOk()->inertiaProps()['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(); $this->assertArrayNotHasKey('sectorDetails', $props); $ids = array_column($props['sectors'], 'id'); $this->assertNotContains($unpublished->id, $ids); $this->assertNotContains($inactive->id, $ids); $detail = $this->get('/sectores/'.$public->slug)->assertOk()->inertiaProps(); $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(); } public function test_selecting_a_sector_keeps_opportunities_scoped_on_reload_and_return(): void { $a = $this->sector();$b = $this->sector(); foreach ([$a, $b] as $sector) { $slug = 'qa-isolated-'.Str::lower(Str::random(12)); Opportunity::create(['sector_id'=>$sector->id, 'reference'=>$slug, 'title'=>$slug, 'slug'=>$slug, 'summary'=>'Synthetic scoped opportunity', 'status'=>'published', 'published_at'=>now()->subDay()]); } $index = $this->get('/sectores')->assertOk()->inertiaProps(); foreach ([$a, $b, $a] as $sector) { $url = collect($index['sectors'])->firstWhere('id', $sector->id)['url']; $first = $this->get($url)->assertOk()->inertiaProps(); $reload = $this->get($url)->assertOk()->inertiaProps(); $this->assertSame($first['sector'], $reload['sector']); $this->assertSame($first['opportunities'], $reload['opportunities']); $this->assertSame($sector->id, $first['sector']['id']); $this->assertSame(Opportunity::where('sector_id',$sector->id)->pluck('slug')->all(), array_column($first['opportunities'],'slug')); $this->assertSame('/investimentos/a-partir-do-setor/'.$sector->slug, $first['sectorEntry']['start_href']); $this->get($first['sectorEntry']['start_href'])->assertRedirect('/login'); $returned = $this->get('/sectores')->assertOk()->inertiaProps(); $this->assertSame($index['sectors'], $returned['sectors']); $this->assertArrayNotHasKey('sectorDetails', $returned); } } }