-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
565 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,11 @@ it("registers a new user successfully", async () => { | |
body: JSON.stringify({ | ||
email: "[email protected]", | ||
password: "Password@123", | ||
confirmPassword: "Password@123", | ||
username: "johndoe", | ||
name: "John", | ||
lastName: "Doe", | ||
dateOfBirth: new Date("1990-01-01"), | ||
dateOfBirth: new Date("1990-01-01").toISOString(), | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
@@ -50,8 +51,9 @@ it("returns error for already used email", async () => { | |
lastName: "Prisma", | ||
email: "[email protected]", | ||
username: "aliceUserName", | ||
password: "alicePassword", | ||
dateOfBirth: new Date("1990-01-01"), | ||
password: "Password@123", | ||
confirmPassword: "Password@123", | ||
dateOfBirth: new Date("1990-01-01").toISOString(), | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
@@ -77,14 +79,258 @@ it("returns error for bad request", async () => { | |
name: "Alice", | ||
lastName: "Prisma", | ||
email: "", | ||
password: "Password@123", | ||
confirmPassword: "Password@123", | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toBe(400); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
errors: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
message: "Ce champ est requis", | ||
path: "email", | ||
}), | ||
]), | ||
}), | ||
); | ||
}, | ||
}); | ||
}); | ||
|
||
it("returns error for invalid date of birth", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
email: "[email protected]", | ||
password: "Password@123", | ||
confirmPassword: "Password@123", | ||
username: "johndoe", | ||
name: "John", | ||
lastName: "Doe", | ||
dateOfBirth: "invalid-date", | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toBe(400); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
errors: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
message: "Date invalide", | ||
path: "dateOfBirth", | ||
}), | ||
]), | ||
}), | ||
); | ||
}, | ||
}); | ||
}); | ||
|
||
it("returns error for future date of birth", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
email: "[email protected]", | ||
password: "Password@123", | ||
confirmPassword: "Password@123", | ||
username: "johndoe", | ||
name: "John", | ||
lastName: "Doe", | ||
dateOfBirth: new Date(Date.now() + 86400000).toISOString(), // Future date | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toBe(400); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
errors: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
message: "La date ne peut pas être dans le futur", | ||
path: "dateOfBirth", | ||
}), | ||
]), | ||
}), | ||
); | ||
}, | ||
}); | ||
}); | ||
|
||
it("returns error for missing name", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
email: "[email protected]", | ||
password: "Password@123", | ||
confirmPassword: "Password@123", | ||
username: "johndoe", | ||
lastName: "Doe", | ||
dateOfBirth: new Date("1990-01-01").toISOString(), | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toBe(400); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
errors: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
message: "Ce champ est requis", | ||
path: "name", | ||
}), | ||
]), | ||
}), | ||
); | ||
}, | ||
}); | ||
}); | ||
|
||
it("returns error for invalid email format", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
email: "invalid-email", | ||
password: "Password@123", | ||
confirmPassword: "Password@123", | ||
username: "johndoe", | ||
name: "John", | ||
lastName: "Doe", | ||
dateOfBirth: new Date("1990-01-01").toISOString(), | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toBe(400); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
errors: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
message: "Email invalide", | ||
path: "email", | ||
}), | ||
]), | ||
}), | ||
); | ||
}, | ||
}); | ||
}); | ||
|
||
it("returns error for weak password", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
email: "[email protected]", | ||
password: "password", | ||
confirmPassword: "password", | ||
username: "johndoe", | ||
name: "John", | ||
lastName: "Doe", | ||
dateOfBirth: new Date("1990-01-01").toISOString(), | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toBe(400); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
errors: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
message: "Veuillez renseigner au moins une lettre majuscule", | ||
path: "password", | ||
}), | ||
]), | ||
}), | ||
); | ||
}, | ||
}); | ||
}); | ||
|
||
it("returns error for whitespace in required fields", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
email: "[email protected]", | ||
password: "Password@123", | ||
confirmPassword: "Password@123", | ||
username: " ", | ||
name: " ", | ||
lastName: " ", | ||
dateOfBirth: new Date("1990-01-01").toISOString(), | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toBe(400); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
errors: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
message: "Ce champ est requis", | ||
path: expect.stringMatching(/^(name|lastName|username)$/), | ||
}), | ||
]), | ||
}), | ||
); | ||
}, | ||
}); | ||
}); | ||
|
||
it("returns error for mismatched passwords", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
email: "[email protected]", | ||
password: "Password@123", | ||
confirmPassword: "Password@124", | ||
username: "johndoe", | ||
name: "John", | ||
lastName: "Doe", | ||
dateOfBirth: new Date("1990-01-01").toISOString(), | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toBe(400); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
message: "email is required", | ||
errors: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
message: "Les mots de passe ne correspondent pas", | ||
path: "confirmPassword", | ||
}), | ||
]), | ||
}), | ||
); | ||
}, | ||
|
Oops, something went wrong.