Skip to content

Conversation

@ntatoud
Copy link
Member

@ntatoud ntatoud commented Nov 16, 2025

Summary by CodeRabbit

  • New Features

    • Added end-to-end test suite for user management, including workflows for creating, editing, and deleting users with access control validation.
    • Introduced authentication setup for pre-authenticated test contexts enabling streamlined e2e testing.
  • Chores

    • Added e2e:setup and db:reset npm commands for test environment management.
    • Enhanced e2e test infrastructure with new utilities and improved configuration.
  • Documentation

    • Updated README with new e2e setup instructions and authentication context warnings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 16, 2025

Warning

Rate limit exceeded

@ntatoud has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 48 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

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

📒 Files selected for processing (3)
  • e2e/users.spec.ts (1 hunks)
  • e2e/utils/page.ts (1 hunks)
  • prisma/seed/book.ts (1 hunks)

Walkthrough

This PR establishes Playwright end-to-end test infrastructure with pre-authenticated contexts and custom page utilities. It introduces a setup project that runs before main tests to generate authentication state files for admin and user roles, refactors test imports to use a new custom fixture system, and adds new user management tests. Configuration is updated to support the setup flow.

Changes

Cohort / File(s) Summary
Configuration & Documentation
.gitignore, README.md, package.json, playwright.config.ts
Added e2e/.auth to gitignore; documented new e2e:setup command and warning about auth context files in README; added e2e:setup and db:reset scripts to package.json; added setup project to Playwright config with conditional dependencies on CI
Test Setup & Authentication
e2e/setup/auth.setup.ts
New setup file defining two authentication routines (admin and user) that navigate to login, authenticate with stored credentials, and save storage state to files for reuse across tests
Utility Infrastructure
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; created CustomFixture type for test fixtures; introduced PageUtils interface with login() and to() methods; extended Playwright test with custom pageWithUtils fixture exposing page utilities; re-exported Playwright test exports
Removed Utilities
e2e/utils/page-utils.ts
Deleted entire pageUtils module; functionality merged into new page.ts fixture
Test File Updates
e2e/api-schema.spec.ts, e2e/login.spec.ts
Updated imports from @playwright/test to e2e/utils; replaced navigation via page.goto() with page.to(); replaced utils.login() with page.login() for direct page method access
New Test Suite
e2e/users.spec.ts
Added comprehensive user management test suite covering access control, user creation, editing, and deletion with admin and user role contexts

Sequence Diagram

sequenceDiagram
    participant CI as CI Environment
    participant Setup as Setup Project
    participant AuthFile as Auth State Files
    participant MainTest as Main Tests
    
    CI->>Setup: Run e2e:setup (on CI)
    Setup->>Setup: Admin login flow<br/>(navigate, authenticate, save state)
    Setup->>AuthFile: Save admin.json
    Setup->>Setup: User login flow<br/>(navigate, authenticate, save state)
    Setup->>AuthFile: Save user.json
    Setup-->>MainTest: Pre-auth contexts ready
    MainTest->>MainTest: Use page.login() & page.to()<br/>with pre-loaded storage state
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • e2e/utils/page.ts — Contains new fixture implementation with login flow logic; verify i18n integration and routing type usage are correct
  • e2e/utils/index.ts — Custom test fixture extension; ensure proper fixture composition and re-export of Playwright utilities
  • e2e/setup/auth.setup.ts — New setup project; verify authentication flow matches expected UI behavior and state file paths align with constants
  • playwright.config.ts — Dependency wiring for conditional setup project execution; verify CI environment variable logic

Suggested reviewers

  • ivan-dalmet
  • HugoPerard

Pre-merge checks and finishing touches

✅ Passed checks (3 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' accurately summarizes the main changes: refactoring e2e test setup infrastructure and utility modules to enhance the testing framework.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

@sonarqubecloud
Copy link

@ntatoud ntatoud marked this pull request as ready for review November 16, 2025 16:35
"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

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.

3 participants