create(new CreateUserDto( email: new EmailAddress('user@example.com'), passwordHash: 'hashed-password', )); app(SessionRepository::class)->create(new CreateSessionDto( token: 'valid-token', user: $user, createdAt: $now, expiresAt: $now->modify('+7 days'), )); $response = $this->withCredentials() ->withUnencryptedCookie( AuthMiddleware::COOKIE_NAME, 'valid-token', )->getJson('/api/me'); $response->assertOk()->assertExactJson([ 'user' => [ 'id' => $user->getId(), 'email' => 'user@example.com', ], ]); } public function test_me_rejects_a_request_without_a_cookie(): void { $response = $this->getJson('/api/me'); $response ->assertStatus(401) ->assertExactJson(['error' => 'unauthenticated']); } public function test_me_allows_credentialed_frontend_requests(): void { $response = $this->withHeaders([ 'Origin' => 'https://localhost:5173', 'Access-Control-Request-Method' => 'GET', ])->options('/api/me'); $response ->assertNoContent() ->assertHeader( 'Access-Control-Allow-Origin', 'https://localhost:5173', ) ->assertHeader('Access-Control-Allow-Credentials', 'true'); } }