Skip to content

Conversation

@ntatoud
Copy link
Member

@ntatoud ntatoud commented Nov 16, 2025

Summary by CodeRabbit

  • New Features

    • Added end-to-end user management tests (create, edit, delete) with access-control checks.
    • Added reusable authentication setup for pre-authenticated test contexts and test utilities to simplify login and navigation.
  • Chores

    • Added an e2e:setup npm script and updated test configuration to include a setup project.
    • Ignored generated e2e auth files from source control.
  • Documentation

    • Updated README with e2e commands and a warning about regenerated auth context files.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 16, 2025

Walkthrough

Adds Playwright E2E infra: pre-authentication setup producing storage-state files, custom page fixtures and utilities, updated tests to use those fixtures, new users E2E tests, and CI-aware Playwright configuration plus related docs and ignore rules.

Changes

Cohort / File(s) Summary
Configuration & Documentation
/.gitignore, README.md, package.json, playwright.config.ts
Added e2e/.auth to gitignore; documented new E2E commands and warning about generated auth context files in README; added e2e:setup script; added a Playwright setup project and wired it as a dependency for browser projects when CI is true.
E2E Setup (pre-auth)
e2e/setup/auth.setup.ts
New setup file defining two authentication routines that log in as admin and user, assert landing pages, and save storage-state files (admin.json, user.json) for reuse.
Test Utilities & Types
e2e/utils/constants.ts, e2e/utils/types.ts, e2e/utils/page.ts, e2e/utils/index.ts
Added AUTH_FILE_BASE, USER_FILE, ADMIN_FILE constants; new CustomFixture type; introduced PageUtils interface with login() and to() and pageWithUtils fixture; created e2e/utils/index.ts to extend and re-export Playwright test.
Removed Utilities
e2e/utils/page-utils.ts
Removed legacy pageUtils module (its login helper moved into the new fixture-based utilities).
Updated Tests (imports & API)
e2e/api-schema.spec.ts, e2e/login.spec.ts
Switched imports from @playwright/test to e2e/utils; replaced page.goto() with page.to() and utils.login() usages with page.login().
New Test Suite
e2e/users.spec.ts
New E2E tests for user management: access control, create/edit/delete user flows using admin and user storage-state contexts.
Seed Script Robustness
prisma/seed/book.ts
Added duplicate-check before creating seeded books to avoid unique-constraint errors.

Sequence Diagram

sequenceDiagram
    participant CI as CI Environment
    participant SetupProj as Playwright "setup" project
    participant BrowserProj as Playwright Browser Projects
    participant AuthStore as e2e/.auth (storage files)
    participant Tests as E2E Test Suites

    CI->>SetupProj: run `playwright test --project=setup` (via e2e:setup)
    SetupProj->>SetupProj: navigate /login, authenticate (admin)
    SetupProj->>AuthStore: write admin.json
    SetupProj->>SetupProj: navigate /login, authenticate (user)
    SetupProj->>AuthStore: write user.json
    SetupProj-->>BrowserProj: signal setup complete (dependency)
    BrowserProj->>AuthStore: load storage-state for tests
    BrowserProj->>Tests: run tests using `page.login()` / `page.to()` with pre-auth state
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review focus:
    • e2e/utils/page.ts — fixture implementation, i18n labels, OTP mocking and navigation behavior
    • e2e/utils/index.ts & e2e/utils/types.ts — correct Playwright fixture extension and re-exports
    • e2e/setup/auth.setup.ts — file paths for storage-state and assertions that match app routes/selectors
    • playwright.config.ts — CI conditional dependency wiring and testMatch for .setup.ts
    • e2e/users.spec.ts — selector stability and test isolation when using stored states

Suggested reviewers

  • HugoPerard
  • ivan-dalmet
  • yoannfleurydev

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'e2e: Improve setup and utils' directly reflects the main changes: new e2e setup file, enhanced e2e utilities, and refactored test imports to use the new utils.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/improve-base-for-e2e-tests

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b9369a and c46fa81.

📒 Files selected for processing (14)
  • .gitignore (1 hunks)
  • README.md (1 hunks)
  • e2e/api-schema.spec.ts (1 hunks)
  • e2e/login.spec.ts (1 hunks)
  • e2e/setup/auth.setup.ts (1 hunks)
  • e2e/users.spec.ts (1 hunks)
  • e2e/utils/constants.ts (1 hunks)
  • e2e/utils/index.ts (1 hunks)
  • e2e/utils/page-utils.ts (0 hunks)
  • e2e/utils/page.ts (1 hunks)
  • e2e/utils/types.ts (1 hunks)
  • package.json (1 hunks)
  • playwright.config.ts (1 hunks)
  • prisma/seed/book.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • e2e/utils/page-utils.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • playwright.config.ts
  • e2e/setup/auth.setup.ts
  • e2e/utils/page.ts
  • e2e/users.spec.ts
  • e2e/utils/constants.ts
  • package.json
  • .gitignore
🧰 Additional context used
🧬 Code graph analysis (3)
e2e/utils/types.ts (1)
e2e/utils/page.ts (1)
  • ExtendedPage (28-28)
prisma/seed/book.ts (1)
src/server/routers/book.ts (1)
  • context (129-153)
e2e/login.spec.ts (2)
e2e/utils/constants.ts (2)
  • ADMIN_EMAIL (7-7)
  • USER_EMAIL (4-4)
e2e/utils/page-utils.ts (2)
  • login (32-59)
  • page (27-61)
🪛 LanguageTool
README.md

[style] ~110-~110: Consider shortening or rephrasing this to strengthen your wording.
Context: ...es contain authentication logic. If you make changes to your local database instance, you shoul...

(MAKE_CHANGES)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Playwright E2E Tests
🔇 Additional comments (8)
e2e/api-schema.spec.ts (1)

1-1: LGTM! Clean refactor to centralized utilities.

The import change correctly aligns with the new centralized e2e utilities pattern while maintaining the same test functionality.

e2e/login.spec.ts (3)

1-2: LGTM! Proper alignment with new utilities.

The import changes correctly adopt the centralized e2e utilities and constants.


13-14: Consistent usage of page utility methods.

The login and navigation methods are used consistently across all three test cases with appropriate email constants.

Also applies to: 20-21


6-7: pageWithUtils fixture is properly implemented with correct method signatures.

The page.to() method correctly aliases page.goto() with type safety via FileRouteTypes, and the page.login() method properly accepts the { email, code? } parameter object. Both methods are correctly utilized in login.spec.ts at lines 6-7 and throughout the test suite.

README.md (2)

104-107: LGTM! Clear documentation of E2E commands.

The updated command documentation accurately reflects the new setup workflow, including the headless mode, setup script, and UI mode commands.


109-110: Helpful warning about authentication context.

The warning appropriately informs developers about re-running setup after database changes, which prevents authentication failures in tests.

e2e/utils/index.ts (1)

1-9: LGTM! Well-structured custom test fixture.

The implementation correctly:

  • Extends the base Playwright test with a custom page fixture
  • Maintains type safety through ExtendedPage
  • Re-exports all standard Playwright utilities for backward compatibility
  • Provides a clean, centralized entry point for e2e test utilities

This pattern enables consistent page utility usage across all tests while preserving access to standard Playwright APIs.

e2e/utils/types.ts (1)

1-11: CustomFixture type is actively used in the codebase.

The type is imported and used in e2e/utils/page.ts as the type annotation for the pageWithUtils fixture definition (export const pageWithUtils: CustomFixture<Page & PageUtils>). No action needed.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
e2e/utils/types.ts (1)

1-11: Prefer import type for ExtendedPage to avoid unnecessary runtime coupling

CustomFixture only needs ExtendedPage at the type level. Keeping a value import from 'e2e/utils/page' makes the circular dependency between types.ts and page.ts tighter than needed and may introduce a runtime import that isn’t actually used.

I’d recommend switching to a type‑only import (and optionally doing the same for the Playwright types):

-import {
-  PlaywrightTestArgs,
-  PlaywrightTestOptions,
-  TestFixture,
-} from '@playwright/test';
-import { ExtendedPage } from 'e2e/utils/page';
+import type {
+  PlaywrightTestArgs,
+  PlaywrightTestOptions,
+  TestFixture,
+} from '@playwright/test';
+import type { ExtendedPage } from 'e2e/utils/page';

This keeps the fixture typing intact while loosening runtime module coupling.

e2e/utils/page.ts (1)

13-28: Extended page utilities design is sound

Modeling helpers via a PageUtils interface and intersecting them into the Playwright page fixture through ExtendedPage provides a clean, typed surface for page.login and page.to. If you later need to reference these helpers directly in tests or other utils, consider exporting PageUtils as well, but it’s not strictly necessary right now.

playwright.config.ts (1)

35-52: LGTM! Proper setup project configuration.

The setup project is correctly configured to run authentication setup before tests in CI. The conditional dependencies (process.env.CI ? ['setup'] : []) appropriately skip the setup locally, allowing developers to manually run pnpm e2e:setup once and reuse the authentication state.

One minor note: The sonarjs/slow-regex disable comment on line 35 appears unnecessary for the simple regex /.*\.setup\.ts/. Consider removing it unless there's a specific reason for the suppression.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12618b5 and 6b9369a.

📒 Files selected for processing (13)
  • .gitignore (1 hunks)
  • README.md (1 hunks)
  • e2e/api-schema.spec.ts (1 hunks)
  • e2e/login.spec.ts (1 hunks)
  • e2e/setup/auth.setup.ts (1 hunks)
  • e2e/users.spec.ts (1 hunks)
  • e2e/utils/constants.ts (1 hunks)
  • e2e/utils/index.ts (1 hunks)
  • e2e/utils/page-utils.ts (0 hunks)
  • e2e/utils/page.ts (1 hunks)
  • e2e/utils/types.ts (1 hunks)
  • package.json (1 hunks)
  • playwright.config.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • e2e/utils/page-utils.ts
🧰 Additional context used
🧬 Code graph analysis (6)
e2e/login.spec.ts (2)
e2e/utils/constants.ts (2)
  • ADMIN_EMAIL (7-7)
  • USER_EMAIL (4-4)
e2e/utils/page-utils.ts (2)
  • login (32-59)
  • page (27-61)
e2e/users.spec.ts (2)
e2e/utils/index.ts (1)
  • test (9-9)
prisma/seed/user.ts (1)
  • createUsers (7-58)
e2e/utils/page.ts (4)
e2e/utils/types.ts (1)
  • CustomFixture (8-11)
src/lib/i18n/constants.ts (1)
  • DEFAULT_LANGUAGE_KEY (11-11)
e2e/utils/page-utils.ts (2)
  • login (32-59)
  • page (27-61)
src/features/auth/page-login.tsx (1)
  • PageLogin (27-147)
e2e/utils/index.ts (2)
e2e/utils/page.ts (2)
  • ExtendedPage (28-28)
  • pageWithUtils (30-66)
e2e/utils/page-utils.ts (1)
  • page (27-61)
e2e/setup/auth.setup.ts (2)
e2e/utils/constants.ts (4)
  • ADMIN_EMAIL (7-7)
  • ADMIN_FILE (6-6)
  • USER_EMAIL (4-4)
  • USER_FILE (3-3)
e2e/utils/page-utils.ts (2)
  • login (32-59)
  • page (27-61)
e2e/utils/types.ts (1)
e2e/utils/page.ts (1)
  • ExtendedPage (28-28)
🪛 LanguageTool
README.md

[style] ~110-~110: Consider shortening or rephrasing this to strengthen your wording.
Context: ...es contain authentication logic. If you make changes to your local database instance, you shoul...

(MAKE_CHANGES)

🔇 Additional comments (9)
.gitignore (1)

56-60: Ignoring generated auth state looks good

Adding e2e/.auth keeps local Playwright storage-state files out of git while remaining consistent with the other e2e artifacts.

package.json (1)

33-41: New e2e and DB lifecycle scripts are consistent and well‑composed

e2e:setup follows the existing dotenv/cross-env Playwright pattern scoped to the setup project, and db:reset sensibly composes dk:clear, dk:init, and db:init with && so failures short‑circuit. Behavior aligns with the rest of the script suite.

e2e/api-schema.spec.ts (1)

1-15: Switching to e2e/utils import is aligned with the new fixture setup

Routing test/expect through e2e/utils keeps this spec consistent with the custom fixture layer and will make it easier to evolve shared fixtures later without touching individual tests, assuming e2e/utils re-exports Playwright’s test and expect as intended.

e2e/login.spec.ts (1)

1-24: LGTM! Clean refactoring to the new fixture system.

The migration from the helper-based approach to the custom fixture pattern is well-executed. Using page.to() and page.login() directly on the page object is more ergonomic and aligns with Playwright's fixture extension patterns.

README.md (1)

104-110: LGTM! Clear documentation of the new E2E workflow.

The updated commands and the warning about re-running setup when the database changes are helpful additions. The warning appropriately guides users on when to refresh the authentication context.

e2e/setup/auth.setup.ts (1)

14-32: LGTM! Well-structured authentication setup.

The setup routines correctly implement Playwright's recommended pattern for multiple signed-in roles. Both admin and user setups follow a consistent pattern: navigate, authenticate, verify, and persist storage state. The assertions before saving state ensure valid authentication contexts.

e2e/utils/constants.ts (1)

1-7: LGTM! Clean constant definitions.

The constants are well-organized with an internal base path and public file path exports. This provides a single source of truth for storage state file locations.

e2e/utils/index.ts (1)

1-9: LGTM! Proper fixture extension pattern.

The custom fixture setup follows Playwright's recommended approach. Extending the base test with pageWithUtils and re-exporting all utilities provides a clean, unified entry point for tests.

e2e/users.spec.ts (1)

42-44: Investigate if force: true is necessary.

Using force: true bypasses Playwright's actionability checks (visibility, stability, enabled state). While sometimes necessary for overlays or animations, it can mask timing issues or UI problems that should be fixed.

Consider removing force: true and ensuring elements are properly actionable. If the clicks fail without it, investigate whether there are underlying timing or UI issues that should be addressed.

Also applies to: 58-62

package.json Outdated
"dk:stop": "docker compose stop",
"dk:clear": "docker compose down --volumes",
"db:init": "pnpm db:push && pnpm db:seed",
"db:reset": "pnpm dk:clear && pnpm dk:init && pnpm db:init",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that db:init can fail here if db is not ready in the docker after dk:init 😕

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was more of a quick workaround to get a "Clean db state" between e2e test runs when running them in local !

We should discuss what's the best path forward to have consistent e2e test runs

@ntatoud ntatoud force-pushed the test/improve-base-for-e2e-tests branch from ede0470 to c46fa81 Compare December 3, 2025 13:58
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 3, 2025

@ntatoud ntatoud merged commit 10c683c into main Dec 4, 2025
12 checks passed
@ntatoud ntatoud deleted the test/improve-base-for-e2e-tests branch December 4, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants