58 lines
3.3 KiB
PHP
58 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Opportunity;
|
|
use App\Models\Sector;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Tests\TestCase;
|
|
|
|
class PublicPortalNavigationTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_home_cache_contains_only_plain_data_and_survives_restricted_unserialization(): void
|
|
{
|
|
$sector = Sector::create(['name' => 'Energia', 'slug' => 'energia-especifica', 'published_at' => now(), 'is_active' => true]);
|
|
Opportunity::create(['sector_id' => $sector->id, 'reference' => 'CACHE-1', 'title' => 'Solar',
|
|
'slug' => 'solar', 'status' => 'published', 'published_at' => now()->subMinute(), 'is_featured' => true]);
|
|
$first = $this->getJson('/api/v1/home')->assertOk()->json();
|
|
$cached = Cache::get('portal_home_sector_organization_v1_pt');
|
|
$this->assertIsArray($cached['sectors']);
|
|
$this->assertIsArray($cached['featuredOpportunities']);
|
|
$restored = unserialize(serialize($cached), ['allowed_classes' => false]);
|
|
$this->assertSame($cached, $restored);
|
|
Cache::put('portal_home_sector_organization_v1_pt', $restored);
|
|
$this->assertSame($first, $this->getJson('/api/v1/home')->assertOk()->json());
|
|
$sector->update(['name' => 'Energia actualizada']);
|
|
$this->assertNull(Cache::get('portal_home_sector_organization_v1_pt'));
|
|
$this->getJson('/api/v1/home')->assertJsonPath('data.sectors.0.name', 'Energia actualizada');
|
|
}
|
|
|
|
public function test_public_links_open_the_expected_views_without_authentication(): void
|
|
{
|
|
$sector = Sector::create(['name' => 'Energia', 'slug' => 'energia-especifica', 'published_at' => now(), 'is_active' => true]);
|
|
$opportunity = Opportunity::create(['sector_id' => $sector->id, 'reference' => 'NAV-1', 'title' => 'Solar',
|
|
'slug' => 'solar', 'status' => 'published', 'published_at' => now()->subMinute()]);
|
|
$this->get('/oportunidades?q=solar')->assertInertia(fn (Assert $page) => $page
|
|
->component('investment/catalogue')->where('filters.q', 'solar')->has('results.data', 1));
|
|
$this->get('/sectores/energia-especifica')->assertInertia(fn (Assert $page) => $page->component('portal/services')->where('section', 'sector')->where('sector.slug', 'energia-especifica')->has('opportunities', 1));
|
|
$this->get('/oportunidades/solar')->assertInertia(fn (Assert $page) => $page
|
|
->component('investment/detail')->where('record.reference', 'NAV-1'));
|
|
$this->actingAs(User::factory()->create());
|
|
$this->get('/manifestar-interesse/solar')->assertInertia(fn (Assert $page) => $page
|
|
->where('initialView', 'interest')->where('initialOpportunity.reference', 'NAV-1'));
|
|
$this->get('/manifestar-interesse')->assertInertia(fn (Assert $page) => $page
|
|
->where('initialView', 'interest')->missing('initialOpportunity'));
|
|
$opportunity->update(['status' => 'draft']);
|
|
$this->get('/oportunidades/solar')->assertNotFound();
|
|
$this->get('/manifestar-interesse/solar')->assertNotFound();
|
|
$sector->update(['is_active' => false]);
|
|
$this->get('/sectores/energia-especifica')->assertNotFound();
|
|
$this->get('/oportunidades/inexistente')->assertNotFound();
|
|
}
|
|
}
|