Skip to content

[BUG] Fix overly aggressive route interception breaking goals sync mock in E2E tests #3309

Description

@rudrakshtank

Bug Description

In the deletion test ([Goals E2E] deleting a goal removes it from the list), the "/api/goals" and "/api/goals/" wildcard route patterns inadvertently intercept requests meant for /api/goals/sync. Because Playwright evaluates routes in reverse order of registration (last registered takes precedence), these wildcards run before the specific /api/goals/sync mock set up in setupGoalsMocks.

When the frontend fires a POST request to /api/goals/sync, the "/api/goals/" wildcard catches it. Because the method is POST—bypassing the DELETE and PATCH conditional blocks—the handler defaults to returning route.fulfill({ status: 204, body: "" }). The frontend application then attempts to parse this empty 204 response as JSON (expecting { ok: true, last_synced_at: ... }), which throws a JSON parsing exception, crashing the widget and failing the test.

Steps to Reproduce

Run the Playwright test "deleting a goal removes it from the list".

The application mounts and automatically dispatches a POST request to /api/goals/sync to synchronize user goals.

The newly registered Playwright wildcard route "/api/goals/" aggressively intercepts this request because it matches the wildcard pattern and has higher precedence than the original setupGoalsMocks mock.

The handler evaluates the HTTP method. Since it's POST (not DELETE or PATCH), it executes the fallback catch-all: return route.fulfill({ status: 204, body: "" }).

The frontend fetch client attempts to parse the empty response body as JSON, resulting in an unhandled exception that interrupts the DOM rendering and causes the visibility assertions to time out.

Affected Area

Other

Screenshots

No response

Browser & OS

No response

Environment

None

Additional Context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggssoc:assignedGSSoC: Issue assigned to a contributorneeds-triageNeeds maintainer triage

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions