createUser('reader@example.com'); $otherUser = $this->createUser('creator@example.com'); $repository = app(SetRepository::class); $course = $repository->create(new CreateSetDto( name: 'Course', creator: $authenticatedUser, )); $bible = $repository->create(new CreateSetDto( name: 'Bible', creator: $otherUser, )); $this->createSession($authenticatedUser); $response = $this->withCredentials() ->withUnencryptedCookie( AuthMiddleware::COOKIE_NAME, 'valid-token', )->getJson('/api/sets'); $response->assertOk()->assertExactJson([ 'sets' => [ [ 'id' => $bible->getId(), 'name' => 'Bible', ], [ 'id' => $course->getId(), 'name' => 'Course', ], ], ]); } public function test_it_returns_an_empty_catalog(): void { $authenticatedUser = $this->createUser('reader@example.com'); $this->createSession($authenticatedUser); $response = $this->withCredentials() ->withUnencryptedCookie( AuthMiddleware::COOKIE_NAME, 'valid-token', )->getJson('/api/sets'); $response->assertOk()->assertExactJson(['sets' => []]); } public function test_it_rejects_an_unauthenticated_request(): void { $response = $this->getJson('/api/sets'); $response ->assertStatus(401) ->assertExactJson(['error' => 'unauthenticated']); } private function createUser(string $email): User { return app(UserRepository::class)->create(new CreateUserDto( email: new EmailAddress($email), passwordHash: 'hashed-password', )); } private function createSession(User $user): void { $createdAt = new DateTimeImmutable( '2026-08-03T12:00:00', new DateTimeZone('UTC'), ); app(SessionRepository::class)->create(new CreateSessionDto( token: 'valid-token', user: $user, createdAt: $createdAt, expiresAt: $createdAt->modify('+10 years'), )); } }