<?php

use App\Models\ManagedEnvironment;
use App\Models\User;
use App\Services\Auth\CapabilityResolver;
use App\Support\TenantRole;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

it('fails fast on unknown capability strings', function () {
    $tenant = ManagedEnvironment::factory()->create();

    $user = User::factory()->create();
    $user->tenants()->attach($tenant->getKey(), ['role' => TenantRole::Owner->value, 'source' => 'manual']);

    $resolver = app(CapabilityResolver::class);

    $resolver->can($user, $tenant, 'tenant_membership.managee');
})->throws(InvalidArgumentException::class);
