batchCooking/apps/api/features/support/world.ts
Nicolas 3363cfad75 Tests API: couverture Mocha + Cucumber pour le foyer et la suppression de compte (step 4/8)
- house.test.ts réécrit (le foyer n'est plus auto-créé) + POST /house,
  POST /house/join, POST /house/leave, DELETE /house/current,
  DELETE /house/members/:id
- auth.test.ts: signup renvoie houseId=null, DELETE /auth/me (mauvais
  mot de passe, suppression, transfert d'admin)
- planning.test.ts/steps.ts: création explicite du foyer (POST /house)
- household.feature: scénarios créer/rejoindre/quitter/supprimer/
  retirer un membre, via un second agent (CustomWorld.secondAgent)
- auth.feature: scénarios de suppression de compte
2026-08-17 10:40:23 +02:00

26 lines
1.1 KiB
TypeScript

import { type IWorldOptions, World, setWorldConstructor } from "@cucumber/cucumber";
import type { Express } from "express";
import request from "supertest";
import { createApp } from "../../src/app.js";
// Fresh Express app per scenario (in-process, via supertest — no server to
// spin up/tear down) plus the last HTTP response, available to every step.
// `agent` persists cookies across requests within a scenario (needed for
// "sign up then check I'm authenticated" style flows).
export class CustomWorld extends World {
app: Express;
agent: ReturnType<typeof request.agent>;
response!: request.Response;
/** A second, independent session (own cookie jar) — only used by scenarios needing two distinct signed-in users, e.g. household invites/admin transfer/member removal. */
secondAgent: ReturnType<typeof request.agent>;
secondResponse!: request.Response;
constructor(options: IWorldOptions) {
super(options);
this.app = createApp();
this.agent = request.agent(this.app);
this.secondAgent = request.agent(this.app);
}
}
setWorldConstructor(CustomWorld);