<?php

declare(strict_types=1);

use App\Models\User;
use App\Models\Workspace;
use App\Models\WorkspaceMembership;
use App\Support\Workspaces\WorkspaceContext;

it('allows a workspace member to open the workspace overview without tenant context', function (): void {
    $user = User::factory()->create();
    $workspace = Workspace::factory()->create(['name' => 'Northwind Workspace']);

    WorkspaceMembership::factory()->create([
        'workspace_id' => (int) $workspace->getKey(),
        'user_id' => (int) $user->getKey(),
        'role' => 'readonly',
    ]);

    $this->actingAs($user)
        ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
        ->get(route('admin.workspace.home', ['workspace' => $workspace]))
        ->assertOk()
        ->assertSee('Workspace overview')
        ->assertSee('Northwind Workspace');
});
