Files
construprogress/tests/Feature/TemplatesAccessTest.php
T
javierandClaude Opus 4.8 484351459a feat(templates): accesos a la página de plantillas de inspección
No había forma de llegar a projects.templates. Añadidos dos accesos, gateados con
@can('edit projects') (mismo permiso que protege la ruta):
- Dashboard del proyecto: botón "Plantillas" junto a "Mapa".
- Mapa: enlace "Gestionar plantillas" junto al selector de plantilla.

Test: TemplatesAccessTest (403 sin permiso, 200 con edit projects). Suite 77 passing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 11:45:03 +02:00

50 lines
1.4 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Project;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Spatie\Permission\Models\Permission;
use Tests\TestCase;
class TemplatesAccessTest extends TestCase
{
use RefreshDatabase;
private function project(User $owner): Project
{
return Project::create([
'reference' => 'TPL-1', 'name' => 'Proyecto Plantillas', 'address' => 'x',
'lat' => 40.0, 'lng' => -3.0, 'start_date' => now()->toDateString(),
'end_date_estimated' => now()->addMonth()->toDateString(),
'status' => 'in_progress', 'created_by' => $owner->id,
]);
}
public function test_templates_page_requires_edit_projects_permission(): void
{
Permission::findOrCreate('edit projects');
$user = User::factory()->create(); // sin permiso
$project = $this->project($user);
$this->actingAs($user)
->get(route('projects.templates', $project))
->assertForbidden();
}
public function test_templates_page_accessible_with_edit_projects_permission(): void
{
Permission::findOrCreate('edit projects');
$user = User::factory()->create();
$user->givePermissionTo('edit projects');
$project = $this->project($user);
$this->actingAs($user)
->get(route('projects.templates', $project))
->assertOk();
}
}