This commit is contained in:
parent
d995d9505e
commit
7c47cfc70c
1 changed files with 62 additions and 3 deletions
|
@ -1,9 +1,68 @@
|
||||||
import GetCardsHelper from "../../../src/helpers/DropHelpers/GetCardsHelper";
|
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", () => {
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Reference in a new issue