Skip to content

Commit

Permalink
Added accessible challenges tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AJaccP committed Jun 13, 2024
1 parent 0aaee4f commit c0c15f5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/challenges-platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export {
ParticipantsService,
ReviewsService,
SubmissionService,
AccesibleChallengesService,
} from "./services";
import { Transformer } from "./models";
import { transformers } from "../../config/challenges-platform/transformers";
Expand Down
32 changes: 32 additions & 0 deletions test/challenges-platform/factories/accessible-challenge-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { challengeFactory } from "./challenge-factory";
import { participantFactory } from "./participant-factory";
import {
Challenge,
Participant,
} from "../../../app/challenges-platform/models";
import { AccesibleChallengesService } from "../../../app/challenges-platform";
import { db } from "../../../db";
import { accessibleChallenges } from "../../../db/schema";

export const accessibleChallengeFactory = async ({
challenge,
participant,
}: {
challenge?: Challenge;
participant?: Participant;
} = {}): Promise<Number> => {
const c = challenge || (await challengeFactory());
const p = participant || (await participantFactory());

const insertResult = await db
.insert(accessibleChallenges)
.values({
challengeId: c.id,
participantId: p.id,
})
.returning();

const result = await AccesibleChallengesService.count(c, p);
if (!result.ok) fail("Expected result to be Ok");
return result.val;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { challengeFactory } from "../factories/challenge-factory";
import { participantFactory } from "../factories/participant-factory";
import { accessibleChallengeFactory } from "../factories/accessible-challenge-factory";
import { AccesibleChallengesService } from "../../../app/challenges-platform";

describe("AccessibleChallengesService", () => {
describe("count", () => {
describe("when the challenge is not accessible", () => {
it("returns 0", async () => {
const challenge = await challengeFactory();
const participant = await participantFactory();

const result = await AccesibleChallengesService.count(challenge, participant);

if (!result.ok) fail("Expected result to be Ok");
expect(result.val).toBe(0);
});
});
describe("when the challenge is accessible", () => {
it("returns 1", async () => {
const challenge = await challengeFactory();
const participant = await participantFactory();

const insert = await accessibleChallengeFactory({
challenge,
participant
});

const result = await AccesibleChallengesService.count(challenge, participant);

if (!result.ok) fail("Expected result to be Ok");
expect(result.val).toBe(1);
});
});
})
});

0 comments on commit c0c15f5

Please sign in to comment.