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 }); }, ); 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); });