changement
This commit is contained in:
62
backend/tests/registerPassword.test.js
Normal file
62
backend/tests/registerPassword.test.js
Normal file
@@ -0,0 +1,62 @@
|
||||
const request = require("supertest");
|
||||
const app = require("../src/app");
|
||||
const prisma = require("../src/config/prisma");
|
||||
|
||||
jest.mock("../src/config/mailer", () => ({ sendMail: jest.fn().mockResolvedValue(true) }));
|
||||
|
||||
const EMAIL = "register-password-test@test.local";
|
||||
|
||||
const payload = (password, confirmPassword = password) => ({
|
||||
firstname: "Camille",
|
||||
lastname: "Martin",
|
||||
email: EMAIL,
|
||||
password,
|
||||
confirmPassword,
|
||||
birthdate: "1990-05-14",
|
||||
});
|
||||
|
||||
async function cleanup() {
|
||||
await prisma.user.deleteMany({ where: { email: EMAIL } });
|
||||
}
|
||||
|
||||
beforeEach(cleanup);
|
||||
afterAll(async () => {
|
||||
await cleanup();
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
|
||||
describe("Regles du mot de passe a l inscription", () => {
|
||||
test.each([
|
||||
["trop court", "Abc12!", /8 caractères/],
|
||||
["sans caractere special", "MotDePasse123", /caractère spécial/],
|
||||
["accents et espaces ne comptent pas comme speciaux", "Mot de passé 123", /caractère spécial/],
|
||||
])("refuse un mot de passe %s", async (_, password, message) => {
|
||||
const res = await request(app).post("/api/auth/register").send(payload(password));
|
||||
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.errors.password[0]).toMatch(message);
|
||||
expect(await prisma.user.findUnique({ where: { email: EMAIL } })).toBeNull();
|
||||
});
|
||||
|
||||
test("refuse une confirmation differente", async () => {
|
||||
const res = await request(app).post("/api/auth/register").send(payload("MotDePasse1!", "MotDePasse2!"));
|
||||
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.errors.confirmPassword[0]).toMatch(/ne correspondent pas/);
|
||||
});
|
||||
|
||||
test("refuse une inscription sans confirmation", async () => {
|
||||
const { confirmPassword, ...sansConfirmation } = payload("MotDePasse1!");
|
||||
const res = await request(app).post("/api/auth/register").send(sansConfirmation);
|
||||
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.errors.confirmPassword).toBeDefined();
|
||||
});
|
||||
|
||||
test("accepte 8 caracteres avec un caractere special", async () => {
|
||||
const res = await request(app).post("/api/auth/register").send(payload("abcdefg#"));
|
||||
|
||||
expect(res.status).toBe(201);
|
||||
expect(await prisma.user.findUnique({ where: { email: EMAIL } })).not.toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user