card-drop/tests/helpers/DropHelpers/GetCardsHelper.test.ts

68 lines
2.8 KiB
TypeScript
Raw Normal View History

2025-01-24 18:04:54 +00:00
import GetCardsHelper from "../../../src/helpers/DropHelpers/GetCardsHelper";
2025-01-24 18:15:33 +00:00
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();
});
2025-01-24 18:04:54 +00:00
describe("FetchCard", () => {
2025-01-24 18:15:33 +00:00
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);
// Act
await GetCardsHelper.FetchCard("userId");
// 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");
2025-01-24 18:15:33 +00:00
expect(GetCardsHelper.GetRandomCard).toHaveBeenCalledTimes(1);
2025-01-24 18:15:33 +00:00
expect(GetUnclaimedCardsHelper.GetRandomCardUnclaimed).not.toHaveBeenCalled();
});
});