From e449e1a2b2bc1a31c8984d0a7b2af97b2d9840b7 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 30 Oct 2024 10:37:36 +0000 Subject: [PATCH] WIP: Create UserEffect tests --- .../database/entities/app/UserEffect.test.ts | 95 +++++++++++++++---- 1 file changed, 79 insertions(+), 16 deletions(-) diff --git a/tests/database/entities/app/UserEffect.test.ts b/tests/database/entities/app/UserEffect.test.ts index 7b5c16b..bcd5b21 100644 --- a/tests/database/entities/app/UserEffect.test.ts +++ b/tests/database/entities/app/UserEffect.test.ts @@ -1,41 +1,104 @@ +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", () => { - test.todo("EXPECT unused to be the amount more"); + beforeEach(() => { + userEffect.AddUnused(1); + }); + + test("EXPECT unused to be the amount more", () => { + expect(userEffect.Unused).toBe(2); + }); }); describe("UseEffect", () => { describe("GIVEN Unused is 0", () => { - test.todo("EXPECT false returned"); + 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", () => { - test.todo("EXPECT true returned"); + let result: boolean; - test.todo("EXPECT Unused to be subtracted by 1"); + beforeEach(() => { + result = userEffect.UseEffect(now); + }); - test.todo("EXPECT WhenExpires to be set"); + 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", () => { - test.todo("EXPECT false returned"); + 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", () => { - test.todo("EXPECT false returned"); + 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", () => { - test.todo("EXPECT true returned"); + let result: boolean; + + beforeEach(() => { + userEffect.WhenExpires = new Date(now.getTime() + 100); + + result = userEffect.IsEffectActive(); + }); + + test("EXPECT true returned", () => { + expect(result).toBe(true); + }); }); }); }); - -describe("FetchOneByUserIdAndName", () => { - test.todo("EXPECT entity to be returned"); - - test.todo("EXPECT AppDataSource.getRepository to have been called"); - - test.todo("EXPECT repository.findOne to have been called"); -});