Skip to content

Commit

Permalink
Add factory tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
MathyouMB committed Jun 22, 2024
1 parent 7d16f6c commit 885b6a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const accessibleChallengeFactory = async ({
}: {
challenge?: Challenge;
participant?: Participant;
} = {}): Promise<any> => {
} = {}): Promise<[Challenge, Participant]> => {
const c = challenge || (await challengeFactory());
const p = participant || (await participantFactory());

Expand All @@ -24,4 +24,6 @@ export const accessibleChallengeFactory = async ({
participantId: p.id,
})
.returning();

return [c, p];
};
16 changes: 13 additions & 3 deletions test/challenges-platform/services/reviews-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ import { ReviewsService } from "../../../app/challenges-platform";
import { Status } from "../../../app/challenges-platform/models";
import { uuid } from "../../../app/common";
import { reviewFactory } from "../factories/review-factory";
import { challengeFactory } from "../factories/challenge-factory";
import { participantFactory } from "../factories/participant-factory";
import { submissionFactory } from "../factories/submission-factory";
import { accessibleChallengeFactory } from "../factories/accessible-challenge-factory";

describe("ReviewsService", () => {
describe("create", () => {
describe("when submission exists", () => {
it("succesfully creates a review", async () => {
const submission = await submissionFactory();
const [challenge, participant] = await accessibleChallengeFactory();
const submission = await submissionFactory({
challenge: challenge,
participant: participant,
});
const body = "Nice work";

const result = await ReviewsService.create(
Expand Down Expand Up @@ -40,7 +47,11 @@ describe("ReviewsService", () => {
describe("when review exists", () => {
it("returns the review", async () => {
const body = "Nice work";
const submission = await submissionFactory();
const [challenge, participant] = await accessibleChallengeFactory();
const submission = await submissionFactory({
challenge: challenge,
participant: participant,
});
const review = await reviewFactory({
submission: submission,
body: body,
Expand Down Expand Up @@ -72,6 +83,5 @@ describe("ReviewsService", () => {
expect(result.val.toString()).toBe("Error: Review not found");
});
});
// implement test for when there is an existing record, need factory(?) + create method
});
});

0 comments on commit 885b6a0

Please sign in to comment.