2024-10-30 10:37:36 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2024-10-26 21:48:24 +01:00
|
|
|
describe("AddUnused", () => {
|
2024-10-30 10:37:36 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
userEffect.AddUnused(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT unused to be the amount more", () => {
|
|
|
|
expect(userEffect.Unused).toBe(2);
|
|
|
|
});
|
2024-10-26 21:48:24 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("UseEffect", () => {
|
|
|
|
describe("GIVEN Unused is 0", () => {
|
2024-10-30 10:37:36 +00:00
|
|
|
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();
|
|
|
|
});
|
2024-10-26 21:48:24 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("GIVEN Unused is greater than 0", () => {
|
2024-10-30 10:37:36 +00:00
|
|
|
let result: boolean;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
result = userEffect.UseEffect(now);
|
|
|
|
});
|
2024-10-26 21:48:24 +01:00
|
|
|
|
2024-10-30 10:37:36 +00:00
|
|
|
test("EXPECT true returned", () => {
|
|
|
|
expect(result).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT Unused to be subtracted by 1", () => {
|
|
|
|
expect(userEffect.Unused).toBe(0);
|
|
|
|
});
|
2024-10-26 21:48:24 +01:00
|
|
|
|
2024-10-30 10:37:36 +00:00
|
|
|
test("EXPECT WhenExpires to be set", () => {
|
|
|
|
expect(userEffect.WhenExpires).toBe(now);
|
|
|
|
});
|
2024-10-26 21:48:24 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("IsEffectActive", () => {
|
|
|
|
describe("GIVEN WhenExpires is null", () => {
|
2024-10-30 10:37:36 +00:00
|
|
|
let result: boolean;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
result = userEffect.IsEffectActive();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT false returned", () => {
|
|
|
|
expect(result).toBe(false);
|
|
|
|
});
|
2024-10-26 21:48:24 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("GIVEN WhenExpires is defined", () => {
|
|
|
|
describe("AND WhenExpires is in the past", () => {
|
2024-10-30 10:37:36 +00:00
|
|
|
let result: boolean;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
userEffect.WhenExpires = new Date(now.getTime() - 100);
|
|
|
|
|
|
|
|
result = userEffect.IsEffectActive();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT false returned", () => {
|
|
|
|
expect(result).toBe(false);
|
|
|
|
});
|
2024-10-26 21:48:24 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("AND WhenExpires is in the future", () => {
|
2024-10-30 10:37:36 +00:00
|
|
|
let result: boolean;
|
2024-10-26 21:48:24 +01:00
|
|
|
|
2024-10-30 10:37:36 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
userEffect.WhenExpires = new Date(now.getTime() + 100);
|
2024-10-26 21:48:24 +01:00
|
|
|
|
2024-10-30 10:37:36 +00:00
|
|
|
result = userEffect.IsEffectActive();
|
|
|
|
});
|
2024-10-26 21:48:24 +01:00
|
|
|
|
2024-10-30 10:37:36 +00:00
|
|
|
test("EXPECT true returned", () => {
|
|
|
|
expect(result).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2024-10-26 21:48:24 +01:00
|
|
|
});
|