Server/project/tests/generators/BotGenerator.test.ts

149 lines
5.9 KiB
TypeScript
Raw Normal View History

2023-11-05 21:11:52 +01:00
import "reflect-metadata";
2023-11-10 23:21:20 +01:00
import { container } from "tsyringe";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2023-11-05 21:11:52 +01:00
2023-11-13 17:43:37 +01:00
import { BotGenerator } from "@spt-aki/generators/BotGenerator";
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
2023-11-05 21:11:52 +01:00
describe("BotGenerator", () =>
{
let botGenerator: any;
beforeEach(() =>
2023-11-05 21:11:52 +01:00
{
botGenerator = container.resolve<BotGenerator>("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(<IPmcData>mockPlayerProfile);
// vi.spyOn(botGenerator.botEquipmentFilterService.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
// vi.spyOn(botGenerator.botInventoryGenerator.botWeaponGenerator.botEquipmentModGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>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");
// });
// });
describe("generateBotNickname", () =>
2023-11-05 21:11:52 +01:00
{
it("should return single name `test` for non pscav assault bot name ", () =>
{
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 0;
const mockPlayerProfile = { Info: { Nickname: "Player Nickname", Level: 1 } };
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
const botJsonTemplate = { firstName: ["test"], lastName: [] };
const sessionId = "sessionId";
const isPlayerScav = false;
const botRole = "assault";
const result = botGenerator.generateBotNickname(botJsonTemplate, isPlayerScav, botRole, sessionId);
expect(result).toBe("test");
});
it("should return `test assault` for non pscav assault bot with `showTypeInNickname` enabled ", () =>
2023-11-05 21:11:52 +01:00
{
botGenerator.botConfig.showTypeInNickname = true;
const mockPlayerProfile = { Info: { Nickname: "Player Nickname", Level: 1 } };
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
const botJsonTemplate = { firstName: ["test"], lastName: [] };
const sessionId = "sessionId";
const isPlayerScav = false;
const botRole = "assault";
const result = botGenerator.generateBotNickname(botJsonTemplate, isPlayerScav, botRole, sessionId);
expect(result).toBe("test assault");
});
2023-11-05 21:11:52 +01:00
it("should return name `test Player` for bot with same name as player and `addPrefixToSameNamePMCAsPlayerChance` 100%", () =>
{
botGenerator.botConfig.showTypeInNickname = false;
botGenerator.pmcConfig.addPrefixToSameNamePMCAsPlayerChance = 100;
const mockPlayerProfile = { Info: { Nickname: "Player", Level: 1 } };
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
vi.spyOn(botGenerator.localisationService, "getRandomTextThatMatchesPartialKey").mockReturnValue("test");
const botJsonTemplate = { firstName: ["Player"], lastName: [] };
const sessionId = "sessionId";
const isPlayerScav = false;
const botRole = "assault";
const result = botGenerator.generateBotNickname(botJsonTemplate, isPlayerScav, botRole, sessionId);
expect(result).toBe("test Player");
});
it("should return name `test` for player scav bot", () =>
{
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 100;
const mockPlayerProfile = { Info: { Nickname: "Player", Level: 1 } };
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
const botJsonTemplate = { firstName: ["test"], lastName: [] };
const sessionId = "sessionId";
const isPlayerScav = true;
const botRole = "assault";
const result = botGenerator.generateBotNickname(botJsonTemplate, isPlayerScav, botRole, sessionId);
expect(result).toBe("test");
});
it("should return name `test (usec)` for player scav bot", () =>
{
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 100;
botGenerator.databaseServer.getTables().bots.types.usec.firstName = ["usec"];
botGenerator.databaseServer.getTables().bots.types.bear.firstName = [];
const mockPlayerProfile = { Info: { Nickname: "Player", Level: 1 } };
2023-11-05 21:11:52 +01:00
vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(<IPmcData>mockPlayerProfile);
const botJsonTemplate = { firstName: ["test"], lastName: [] };
2023-11-05 21:11:52 +01:00
const sessionId = "sessionId";
const isPlayerScav = false;
const botRole = "assault";
2023-11-05 21:11:52 +01:00
const result = botGenerator.generateBotNickname(botJsonTemplate, isPlayerScav, botRole, sessionId);
expect(result).toBe("test (usec)");
2023-11-05 21:11:52 +01:00
});
});
});