<?php

use App\Models\QrCode;
use App\Models\User;

test('guests are redirected to the login page for all qr code pages', function (string $routeName) {
    $qrCode = QrCode::factory()->create();

    $route = $routeName === 'admin.qr-codes.show'
        ? route($routeName, $qrCode)
        : route($routeName);

    $this->get($route)->assertRedirect(route('login'));
})->with([
    'admin.qr-codes',
    'admin.qr-codes.create',
    'admin.qr-codes.show',
]);

test('non admin users receive a 403 for all qr code pages', function (string $routeName) {
    $user = User::factory()->create(['is_admin' => false]);
    $qrCode = QrCode::factory()->create();

    $route = $routeName === 'admin.qr-codes.show'
        ? route($routeName, $qrCode)
        : route($routeName);

    $this->actingAs($user)->get($route)->assertForbidden();
})->with([
    'admin.qr-codes',
    'admin.qr-codes.create',
    'admin.qr-codes.show',
]);

test('admins can access all qr code pages', function (string $routeName) {
    $admin = User::factory()->admin()->create();
    $qrCode = QrCode::factory()->create();

    $route = $routeName === 'admin.qr-codes.show'
        ? route($routeName, $qrCode)
        : route($routeName);

    $this->actingAs($admin)->get($route)->assertOk();
})->with([
    'admin.qr-codes',
    'admin.qr-codes.create',
    'admin.qr-codes.show',
]);
