Skip to content

Commit

Permalink
small challenge deletion fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AJaccP authored and MathyouMB committed Jun 22, 2024
1 parent 0a0325a commit 7d16f6c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/challenges-platform/services/submissions-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ const beforeCreate = async (
const challengeResult = await ChallengesService.findByUuid(challengeId);
if (!challengeResult.ok) {
return Err(new Error("Failed to find challenge"));
} else if (challengeResult.val.deleted === true) {
return Err(new Error("Challenge is deleted"));
}

const participantResult = await ParticipantsService.findByUuid(participantId);
Expand Down
21 changes: 21 additions & 0 deletions test/challenges-platform/services/submissions-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ describe("SubmissionService", () => {
expect(result.val.toString()).toBe("Error: Failed to find challenge");
});
});

describe("when challenge is deleted", () => {
it("returns an error", async () => {
const factory = await challengeFactory();
// Delete the challenge
const challenge = await ChallengesService.destroy(factory.uuid);
if (!challenge.ok)
fail("Expected challenge to be Ok, something went really wrong");

const participant = await participantFactory();

const result = await SubmissionService.create(
challenge.val.uuid,
participant.uuid,
);

expect(result.err).toBe(true);
expect(result.val.toString()).toBe("Error: Challenge is deleted");
});
});

describe("when participant does not exist", () => {
it("returns an error", async () => {
const challenge = await challengeFactory();
Expand Down

0 comments on commit 7d16f6c

Please sign in to comment.