Some checks failed
Formulaire in-app de remontée de bug / suggestion pour les utilisateurs connectés (PR 1/2 de l'issue #80). - Modèle Prisma `ContactMessage` (+ relation inverse sur `UserProfile`) et migration `20260908120000_contact_message` — table neuve, aucun backfill. `authorId` nullable + `onDelete: SetNull` : un signalement survit à la suppression de son compte. - Contrat partagé `schemas/contact.ts` : `CONTACT_MESSAGE_TYPES`, `submitContactMessageSchema` (type enum, message 10-5000 trim, pageUrl / appVersion optionnels — jamais le user-agent). - Module API `contact` : `POST /contact` (`requireAuth`, monté `/contact`), `204` sans corps. Le user-agent est lu de l'en-tête de requête, jamais du corps. Émet `analytics.recordEvent(contact.submitted, …)`. - Page `/parametres/contact` (`ContactPage` + `contact.ts` + `.scss`) : select de type, textarea, validation cliente via le schéma partagé, états succès / erreur (`ErrorMessageService`, jamais `err.message`). Entrée de nav « Nous contacter » dans `SETTINGS_ITEMS` + clé i18n + icône. `apiClient.submitContactMessage(input)` ajoute `pageUrl` / `appVersion`. - Tests : `apps/api/test/contact.test.ts` (Mocha — insertion, en-tête UA, champs nullables, message trop court / trop long, type inconnu), `contact.feature` + steps (Cypress e2e — envoi + confirmation + contexte), `contact-page.cy.ts` (rendu + garde `RequireAuth` + label d'erreur). - Docs : `batch-cooking-modele.md`, `backend-architecture.md`, `frontend-architecture.md`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
58 lines
2 KiB
TypeScript
58 lines
2 KiB
TypeScript
// Mocks the API via cy.intercept — this job doesn't run a live backend (see
|
|
// .github/workflows/ci.yml); apps/api's own Mocha suite covers real
|
|
// `POST /contact` behavior against a real database. The Gherkin journey
|
|
// (fill + send + confirmation) lives in contact.feature — this file only
|
|
// covers the page's initial render and its guards.
|
|
|
|
const authenticatedProfile = {
|
|
id: 1,
|
|
firstName: "Alice",
|
|
lastName: "Martin",
|
|
email: "alice@example.com",
|
|
tokenVersion: 0,
|
|
houseId: null,
|
|
dietId: null,
|
|
};
|
|
|
|
describe("Contact page (/parametres/contact)", () => {
|
|
it("redirects to /login when signed out (RequireAuth)", () => {
|
|
cy.intercept("GET", "**/auth/me", { statusCode: 401 });
|
|
|
|
cy.visit("/parametres/contact");
|
|
|
|
cy.url().should("include", "/login");
|
|
});
|
|
|
|
describe("signed in", () => {
|
|
beforeEach(() => {
|
|
cy.intercept("GET", "**/auth/me", { statusCode: 200, body: authenticatedProfile });
|
|
});
|
|
|
|
it("renders the form: a type select defaulting to Bug, a message box, a submit button", () => {
|
|
cy.visit("/parametres/contact");
|
|
|
|
cy.contains("h1", "Nous contacter").should("be.visible");
|
|
cy.get("#contactType option").should("have.length", 3);
|
|
cy.get("#contactType").should("have.value", "bug");
|
|
cy.get("#contactMessage").should("be.visible");
|
|
cy.contains("button", "Envoyer").should("not.be.disabled");
|
|
});
|
|
|
|
it("shows a translated error label, never the raw server message, when the submit fails", () => {
|
|
cy.intercept("POST", "**/contact", {
|
|
statusCode: 500,
|
|
body: { code: 5000, message: "raw internal boom" },
|
|
}).as("submitContact");
|
|
|
|
cy.visit("/parametres/contact");
|
|
cy.get("#contactMessage").type(
|
|
"Ceci est un message de test suffisamment long pour être valide.",
|
|
);
|
|
cy.contains("button", "Envoyer").click();
|
|
|
|
cy.wait("@submitContact");
|
|
cy.get(".field-error").should("be.visible");
|
|
cy.contains("raw internal boom").should("not.exist");
|
|
});
|
|
});
|
|
});
|