From 60bb39253f98858ff4e4e89fb0b698f15b7b7730 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 31 Oct 2024 17:59:46 +0000 Subject: [PATCH] WIP Start creating EffectHelper tests --- tests/helpers/EffectHelper.test.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/helpers/EffectHelper.test.ts b/tests/helpers/EffectHelper.test.ts index d9520a2..9e3b5b0 100644 --- a/tests/helpers/EffectHelper.test.ts +++ b/tests/helpers/EffectHelper.test.ts @@ -1,8 +1,33 @@ +import UserEffect from "../../src/database/entities/app/UserEffect"; +import EffectHelper from "../../src/helpers/EffectHelper"; + describe("AddEffectToUserInventory", () => { describe("GIVEN effect is in database", () => { - test.todo("EXPECT effect to be updated"); + const effectMock = { + AddUnused: jest.fn(), + Save: jest.fn(), + }; - test.todo("EXPECT effect to be saved"); + beforeAll(async () => { + UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(effectMock); + + await EffectHelper.AddEffectToUserInventory("userId", "name", 1); + }); + + test("EXPECT database to be fetched", () => { + expect(UserEffect.FetchOneByUserIdAndName).toHaveBeenCalledTimes(1); + expect(UserEffect.FetchOneByUserIdAndName).toHaveBeenCalledWith("userId", "name"); + }); + + test("EXPECT effect to be updated", () => { + expect(effectMock.AddUnused).toHaveBeenCalledTimes(1); + expect(effectMock.AddUnused).toHaveBeenCalledWith(1); + }); + + test("EXPECT effect to be saved", () => { + expect(effectMock.Save).toHaveBeenCalledTimes(1); + expect(effectMock.Save).toHaveBeenCalledWith(UserEffect, effectMock); + }); }); describe("GIVEN effect is not in database", () => {