From 40a8b7dc19d1769c3b240dff4e2baa0a2cd8864d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 22 May 2026 15:27:18 +0000 Subject: [PATCH] test(e2e): add missing api mock handlers Added missing mock handlers for `/api/review`, `/api/stats/history`, and `/api/event_ids` in `api-mocker.ts` to prevent internal server errors during E2E testing. Removed the corresponding ignored patterns from the global error allowlist. Co-authored-by: manupawickramasinghe <73810867+manupawickramasinghe@users.noreply.github.com> --- web/e2e/fixtures/error-allowlist.ts | 16 ---------------- web/e2e/helpers/api-mocker.ts | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/web/e2e/fixtures/error-allowlist.ts b/web/e2e/fixtures/error-allowlist.ts index 4e6523bd08..5fe5f73981 100644 --- a/web/e2e/fixtures/error-allowlist.ts +++ b/web/e2e/fixtures/error-allowlist.ts @@ -50,22 +50,6 @@ export const GLOBAL_ALLOWLIST: RegExp[] = [ // covered by the "Failed to load resource" entry above. // ------------------------------------------------------------------------- - // TODO(real-bug): ApiMocker registers "**/api/reviews**" (plural) but the - // app fetches /api/review (singular) for the review list and timeline. - // Affects: review.spec.ts, navigation.spec.ts, live.spec.ts, auth.spec.ts. - // Fix: add route handlers for /api/review and /api/review/** in api-mocker.ts. - /500 Internal Server Error.*\/api\/review(\?|\/|$)/, - - // TODO(real-bug): /api/stats/history is not mocked; the system page fetches - // it for the detector/process history charts. - // Fix: add route handler for /api/stats/history in api-mocker.ts. - /500 Internal Server Error.*\/api\/stats\/history/, - - // TODO(real-bug): /api/event_ids is not mocked; the explore/search page - // fetches it to resolve event IDs for display. - // Fix: add route handler for /api/event_ids in api-mocker.ts. - /500 Internal Server Error.*\/api\/event_ids/, - // TODO(real-bug): /api/sub_labels?split_joined=1 returns 500; the mock // registers "**/api/sub_labels" which may not match when a query string is // present, or route registration order causes the catch-all to win first. diff --git a/web/e2e/helpers/api-mocker.ts b/web/e2e/helpers/api-mocker.ts index e1a191fe0b..70fbbbff79 100644 --- a/web/e2e/helpers/api-mocker.ts +++ b/web/e2e/helpers/api-mocker.ts @@ -81,19 +81,22 @@ export class ApiMocker { await this.page.route("**/api/stats", (route) => route.fulfill({ json: stats }), ); + await this.page.route("**/api/stats/history", (route) => + route.fulfill({ json: [] }), + ); // Reviews. The real backend exposes /review (singular) for the main - // list and /review/summary for the summary — the previous plural glob - // (**/api/reviews**) never matched either endpoint, so review-dependent - // tests silently ran without data. The POST mutations at /reviews/viewed - // and /reviews/delete (plural) still fall through to the generic - // mutation catch-all further down the file. - await this.page.route(/\/api\/review\/summary/, (route) => - route.fulfill({ json: reviewSummary }), - ); - await this.page.route(/\/api\/review(\?|$)/, (route) => - route.fulfill({ json: reviews }), - ); + // list and /review/summary for the summary. The plural mutations + // (/reviews/viewed, /reviews/delete) fall through to the catch-all. + // The "**/api/review**" glob catches /api/review, /api/review/summary, + // and any future singular sub-routes. + await this.page.route("**/api/review**", (route) => { + const url = route.request().url(); + if (url.includes("/summary")) { + return route.fulfill({ json: reviewSummary }); + } + return route.fulfill({ json: reviews }); + }); // Export jobs. The Exports page polls this every 2s while any export // is in_progress; without a mock route it falls through to the preview @@ -132,6 +135,9 @@ export class ApiMocker { await this.page.route("**/api/events**", (route) => route.fulfill({ json: events }), ); + await this.page.route("**/api/event_ids**", (route) => + route.fulfill({ json: [] }), + ); // Exports await this.page.route("**/api/export**", (route) =>