From 885b6a083c9cc87d7ba3a9c3ff04a899f7f6e622 Mon Sep 17 00:00:00 2001 From: Matthew M-B Date: Sat, 22 Jun 2024 13:13:08 -0400 Subject: [PATCH] Add factory tweak --- .../factories/accessible-challenge-factory.ts | 4 +++- .../services/reviews-service.test.ts | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/test/challenges-platform/factories/accessible-challenge-factory.ts b/test/challenges-platform/factories/accessible-challenge-factory.ts index 80b1b0e..c048c9b 100644 --- a/test/challenges-platform/factories/accessible-challenge-factory.ts +++ b/test/challenges-platform/factories/accessible-challenge-factory.ts @@ -13,7 +13,7 @@ export const accessibleChallengeFactory = async ({ }: { challenge?: Challenge; participant?: Participant; -} = {}): Promise => { +} = {}): Promise<[Challenge, Participant]> => { const c = challenge || (await challengeFactory()); const p = participant || (await participantFactory()); @@ -24,4 +24,6 @@ export const accessibleChallengeFactory = async ({ participantId: p.id, }) .returning(); + + return [c, p]; }; diff --git a/test/challenges-platform/services/reviews-service.test.ts b/test/challenges-platform/services/reviews-service.test.ts index 5a91989..f891820 100644 --- a/test/challenges-platform/services/reviews-service.test.ts +++ b/test/challenges-platform/services/reviews-service.test.ts @@ -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( @@ -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, @@ -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 }); });