<?php

$_SERVER['REQUEST_URI'] = '/test-permissions';

app_require('classes/permission_node.php');
app_require('modules/subusers/helpers/subusers_permission_node_key.php');
app_require('traits/route_t.php');

use classes\permission_node;
use modules\subusers\helpers\subusers_permission_node_key;
use traits\route_t;

class PermissionRouteTestHost
{
    use route_t;

    public function __construct()
    {
        // no-op for unit tests
    }
}

it('creates permission nodes linked to subuser permission keys', function (): void {
    $host = new PermissionRouteTestHost();
    $node = $host->definePermission('list_own_bookings', subusers_permission_node_key::BOOKINGS_LIST);

    expect($node)->toBeInstanceOf(permission_node::class);
    expect($node->permission)->toBe('list_own_bookings');
    expect($node->subusers_node_key)->toBe(subusers_permission_node_key::BOOKINGS_LIST);
});

it('rejects empty permission definitions', function (): void {
    $host = new PermissionRouteTestHost();
    $host->definePermission('');
})->throws(\Exception::class, 'Permission cannot be empty');

