Files
amare/tests/Feature/Marketing/ServiceCatalogTest.php
manoel freitas 8da8d19504 feat: CMS de conteúdo do site (WEB-02/03/04/06)
Implementa gestão Filament de configurações, serviços, portfólio e depoimentos com policies admin-only, upload validado e seed determinístico.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-28 23:16:25 -03:00

69 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Marketing;
use App\Filament\Resources\Services\Pages\ListServices;
use App\Models\Service;
use App\Models\User;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Livewire\Livewire;
use Tests\TestCase;
class ServiceCatalogTest extends TestCase
{
use RefreshDatabase;
public function test_published_scope_excludes_unpublished_services(): void
{
Service::factory()->create(['published_at' => null]);
$published = Service::factory()->published()->create();
$this->assertCount(1, Service::query()->published()->get());
$this->assertTrue(Service::query()->published()->first()?->is($published));
}
public function test_slug_uniqueness_is_enforced(): void
{
Service::factory()->create(['slug' => 'casamentos']);
$this->expectException(QueryException::class);
Service::factory()->create(['slug' => 'casamentos']);
}
public function test_assistant_cannot_access_services_resource(): void
{
$assistant = User::factory()->assistant()->create();
$this->actingAs($assistant);
Livewire::test(ListServices::class)
->assertForbidden();
}
public function test_admin_can_access_services_resource(): void
{
$admin = User::factory()->admin()->create();
$this->actingAs($admin);
Livewire::test(ListServices::class)
->assertSuccessful();
}
public function test_publication_uses_published_at_timestamp(): void
{
$publishedAt = Carbon::parse('2026-02-01 12:00:00');
$service = Service::factory()->create([
'published_at' => $publishedAt,
]);
$this->assertTrue(Service::query()->published()->whereKey($service->id)->exists());
}
}