<?php

use App\Models\Role;
use App\Models\User;

test('técnico recibe 403 al abrir ot ajena', function () {
    $tech = createUserWithRole(Role::TECHNICIAN_NAME);
    $other = User::factory()->create();
    $work = createWorkWithUserAssignments(technician: $other);

    $this->actingAs($tech);

    $this->get(route('works.show', $work))->assertForbidden();
});

test('técnico puede abrir su ot asignada', function () {
    $tech = createUserWithRole(Role::TECHNICIAN_NAME);
    $work = createWorkWithUserAssignments(technician: $tech);

    $this->actingAs($tech);

    $this->get(route('works.show', $work))->assertOk();
});

test('coordinador puede abrir ficha de trabajo', function () {
    $coord = createUserWithRole(Role::COORDINATOR_NAME);
    $work = createWorkWithUserAssignments();

    $this->actingAs($coord);

    $this->get(route('works.show', $work))->assertOk();
});

test('noc puede abrir ficha de trabajo', function () {
    $noc = createUserWithRole(Role::NOC_NAME);
    $work = createWorkWithUserAssignments();

    $this->actingAs($noc);

    $this->get(route('works.show', $work))->assertOk();
});

test('invitado es redirigido al login', function () {
    $work = createWorkWithUserAssignments();

    $this->get(route('works.show', $work))->assertRedirect(route('login'));
});
