import assert from "node:assert/strict"; import { ErrorCode } from "@batch-cooking/shared"; import { Then, When } from "@cucumber/cucumber"; import request from "supertest"; import type { CustomWorld } from "../support/world.js"; When("I send a GET request to {string}", async function (this: CustomWorld, path: string) { this.response = await request(this.app).get(path); }); Then("the response status should be {int}", function (this: CustomWorld, status: number) { assert.equal(this.response.status, status); }); Then("the response body should be:", function (this: CustomWorld, expectedJson: string) { assert.deepEqual(this.response.body, JSON.parse(expectedJson)); }); // Generic enough to be reused by any feature asserting on the shared // ApiErrorResponse contract's `code` field — not health-specific, but this // file is where the other generic response-assertion steps already live. // // `code` here is the enum *member name* (readable in the .feature file, // e.g. "EMAIL_ALREADY_IN_USE") — ErrorCode[name] resolves it to the real // numeric value via TypeScript's reverse enum lookup, so this never // compares against a hardcoded number. Then("the response error code should be {string}", function (this: CustomWorld, code: string) { const expected = ErrorCode[code as keyof typeof ErrorCode]; assert.notEqual(expected, undefined, `Unknown ErrorCode member: "${code}"`); assert.equal(this.response.body.code, expected); });