From 7c47cfc70cb418ea11b6f9f711896ade693633a9 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 24 Jan 2025 18:15:33 +0000 Subject: [PATCH] WIP: Add GetCardsHelper tests --- .../DropHelpers/GetCardsHelper.test.ts | 65 ++++++++++++++++++- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/tests/helpers/DropHelpers/GetCardsHelper.test.ts b/tests/helpers/DropHelpers/GetCardsHelper.test.ts index f0232ac..421d4ef 100644 --- a/tests/helpers/DropHelpers/GetCardsHelper.test.ts +++ b/tests/helpers/DropHelpers/GetCardsHelper.test.ts @@ -1,9 +1,68 @@ import GetCardsHelper from "../../../src/helpers/DropHelpers/GetCardsHelper"; +import EffectHelper from "../../../src/helpers/EffectHelper"; +import GetUnclaimedCardsHelper from "../../../src/helpers/DropHelpers/GetUnclaimedCardsHelper"; +import CardConstants from "../../../src/constants/CardConstants"; + +jest.mock("../../../src/helpers/EffectHelper"); +jest.mock("../../../src/helpers/DropHelpers/GetUnclaimedCardsHelper"); + +beforeEach(() => { + jest.resetAllMocks(); +}); describe("FetchCard", () => { - test.todo("GIVEN user has the unclaimed effect AND unused chance is within constraint, EXPECT unclaimed card returned"); + test("GIVEN user has the unclaimed effect AND unused chance is within constraint, EXPECT unclaimed card returned", async () => { + // Arrange + (EffectHelper.HasEffect as jest.Mock).mockResolvedValue(true); + GetCardsHelper.GetRandomCard = jest.fn(); + Math.random = jest.fn().mockReturnValue(CardConstants.UnusedChanceUpChance - 0.1); - test.todo("GIVEN user has unclaimed effect AND unused chance is NOT within constraint, EXPECT random card returned"); + // Act + await GetCardsHelper.FetchCard("userId"); - test.todo("GIVEN user does NOT have unclaimed effect, EXPECT random card returned"); + // Assert + expect(EffectHelper.HasEffect).toHaveBeenCalledTimes(1); + expect(EffectHelper.HasEffect).toHaveBeenCalledWith("userId", "unclaimed"); + + expect(GetUnclaimedCardsHelper.GetRandomCardUnclaimed).toHaveBeenCalledTimes(1); + expect(GetUnclaimedCardsHelper.GetRandomCardUnclaimed).toHaveBeenCalledWith("userId"); + + expect(GetCardsHelper.GetRandomCard).not.toHaveBeenCalled(); + }); + + test("GIVEN user has unclaimed effect AND unused chance is NOT within constraint, EXPECT random card returned", async () => { + // Arrange + (EffectHelper.HasEffect as jest.Mock).mockResolvedValue(true); + GetCardsHelper.GetRandomCard = jest.fn(); + Math.random = jest.fn().mockReturnValue(CardConstants.UnusedChanceUpChance + 0.1); + + // Act + await GetCardsHelper.FetchCard("userId"); + + // Assert + expect(EffectHelper.HasEffect).toHaveBeenCalledTimes(1); + expect(EffectHelper.HasEffect).toHaveBeenCalledWith("userId", "unclaimed"); + + expect(GetCardsHelper.GetRandomCard).toHaveBeenCalledTimes(1); + + expect(GetUnclaimedCardsHelper.GetRandomCardUnclaimed).not.toHaveBeenCalled(); + }); + + test("GIVEN user does NOT have unclaimed effect, EXPECT random card returned", async () => { + // Arrange + (EffectHelper.HasEffect as jest.Mock).mockResolvedValue(false); + GetCardsHelper.GetRandomCard = jest.fn(); + Math.random = jest.fn().mockReturnValue(CardConstants.UnusedChanceUpChance + 0.1); + + // Act + await GetCardsHelper.FetchCard("userId"); + + // Assert + expect(EffectHelper.HasEffect).toHaveBeenCalledTimes(1); + expect(EffectHelper.HasEffect).toHaveBeenCalledWith("userId", "unclaimed"); + + expect(GetCardsHelper.GetRandomCard).toHaveBeenCalledTimes(1); + + expect(GetUnclaimedCardsHelper.GetRandomCardUnclaimed).not.toHaveBeenCalled(); + }); }); \ No newline at end of file