<?php

declare(strict_types=1);

use App\Models\User;
use App\Models\Workspace;
use App\Models\WorkspaceMembership;
use App\Support\Workspaces\WorkspaceContext;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;

uses(RefreshDatabase::class);

it('does not make outbound HTTP requests when rendering db-only auth pages', function () {
    Http::preventStrayRequests();

    $this->get('/admin/login')->assertOk();

    $user = User::factory()->create();

    $workspace = Workspace::factory()->create();

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

    $this->actingAs($user)->withSession([
        WorkspaceContext::SESSION_KEY => (int) $workspace->getKey(),
    ]);

    $this->get('/admin/no-access')->assertOk();
    $this->get('/admin/choose-environment')->assertOk();
});
