From 54223f384891743d4f635545a68c9f2249246aad Mon Sep 17 00:00:00 2001 From: Dev Date: Sun, 5 Nov 2023 20:11:52 +0000 Subject: [PATCH] Add botController test --- project/tests/Setup.test.ts | 3 +- project/tests/generators/BotGenerator.test.ts | 56 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 project/tests/generators/BotGenerator.test.ts diff --git a/project/tests/Setup.test.ts b/project/tests/Setup.test.ts index 0cee7191..c1bcef0c 100644 --- a/project/tests/Setup.test.ts +++ b/project/tests/Setup.test.ts @@ -3,6 +3,7 @@ import "@tests/controllers/InsuranceController.test"; //Generators import "@tests/generators/BotLevelGenerator.test"; +import "@tests/generators/BotGenerator.test"; //Helpers import "@tests/helpers/BotHelper.test"; @@ -13,4 +14,4 @@ import "@tests/helpers/ItemHelper.test"; //Services import "@tests/services/ItemBaseClassService.test"; import "@tests/services/PaymentService.test"; -import "@tests/services/PlayerService.test"; +import "@tests/services/PlayerService.test"; \ No newline at end of file diff --git a/project/tests/generators/BotGenerator.test.ts b/project/tests/generators/BotGenerator.test.ts new file mode 100644 index 00000000..c40defbe --- /dev/null +++ b/project/tests/generators/BotGenerator.test.ts @@ -0,0 +1,56 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import "reflect-metadata"; +import { container } from "tsyringe"; +import { vi, beforeAll, afterEach, describe, expect, it } from "vitest"; +import { BotGenerator } from "@spt-aki/generators/BotGenerator"; +import { BotGenerationDetails } from "@spt-aki/models/spt/bots/BotGenerationDetails"; +import { IPmcData } from "@spt-aki/models/eft/common/IPmcData"; + +describe("BotGenerator", () => +{ + let botGenerator: any; + + beforeAll(() => + { + botGenerator = container.resolve("BotGenerator"); + }); + + afterEach(() => + { + vi.restoreAllMocks(); + }); + + describe("prepareAndGenerateBots", () => + { + it("should return a single generated assault bot", () => + { + const mockPlayerProfile = { + Info: { + Nickname: "Player Nickname", + Level: 1 + } + }; + + vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); + vi.spyOn(botGenerator.botEquipmentFilterService.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); + vi.spyOn(botGenerator.botInventoryGenerator.botWeaponGenerator.botEquipmentModGenerator.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); + + const sessionId = "12345"; + const generationDetails: BotGenerationDetails = { + isPmc: false, + role: "assault", + side: "Savage", + playerLevel: 1, + botRelativeLevelDeltaMax: 10, + botCountToGenerate: 1, + botDifficulty: "easy", + isPlayerScav: false + }; + + const result = botGenerator.prepareAndGenerateBots(sessionId, generationDetails); + + expect(result.length).toBe(1); + expect(result[0].Info.Side).toBe("Savage"); + }); + }); +});