Compare commits

..

No commits in common. "0569884ddca103e650fda82b45df3f79e9349df4" and "3b78582d29a6967fc1ff3d8482f22c17c5e3669c" have entirely different histories.

View file

@ -53,33 +53,21 @@ describe("Admin monitoring", () => {
}); });
// The page route `/admin/monitoring` and the API path `GET /admin/monitoring` // The page route `/admin/monitoring` and the API path `GET /admin/monitoring`
// are identical — a plain `**/admin/monitoring` glob also matches the // are identical — a plain `**/admin/monitoring` glob would also match the
// `cy.visit()` document request (and whether that's same-origin or not // `cy.visit()` document request (and whether that's same-origin or not
// depends on `VITE_API_URL`, which isn't set in CI). // depends on `VITE_API_URL`, which isn't set in CI). `resourceType: "fetch"`
// // pins the intercept to the `AdminApiClient` XHR only.
// This used to be disambiguated with a declarative `resourceType: "fetch"` const monitoringApi = {
// route matcher, but that stopped working (Cypress 13.17.0 on this method: "GET",
// machine's Chrome 152): the *declarative* `resourceType` matcher no url: "**/admin/monitoring",
// longer catches this request at all — confirmed by logging every request resourceType: "fetch",
// Cypress hands to a `{resourceType: "fetch"}` intercept, which only ever } as const;
// saw `/admin/auth/me`, never `/admin/monitoring` — even though the very
// same request's own `req.resourceType`, read *inside* a handler matched
// by url/method alone, reliably reads back `"fetch"`. So the request *is*
// correctly typed; only the pre-filtering by that type is broken. Reading
// `req.resourceType` inside the handler and branching manually (as below)
// isn't affected by that bug and reproduced correctly in every check.
function interceptMonitoringApi(response: { statusCode: number; body: unknown }) {
return cy.intercept("GET", "**/admin/monitoring", (req) => {
if (req.resourceType === "document") {
req.continue();
return;
}
req.reply(response);
});
}
it("renders one card per service with its status and details", () => { it("renders one card per service with its status and details", () => {
interceptMonitoringApi({ statusCode: 200, body: monitoringFixture() }).as("getMonitoring"); cy.intercept(monitoringApi, {
statusCode: 200,
body: monitoringFixture(),
}).as("getMonitoring");
cy.visit("/admin/monitoring"); cy.visit("/admin/monitoring");
cy.wait("@getMonitoring"); cy.wait("@getMonitoring");
@ -97,17 +85,11 @@ describe("Admin monitoring", () => {
}); });
it("shows an error state when the request fails", () => { it("shows an error state when the request fails", () => {
// Aliased and waited on (unlike the other tests' plain intercepts) so cy.intercept(monitoringApi, {
// this genuinely proves the 500 came from the mock — without a live API statusCode: 500,
// server, an unmatched request fails at the network level too, which body: { code: 5000, message: "x" },
// `MonitoringPage`'s `.catch()` can't tell apart from a real 500 (see });
// the comment above `interceptMonitoringApi`, this is exactly the class
// of bug that let this test pass for the wrong reason before).
interceptMonitoringApi({ statusCode: 500, body: { code: 5000, message: "x" } }).as(
"getMonitoringError",
);
cy.visit("/admin/monitoring"); cy.visit("/admin/monitoring");
cy.wait("@getMonitoringError");
cy.contains("Impossible de charger").should("be.visible"); cy.contains("Impossible de charger").should("be.visible");
}); });
}); });