card-drop/tests/database/entities/app/UserEffect.test.ts
Ethan Lane e449e1a2b2
Some checks failed
Test / build (push) Failing after 12s
WIP: Create UserEffect tests
2024-10-30 10:37:36 +00:00

104 lines
2.6 KiB
TypeScript

import AppDataSource from "../../../../src/database/dataSources/appDataSource";
import UserEffect from "../../../../src/database/entities/app/UserEffect";
let userEffect: UserEffect;
const now = new Date();
beforeEach(() => {
userEffect = new UserEffect("name", "userId", 1);
});
describe("AddUnused", () => {
beforeEach(() => {
userEffect.AddUnused(1);
});
test("EXPECT unused to be the amount more", () => {
expect(userEffect.Unused).toBe(2);
});
});
describe("UseEffect", () => {
describe("GIVEN Unused is 0", () => {
let result: boolean;
beforeEach(() => {
userEffect.Unused = 0;
result = userEffect.UseEffect(now);
});
test("EXPECT false returned", () => {
expect(result).toBe(false);
});
test("EXPECT details not to be changed", () => {
expect(userEffect.Unused).toBe(0);
expect(userEffect.WhenExpires).toBeUndefined();
});
});
describe("GIVEN Unused is greater than 0", () => {
let result: boolean;
beforeEach(() => {
result = userEffect.UseEffect(now);
});
test("EXPECT true returned", () => {
expect(result).toBe(true);
});
test("EXPECT Unused to be subtracted by 1", () => {
expect(userEffect.Unused).toBe(0);
});
test("EXPECT WhenExpires to be set", () => {
expect(userEffect.WhenExpires).toBe(now);
});
});
});
describe("IsEffectActive", () => {
describe("GIVEN WhenExpires is null", () => {
let result: boolean;
beforeEach(() => {
result = userEffect.IsEffectActive();
});
test("EXPECT false returned", () => {
expect(result).toBe(false);
});
});
describe("GIVEN WhenExpires is defined", () => {
describe("AND WhenExpires is in the past", () => {
let result: boolean;
beforeEach(() => {
userEffect.WhenExpires = new Date(now.getTime() - 100);
result = userEffect.IsEffectActive();
});
test("EXPECT false returned", () => {
expect(result).toBe(false);
});
});
describe("AND WhenExpires is in the future", () => {
let result: boolean;
beforeEach(() => {
userEffect.WhenExpires = new Date(now.getTime() + 100);
result = userEffect.IsEffectActive();
});
test("EXPECT true returned", () => {
expect(result).toBe(true);
});
});
});
});