From 98620d2e1f08fef63b8bc3e669481913462a3a23 Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 14 May 2024 15:45:56 +0100 Subject: [PATCH] Added tests for `botDifficultyHelper` --- .../tests/helpers/BotDifficultyHelper.test.ts | 68 +++++++++++++++++++ project/tests/services/LocaleService.test.ts | 2 +- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 project/tests/helpers/BotDifficultyHelper.test.ts diff --git a/project/tests/helpers/BotDifficultyHelper.test.ts b/project/tests/helpers/BotDifficultyHelper.test.ts new file mode 100644 index 00000000..e0d1543b --- /dev/null +++ b/project/tests/helpers/BotDifficultyHelper.test.ts @@ -0,0 +1,68 @@ + + +import "reflect-metadata"; +import { container } from "tsyringe"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +import { BotDifficultyHelper } from "@spt-aki/helpers/BotDifficultyHelper"; + +describe("BotHelper", () => +{ + let botDifficultyHelper: any; + + beforeEach(() => + { + botDifficultyHelper = container.resolve("BotDifficultyHelper"); + }); + + afterEach(() => + { + vi.restoreAllMocks(); + }); + + describe("convertBotDifficultyDropdownToBotDifficulty", () => + { + it("should return 'normal' when medium passed in", () => + { + expect(botDifficultyHelper.convertBotDifficultyDropdownToBotDifficulty("medium")).toBe("normal"); + }); + + it("should return 'normal' when randomly capitalized medium passed in", () => + { + expect(botDifficultyHelper.convertBotDifficultyDropdownToBotDifficulty("mEdIuM")).toBe("normal"); + }); + + it("should return passed in value when its not medium or random", () => + { + expect(botDifficultyHelper.convertBotDifficultyDropdownToBotDifficulty("test_value")).toBe("test_value"); + }); + + it("should return randomised value when random passed in", () => + { + vi.spyOn(botDifficultyHelper, "chooseRandomDifficulty").mockReturnValue( + "randomValue" + ); + + expect(botDifficultyHelper.convertBotDifficultyDropdownToBotDifficulty("random")).toBe("randomValue"); + }); + }); + + describe("getBotDifficultySettings", () => + { + + it("should return assault bot if invalid bot type provided", () => + { + vi.spyOn(botDifficultyHelper, "convertBotDifficultyDropdownToBotDifficulty").mockReturnValue( + "normal" + ); + vi.spyOn(botDifficultyHelper.botHelper, "getBotTemplate").mockReturnValue( + { difficulty: {normal: "test"}} + ); + const warningLogSpy = vi.spyOn(botDifficultyHelper.logger, "warning"); + + const result = botDifficultyHelper.getBotDifficultySettings("INVALID_TYPE", "normal") + expect(result).toBe("test"); + expect(warningLogSpy).toHaveBeenCalledTimes(1); + }); + }); +}); diff --git a/project/tests/services/LocaleService.test.ts b/project/tests/services/LocaleService.test.ts index 9e373ed7..ed4f49d2 100644 --- a/project/tests/services/LocaleService.test.ts +++ b/project/tests/services/LocaleService.test.ts @@ -87,7 +87,7 @@ describe("LocaleService", () => undefined ); - const warningLogSpy = vi.spyOn(localeService.logger, "warning") + const warningLogSpy = vi.spyOn(localeService.logger, "warning"); expect(localeService.getPlatformForServerLocale()).toBe("en"); expect(warningLogSpy).toHaveBeenCalledTimes(1);