Skip to content

Commit

Permalink
Jest config (#13)
Browse files Browse the repository at this point in the history
front, list event, list journey, journey form

---------

Co-authored-by: alexandre-kakal-akarah <[email protected]>
Co-authored-by: Maxime Dandel <[email protected]>
  • Loading branch information
3 people authored Jun 24, 2024
1 parent 5ed9931 commit 7142125
Show file tree
Hide file tree
Showing 59 changed files with 2,786 additions and 2,222 deletions.
1 change: 0 additions & 1 deletion __test__/auth/apiClient/registerUserApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ it("returns error for bad request", async () => {
});
});


it("returns error for invalid date of birth", async () => {
await testApiHandler({
appHandler: registerHandler,
Expand Down
48 changes: 48 additions & 0 deletions __test__/auth/registerSchema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// __tests__/auth/registerSchema.test.ts
import registerSchema from "@/validators/registerSchema";

describe("registerSchema", () => {
it("should validate correct input", () => {
const validData = {
name: "John",
lastName: "Doe",
username: "johndoe",
dateOfBirth: new Date(1990, 1, 1),
email: "[email protected]",
password: "Password@123",
confirmPassword: "Password@123",
};

expect(() => registerSchema.parse(validData)).not.toThrow();
});

it("should throw error for invalid email", () => {
const invalidData = {
name: "John",
lastName: "Doe",
username: "johndoe",
dateOfBirth: new Date(1990, 1, 1),
email: "john.doe",
password: "Password@123",
confirmPassword: "Password@123",
};

expect(() => registerSchema.parse(invalidData)).toThrow();
});

it("should throw error for password mismatch", () => {
const invalidData = {
name: "John",
lastName: "Doe",
username: "johndoe",
dateOfBirth: new Date(1990, 1, 1),
email: "[email protected]",
password: "Password@123",
confirmPassword: "DifferentPassword@123",
};

expect(() => registerSchema.parse(invalidData)).toThrow();
});

// Add more tests for other invalid cases as needed
});
284 changes: 284 additions & 0 deletions __test__/journey.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
import { testApiHandler } from "next-test-api-route-handler";
import * as journeyHandler from "@/app/api/journeys/route";
import * as journeyWithParamsHandler from "@/app/api/journeys/[id]/route";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

beforeAll(async () => {
await prisma.journey.create({
data: {
id: 999,
authorId: 1,
title: "Mon premier parcours",
description: "Ceci est un exemple de parcours",
requirement: "Aucun",
treasure: "Un trésor caché",
estimatedDistance: 10,
estimatedDuration: 120,
cluesDifficulty: 3,
physicalDifficulty: 2,
lastCompletion: "2022-12-01T00:00:00.000Z",
mobilityImpaired: "undefined",
partiallySighted: "undefined",
partiallyDeaf: "undefined",
cognitivelyImpaired: "undefined",
steps: {
create: [
{
puzzle: "Première énigme",
answer: "Réponse à la première énigme",
hint: "Indice pour la première énigme",
picturePuzzle: "url_de_l'image_de_l'énigme",
pictureHint: "url_de_l'image_de_l'indice",
latitude: 45.7578137,
longitude: 4.8320114,
address: "1 Place Bellecour",
city: "Lyon",
postalCode: "69002",
country: "France",
stepNumber: 1,
},
],
},
},
});
});

it("Get all Journeys", async () => {
await testApiHandler({
appHandler: journeyHandler,
async test({ fetch }) {
const res = await fetch({ method: "GET" });
expect(res.status).toBe(200);
},
});
});

it("Create a journey successfully", async () => {
await testApiHandler({
appHandler: journeyHandler,
async test({ fetch }) {
const res = await fetch({
method: "POST",
body: JSON.stringify({
journey: {
authorId: 1,
title: "Mon premier parcours",
description: "Ceci est un exemple de parcours",
requirement: "Aucun",
treasure: "Un trésor caché",
estimatedDistance: 10,
estimatedDuration: 120,
cluesDifficulty: 3,
physicalDifficulty: 2,
lastCompletion: "2022-12-01T00:00:00.000Z",
mobilityImpaired: "undefined",
partiallySighted: "undefined",
partiallyDeaf: "undefined",
cognitivelyImpaired: "undefined",
},
steps: [
{
puzzle: "Première énigme",
answer: "Réponse à la première énigme",
hint: "Indice pour la première énigme",
picturePuzzle: "url_de_l'image_de_l'énigme",
pictureHint: "url_de_l'image_de_l'indice",
latitude: 45.7578137,
longitude: 4.8320114,
address: "1 Place Bellecour",
city: "Lyon",
postalCode: "69002",
country: "France",
stepNumber: 1,
},
{
puzzle: "Deuxième énigme",
answer: "Réponse à la deuxième énigme",
hint: "Indice pour la deuxième énigme",
picturePuzzle: "url_de_l'image_de_l'énigme",
pictureHint: "url_de_l'image_de_l'indice",
latitude: 45.7582413,
longitude: 4.835658,
address: "2 Place Antonin Poncet",
city: "Lyon",
postalCode: "69002",
country: "France",
stepNumber: 2,
},
],
}),
});
expect(res.status).toBe(201);
},
});
});

it("Create a journey with missing arguments", async () => {
await testApiHandler({
appHandler: journeyHandler,
async test({ fetch }) {
const res = await fetch({
method: "POST",
body: JSON.stringify({
journey: {
authorId: 1,
title: "Mon premier parcours",
description: "Ceci est un exemple de parcours",
requirement: "Aucun",
treasure: "Un trésor caché",
estimatedDistance: 10,
estimatedDuration: 120,
cluesDifficulty: 3,
physicalDifficulty: 2,
lastCompletion: "2022-12-01T00:00:00.000Z",
mobilityImpaired: "undefined",
partiallySighted: "undefined",
partiallyDeaf: "undefined",
cognitivelyImpaired: "undefined",
},
}),
});
expect(res.status).toBe(400);
},
});
});

it("Update a journey with a specific id", async () => {
await testApiHandler({
paramsPatcher(params) {
params.id = "999";
},
appHandler: journeyWithParamsHandler,
async test({ fetch }) {
const res = await fetch({
method: "PUT",
body: JSON.stringify({
journey: {
authorId: 1,
title: "Mon premier parcours (modifié)",
description: "Ceci est un exemple de parcours (modifié)",
requirement: "Aucun",
treasure: "Un trésor caché (modifié)",
estimatedDistance: 10,
estimatedDuration: 120,
cluesDifficulty: 3,
physicalDifficulty: 2,
lastCompletion: "2022-12-01T00:00:00.000Z",
mobilityImpaired: "undefined",
partiallySighted: "undefined",
partiallyDeaf: "undefined",
cognitivelyImpaired: "undefined",
},
steps: [
{
puzzle: "Première énigme (modifié)",
answer: "Réponse à la première énigme (modifié)",
hint: "Indice pour la première énigme",
picturePuzzle: "url_de_l'image_de_l'énigme",
pictureHint: "url_de_l'image_de_l'indice",
latitude: 45.7578137,
longitude: 4.8320114,
address: "1 Place Bellecour",
city: "Lyon",
postalCode: "69002",
country: "France",
stepNumber: 1,
},
{
puzzle: "Deuxième énigme (modifié)",
answer: "Réponse à la deuxième énigme (modifié)",
hint: "Indice pour la deuxième énigme (modifié)",
picturePuzzle: "url_de_l'image_de_l'énigme",
pictureHint: "url_de_l'image_de_l'indice",
latitude: 45.7582413,
longitude: 4.835658,
address: "2 Place Antonin Poncet",
city: "Lyon",
postalCode: "69002",
country: "France",
stepNumber: 2,
},
],
}),
});
expect(res.status).toBe(200);
},
});
});

it("Update a journey that doesn't exist", async () => {
await testApiHandler({
paramsPatcher(params) {
params.id = "2345";
},
appHandler: journeyWithParamsHandler,
async test({ fetch }) {
const res = await fetch({
method: "PUT",
body: JSON.stringify({
journey: {
authorId: 1,
title: "Mon premier parcours (modifié)",
description: "Ceci est un exemple de parcours (modifié)",
requirement: "Aucun",
treasure: "Un trésor caché (modifié)",
estimatedDistance: 10,
estimatedDuration: 120,
cluesDifficulty: 3,
physicalDifficulty: 2,
lastCompletion: "2022-12-01T00:00:00.000Z",
mobilityImpaired: "undefined",
partiallySighted: "undefined",
partiallyDeaf: "undefined",
cognitivelyImpaired: "undefined",
},
steps: [
{
puzzle: "Première énigme (modifié)",
answer: "Réponse à la première énigme (modifié)",
hint: "Indice pour la première énigme",
picturePuzzle: "url_de_l'image_de_l'énigme",
pictureHint: "url_de_l'image_de_l'indice",
latitude: 45.7578137,
longitude: 4.8320114,
address: "1 Place Bellecour",
city: "Lyon",
postalCode: "69002",
country: "France",
stepNumber: 1,
},
],
}),
});
expect(res.status).toBe(404);
},
});
});

it("Delete a journey with a specific id", async () => {
await testApiHandler({
paramsPatcher(params) {
params.id = "999";
},
appHandler: journeyWithParamsHandler,
async test({ fetch }) {
const res = await fetch({ method: "DELETE" });
expect(res.status).toBe(204);
},
});
});

it("Delete a journey that doesn't exist", async () => {
await testApiHandler({
paramsPatcher(params) {
params.id = "2345";
},
appHandler: journeyWithParamsHandler,
async test({ fetch }) {
const res = await fetch({ method: "DELETE" });
expect(res.status).toBe(404);
},
});
});
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const nextConfig = {
remotePatterns: [
{
protocol: "https",
hostname: "via.assets.so",
hostname: "picsum.photos",
},
],
},
Expand Down
Loading

0 comments on commit 7142125

Please sign in to comment.