-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/#729 refacto de la table hebergement v 2 #617
Open
benjaminDNUM
wants to merge
2
commits into
main
Choose a base branch
from
fix/#729-refacto-de-la-table-hebergement-v-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
38 changes: 0 additions & 38 deletions
38
packages/backend/src/controllers/demandeSejour/getHebergement.js
This file was deleted.
Oops, something went wrong.
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
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
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
2 changes: 1 addition & 1 deletion
2
packages/backend/src/controllers/hebergement/getByDepartements.js
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
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
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
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
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
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
56 changes: 56 additions & 0 deletions
56
packages/backend/src/routes/__tests__/hebergement/FU-getById.test.js
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const request = require("supertest"); | ||
const app = require("../../../app"); // Chemin vers ton application Express | ||
const Hebergement = require("../../../services/hebergement/Hebergement"); | ||
const CheckJWT = require("../../../middlewares/checkJWT"); | ||
const checkPermissionHebergement = require("../../../middlewares/checkPermissionHebergement"); | ||
|
||
// Mock des services et middlewares | ||
jest.mock("../../../services/hebergement/Hebergement"); | ||
jest.mock("../../../middlewares/checkJWT"); | ||
jest.mock("../../../middlewares/checkPermissionHebergement"); | ||
|
||
describe("GET /hebergement/:id", () => { | ||
const user = { | ||
id: 1, | ||
role: "admin", | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
// Mock des middlewares | ||
CheckJWT.mockImplementation((req, res, next) => { | ||
req.decoded = { ...user }; | ||
next(); | ||
}); | ||
checkPermissionHebergement.mockImplementation((req, res, next) => { | ||
next(); | ||
}); | ||
}); | ||
|
||
it("devrait retourner un hébergement par ID avec succès", async () => { | ||
const mockHebergement = { | ||
id: "123", | ||
}; | ||
|
||
// Mock de Hebergement.getById | ||
Hebergement.getById.mockResolvedValue(mockHebergement); | ||
|
||
const response = await request(app).get("/hebergement/123"); | ||
|
||
// Vérification des résultats | ||
expect(response.status).toBe(200); | ||
expect(Hebergement.getById).toHaveBeenCalledWith("123"); | ||
}); | ||
|
||
it("devrait retourner une erreur 400 si l'ID est manquant ou invalide", async () => { | ||
CheckJWT.mockImplementationOnce((req, res, next) => { | ||
req.decoded = { ...user }; | ||
req.params = {}; | ||
next(); | ||
}); | ||
|
||
const response = await request(app).get("/hebergement/2"); | ||
expect(response.status).toBe(400); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
packages/backend/src/routes/__tests__/hebergement/admin-getById.test.js
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const request = require("supertest"); | ||
const app = require("../../../app"); // Chemin vers ton application Express | ||
const Hebergement = require("../../../services/hebergement/Hebergement"); | ||
const boCheckJWT = require("../../../middlewares/bo-check-JWT"); | ||
const checkPermissionHebergement = require("../../../middlewares/checkPermissionHebergement"); | ||
|
||
// Mock des services et middlewares | ||
jest.mock("../../../services/hebergement/Hebergement"); | ||
jest.mock("../../../middlewares/bo-check-JWT"); | ||
jest.mock("../../../middlewares/checkPermissionHebergement"); | ||
|
||
describe("GET /hebergement/admin/:id", () => { | ||
const user = { | ||
id: 1, | ||
role: "admin", | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
// Mock des middlewares | ||
boCheckJWT.mockImplementation((req, res, next) => { | ||
req.decoded = { ...user }; | ||
next(); | ||
}); | ||
checkPermissionHebergement.mockImplementation((req, res, next) => { | ||
next(); | ||
}); | ||
}); | ||
|
||
it("devrait retourner un hébergement par ID avec succès", async () => { | ||
const mockHebergement = { | ||
id: "123", | ||
}; | ||
|
||
// Mock de Hebergement.getById | ||
Hebergement.getById.mockResolvedValue(mockHebergement); | ||
|
||
const response = await request(app).get("/hebergement/admin/123"); | ||
|
||
// Vérification des résultats | ||
expect(response.status).toBe(200); | ||
expect(Hebergement.getById).toHaveBeenCalledWith("123"); | ||
}); | ||
|
||
it("devrait retourner une erreur 400 si l'ID est manquant ou invalide", async () => { | ||
boCheckJWT.mockImplementationOnce((req, res, next) => { | ||
req.decoded = { ...user }; | ||
req.params = {}; | ||
next(); | ||
}); | ||
|
||
const response = await request(app).get("/hebergement/admin/2"); | ||
expect(response.status).toBe(400); | ||
}); | ||
}); |
108 changes: 108 additions & 0 deletions
108
packages/backend/src/routes/__tests__/hebergement/post.test.js
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const request = require("supertest"); | ||
const app = require("../../../app"); | ||
const Hebergement = require("../../../services/hebergement/Hebergement"); | ||
const checkJWT = require("../../../middlewares/checkJWT"); | ||
const checkPermissionHebergement = require("../../../middlewares/checkPermissionHebergement"); | ||
const yup = require("yup"); | ||
const FOUser = require("../../../services/FoUser"); | ||
|
||
// Mock de la méthode Hebergement.update | ||
jest.mock("../../../services/hebergement/Hebergement"); | ||
jest.mock("../../../middlewares/checkJWT"); | ||
jest.mock("../../../middlewares/checkPermissionHebergement"); | ||
jest.mock("../../../schemas/hebergement"); | ||
jest.mock("../../../services/FoUser"); | ||
|
||
describe("POST /", () => { | ||
const user = { | ||
id: 1, | ||
}; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
checkJWT.mockImplementation((req, res, next) => { | ||
req.decoded = { ...user }; | ||
next(); | ||
}); | ||
checkPermissionHebergement.mockImplementation((req, res, next) => { | ||
next(); | ||
}); | ||
}); | ||
|
||
it("should return 400 if a required parameter is missing", async () => { | ||
const res = await request(app) | ||
.post("/hebergement") | ||
.send({ nom: "Hébergement" }) // Paramètre manquant | ||
.expect(400); | ||
expect(res.statusCode).toBe(400); | ||
}); | ||
|
||
it("should return 200 if the hebergement is posted successfully", async () => { | ||
Hebergement.create.mockResolvedValueOnce(true); | ||
FOUser.getUserOrganisme.mockResolvedValueOnce(1); | ||
|
||
const body = { | ||
nom: "Hébergement 1", | ||
coordonnees: { lat: 10, lon: 20 }, | ||
informationsLocaux: {}, | ||
informationsTransport: {}, | ||
}; | ||
|
||
jest.spyOn(yup, "object").mockImplementationOnce(() => ({ | ||
validate: (parametre) => { | ||
return parametre; | ||
}, | ||
})); | ||
const res = await request(app).post("/hebergement").send(body); | ||
|
||
expect(res.status).toBe(200); | ||
expect(Hebergement.create).toHaveBeenCalledWith( | ||
1, | ||
1, | ||
expect.objectContaining(body), | ||
); | ||
}); | ||
|
||
it("should return 400 if validation fails with yup", async () => { | ||
// Simule l'échec de la validation avec yup | ||
jest.spyOn(yup, "object").mockImplementationOnce(() => ({ | ||
validate: () => { | ||
throw new Error("error"); | ||
}, | ||
})); | ||
|
||
const res = await request(app) | ||
.post("/hebergement") | ||
.send({ | ||
nom: "Hébergement", | ||
coordonnees: {}, | ||
informationsLocaux: "Info", | ||
informationsTransport: "Info", | ||
}) | ||
.expect(400); | ||
|
||
expect(res.status).toBe(400); | ||
}); | ||
|
||
it("should return 404 if Hebergement.update throws an archive error", async () => { | ||
const archiveError = new Error("Hebergement archived"); | ||
archiveError.cause = "archive"; | ||
Hebergement.update.mockRejectedValueOnce(archiveError); | ||
|
||
jest.spyOn(yup, "object").mockImplementationOnce(() => ({ | ||
validate: (parametre) => { | ||
return parametre; | ||
}, | ||
})); | ||
|
||
const res = await request(app) | ||
.post("/hebergement/123") | ||
.send({ | ||
nom: "Hébergement", | ||
coordonnees: { lat: 10, lon: 20 }, | ||
informationsLocaux: "Info locaux", | ||
informationsTransport: "Info transport", | ||
}); | ||
|
||
expect(res.status).toBe(400); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mettre au moins AS "departement" pour pas se trainer un truc bizarre dans le code