Skip to content

Commit

Permalink
Merge pull request #124 from lennygir/fix/185-co-supervisor-overlap
Browse files Browse the repository at this point in the history
fix/185-co-supervisor-overlap
  • Loading branch information
valerianoCarlos authored Jan 16, 2024
2 parents ed6ec5b + 3b5d3e8 commit 5c10cb1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ function validateProposal(res, proposal, user) {
if (!groups.every((group) => legal_groups.includes(group))) {
throw new Error("Invalid groups");
}
if (co_supervisors.includes(user.email)) {
throw new Error(
"The supervisor's email is included in the list of co-supervisors",
);
}
}

async function setStateToApplication(req, res, state) {
Expand Down
35 changes: 35 additions & 0 deletions server/tests/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,33 @@ it("CRUD on proposal", async () => {
});
});

describe("Proposal update tests", () => {
it("Update of a proposal with the supervisor in the list of co-supervisors", async () => {
logIn("[email protected]");
const inserted_proposal_id = (await insertProposal(proposal)).body;
proposal.co_supervisors.push("[email protected]");
const response = await modifyProposal(inserted_proposal_id, proposal);
expect(response.status).toBe(400);
expect(response.body).toEqual({
message:
"The supervisor's email is included in the list of co-supervisors",
});
});
});

describe("Proposal insertion tests", () => {
it("Insertion of a proposal with the supervisor in the list of co-supervisors", async () => {
logIn("[email protected]");
proposal.co_supervisors.push("[email protected]");
const response = await insertProposal(proposal);
expect(response.status).toBe(400);
expect(response.body).toEqual({
message:
"The supervisor's email is included in the list of co-supervisors",
});
const returned_proposals = (await getProposals()).body;
expect(returned_proposals).toHaveLength(0);
});
it("Insertion of a proposal with no notes", async () => {
proposal.notes = null;

Expand Down Expand Up @@ -698,6 +724,9 @@ describe("Proposal expiration tests (no virtual clock)", () => {

// the professor inserts a proposal
logIn("[email protected]");
proposal.co_supervisors = proposal.co_supervisors.filter(
(co_supervisor) => co_supervisor !== "[email protected]",
);
const inserted_proposal_id = (await insertProposal(proposal)).body;

// the student applies for the proposal
Expand All @@ -714,6 +743,9 @@ describe("Proposal expiration tests (no virtual clock)", () => {
logIn("[email protected]");
proposal.expiration_date = dayjs().add(1, "day").format("YYYY-MM-DD");
proposal.groups = ["ELITE"];
proposal.co_supervisors = proposal.co_supervisors.filter(
(co_supervisor) => co_supervisor !== "[email protected]",
);
const notExpiredProposalId = (await insertProposal(proposal)).body;

// the same student, now that the previous proposal is expired, can apply to another proposal
Expand Down Expand Up @@ -775,6 +807,9 @@ describe("Proposal expiration tests (no virtual clock)", () => {

// the professor inserts a proposal
logIn("[email protected]");
proposal.co_supervisors = proposal.co_supervisors.filter(
(co_supervisor) => co_supervisor !== "[email protected]",
);
const inserted_proposal_id = (await insertProposal(proposal)).body;

// the proposal expires
Expand Down

0 comments on commit 5c10cb1

Please sign in to comment.