<?php

namespace Tests\Feature;

use App\Http\Middleware\UseSuperAdminSession;
use Illuminate\Http\Request;
use Tests\TestCase;

class SuperAdminSessionMiddlewareTest extends TestCase
{
    public function test_middleware_sets_super_admin_session_cookie_for_super_admin_routes(): void
    {
        config(['session.cookie' => 'laravel_session']);

        $middleware = new UseSuperAdminSession;
        $request = Request::create('/super-admin', 'GET');

        $middleware->handle($request, function () {
            return response('ok');
        });

        $this->assertSame('super_admin_session', config('session.cookie'));
    }

    public function test_middleware_sets_super_admin_session_cookie_for_livewire_requests_with_super_admin_referer(): void
    {
        config(['session.cookie' => 'laravel_session']);

        $middleware = new UseSuperAdminSession;
        $request = Request::create('/livewire/update', 'POST');
        $request->headers->set('referer', 'https://fotospiel.test/super-admin/login');

        $middleware->handle($request, function () {
            return response('ok');
        });

        $this->assertSame('super_admin_session', config('session.cookie'));
    }

    public function test_middleware_keeps_default_session_cookie_for_regular_routes(): void
    {
        config(['session.cookie' => 'laravel_session']);

        $middleware = new UseSuperAdminSession;
        $request = Request::create('/checkout', 'GET');

        $middleware->handle($request, function () {
            return response('ok');
        });

        $this->assertSame('laravel_session', config('session.cookie'));
    }
}
