Create use effect command #419

Merged
Vylpes merged 26 commits from feature/380-use-effect into develop 2025-01-25 17:29:01 +00:00
Showing only changes of commit 7c47cfc70c - Show all commits

View file

@ -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();
});
});