Server/project/tests/helpers/BotHelper.test.ts

136 lines
4.0 KiB
TypeScript
Raw Normal View History

2023-11-04 14:34:09 +01:00
import "reflect-metadata";
import { container } from "tsyringe";
2023-11-10 23:21:20 +01:00
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { BotHelper } from "@spt/helpers/BotHelper";
2023-11-04 14:34:09 +01:00
describe("BotHelper", () =>
{
let botHelper: any;
beforeEach(() =>
2023-11-04 14:34:09 +01:00
{
botHelper = container.resolve<BotHelper>("BotHelper");
});
afterEach(() =>
{
vi.restoreAllMocks();
});
describe("isBotPmc", () =>
{
it("should return true when lowercase PMC role is provided", () =>
{
const result = botHelper.isBotPmc("usec");
expect(result).toBe(true);
});
it("should return true when uppercase PMC role is provided", () =>
{
const result = botHelper.isBotPmc("pmcBEAR");
2023-11-04 14:34:09 +01:00
expect(result).toBe(true);
});
it("should return false when legitimate non-PMC role is provided", () =>
{
const result = botHelper.isBotPmc("assault");
expect(result).toBe(false);
});
it("should return false when legitimate non-PMC role is provided", () =>
{
const result = botHelper.isBotPmc("FLUBBUB");
expect(result).toBe(false);
});
it("should return false when undefined role is provided", () =>
{
const result = botHelper.isBotPmc(undefined);
expect(result).toBe(false);
});
it("should return false when empty string role is provided", () =>
{
const result = botHelper.isBotPmc("");
expect(result).toBe(false);
});
});
describe("isBotBoss", () =>
{
it("should return true when lowercase boss role is provided", () =>
{
const result = botHelper.isBotBoss("bossboar");
expect(result).toBe(true);
});
it("should return true when uppercase boss role is provided", () =>
{
const result = botHelper.isBotBoss("BOSSBOAR");
expect(result).toBe(true);
});
it("should return false when legitimate non-boss role is provided", () =>
{
const result = botHelper.isBotBoss("assault");
expect(result).toBe(false);
});
it("should return false when undefined role is provided", () =>
{
const result = botHelper.isBotBoss(undefined);
expect(result).toBe(false);
});
it("should return false when empty string role is provided", () =>
{
const result = botHelper.isBotBoss("");
expect(result).toBe(false);
});
});
describe("getPmcSideByRole", () =>
{
it("should return `Bear` when pmcBEAR role is provided", () =>
2023-11-04 14:34:09 +01:00
{
const result = botHelper.getPmcSideByRole("pmcBEAR");
2023-11-04 14:34:09 +01:00
expect(result).toBe("Bear");
});
it("should return `Usec` when pmcUSEC role is provided", () =>
2023-11-04 14:34:09 +01:00
{
const result = botHelper.getPmcSideByRole("pmcUSEC");
2023-11-04 14:34:09 +01:00
expect(result).toBe("Usec");
});
it("should return `Usec` or `Bear` when non-PMC role is provided", () =>
{
const result = botHelper.getPmcSideByRole("assault");
expect(["Usec", "Bear"]).toContain(result);
});
it("should return `Usec` or `Bear` when empty string role is provided", () =>
{
const result = botHelper.getPmcSideByRole("");
expect(["Usec", "Bear"]).toContain(result);
});
});
describe("getRandomizedPmcSide", () =>
{
it("should return `Bear` when isUsec config set to 0", () =>
{
botHelper.pmcConfig.isUsec = 0;
const result = botHelper.getRandomizedPmcSide();
expect(result).toBe("Bear");
});
it("should return `Bear` when isUsec config set to 100", () =>
{
botHelper.pmcConfig.isUsec = 100;
const result = botHelper.getRandomizedPmcSide();
expect(result).toBe("Usec");
});
});
});