batchCooking/apps/api/features/step-definitions/auth.steps.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

67 lines
2.2 KiB
TypeScript

import assert from "node:assert/strict";
import type { DataTable } from "@cucumber/cucumber";
import { Given, Then, When } from "@cucumber/cucumber";
import { faker } from "@faker-js/faker";
import { signup } from "../../src/modules/auth/auth.service.js";
import type { CustomWorld } from "../support/world.js";
// firstName/lastName/password below are filler for background state the
// scenario doesn't actually read (only the emails in the .feature file are
// part of what's being tested) — faker-generated rather than hardcoded so
// no test fixture ever looks like a real person's data.
Given("a profile already exists with email {string}", async (email: string) => {
await signup({
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
email,
password: faker.internet.password({ length: 16 }),
});
});
Given(
"a profile already exists with email {string} and password {string}",
async (email: string, password: string) => {
await signup({
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
email,
password,
});
},
);
When("I sign up with the following details:", async function (this: CustomWorld, table: DataTable) {
const details = table.rowsHash();
this.response = await this.agent.post("/auth/signup").send({
firstName: details.firstName,
lastName: details.lastName,
email: details.email,
password: details.password,
});
});
When(
"I log in with email {string} and password {string}",
async function (this: CustomWorld, email: string, password: string) {
this.response = await this.agent.post("/auth/login").send({ email, password });
},
);
When(
"I delete my account with password {string}",
async function (this: CustomWorld, password: string) {
this.response = await this.agent.delete("/auth/me").send({ password });
},
);
Then("I am authenticated as {string}", async function (this: CustomWorld, email: string) {
const res = await this.agent.get("/auth/me");
assert.equal(res.status, 200);
assert.equal(res.body.email, email);
});
Then("I am no longer authenticated", async function (this: CustomWorld) {
const res = await this.agent.get("/auth/me");
assert.equal(res.status, 401);
});