0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00
server/project/tests/generators/BotLevelGenerator.test.ts

84 lines
2.9 KiB
TypeScript
Raw Permalink Normal View History

2023-11-05 09:20:11 +00:00
import "reflect-metadata";
import { BotLevelGenerator } from "@spt/generators/BotLevelGenerator";
import { MinMax } from "@spt/models/common/MinMax";
BunJS Runtime, Updated Build System, and... (#992) This is a big one. 🔥 **Changes:** - Targets next major release (v4.0.0) - Switch runtimes from NodeJS to BunJS (bun.sh) - Typescript library support moved to `ESNext` - Typescript compile option `verbatimModuleSyntax` enabled - Updated all interfaces to be imported explicitly as types - Strict mode enabled - Reduces the number of tsconfig files - Pins all dep packages to specific patch versions - Includes Bun lock file in repo (doesn't cause issues like the package-lock did) - Replaces Gulp with a new Typescript based build system - Adds `core-js` as a workaround for Bun not playing nice with `reflect-metadata` - Removes `pkg` and `swc` (Yay Bun!) - Updated package scripts and entry point system to be more intuitive - Updated VSCode workspace configurations - Updated `.gitignore` to align with updated project structure - Updated Biome configuration to align with updated project structure - `Program.ts` - Removes call to set encoding on the process - `global.d.ts` - Added underscores to build globals to match other global names - `JsonUtil.ts` - Replaced old `fixJson` package with newer `jsonrepair` package - `HashUtil.ts` - Replaced old `buffer-crc32` package with built-in `node:zlib` package - `DatabaseImporter.ts` - Updates database validation object to be flat, where the keys are the relative path to the file - `BunTimer.ts` - Adds an easy to use timer class that's compatible with nanoseconds. **TODO:** - Look into mod loading. I think we use a TS transpiler for mods and I believe that can be removed now. - Bun includes a number of APIs that can be used in place of Node's packages (built-in or otherwise); HTTP server, WebSocket server, File IO, Hashing, File Globing, Testing... Each of these should be utilized where ever possible. - Update in-repo documentation to reference BunJS instead of NodeJS.
2024-12-21 17:46:39 -05:00
import type { IBotGenerationDetails } from "@spt/models/spt/bots/BotGenerationDetails";
import { container } from "tsyringe";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2023-11-05 09:20:11 +00:00
describe("BotLevelGenerator", () => {
2024-08-19 14:10:00 +00:00
let botLevelGenerator: BotLevelGenerator;
2023-11-05 09:20:11 +00:00
beforeEach(() => {
2023-11-05 09:20:11 +00:00
botLevelGenerator = container.resolve<BotLevelGenerator>("BotLevelGenerator");
});
afterEach(() => {
2023-11-05 09:20:11 +00:00
vi.restoreAllMocks();
});
describe("generateBotLevel", () => {
it("should return value between 5 and 10 when player is level 5 and max is 10", () => {
const levelDetails: MinMax = { min: 5, max: 10 };
2023-11-05 09:20:11 +00:00
const botGenerationDetails: IBotGenerationDetails = {
2023-11-05 09:20:11 +00:00
isPmc: false,
role: "",
side: "",
playerLevel: 5,
botRelativeLevelDeltaMax: 0,
botRelativeLevelDeltaMin: 0,
2023-11-05 09:20:11 +00:00
botCountToGenerate: 0,
botDifficulty: "",
2023-11-10 17:21:20 -05:00
isPlayerScav: false,
2023-11-05 09:20:11 +00:00
};
const result = botLevelGenerator.generateBotLevel(levelDetails, botGenerationDetails, null);
expect(result.level).greaterThan(0);
expect(result.level).lessThan(10);
});
});
2024-08-19 14:10:00 +00:00
describe("getRelativeBotLevelRange", () => {
it("should return 10 when player level is 5 and delta is 5", () => {
const levelDetails: MinMax = { min: 5, max: 10 };
const botGenDetails: IBotGenerationDetails = {
2024-08-19 14:10:00 +00:00
isPmc: false,
role: "",
side: "",
botRelativeLevelDeltaMax: 5,
botRelativeLevelDeltaMin: 5,
playerLevel: 5,
botCountToGenerate: 0,
botDifficulty: "",
isPlayerScav: false,
};
2023-11-05 09:20:11 +00:00
2024-08-19 14:10:00 +00:00
// @ts-expect-error
const result = botLevelGenerator.getRelativeBotLevelRange(botGenDetails, levelDetails, 79);
2023-11-05 09:20:11 +00:00
2024-08-19 14:10:00 +00:00
expect(result.max).toBe(10);
2023-11-05 09:20:11 +00:00
});
it("should return 79 when player level is above possible max (100), desired max is 100 and delta is 5", () => {
const levelDetails: MinMax = { min: 100, max: 100 };
const botGenDetails: IBotGenerationDetails = {
2024-08-19 14:10:00 +00:00
isPmc: false,
role: "",
side: "",
botRelativeLevelDeltaMax: 5,
botRelativeLevelDeltaMin: 5,
playerLevel: 100,
botCountToGenerate: 0,
botDifficulty: "",
isPlayerScav: false,
};
2023-11-05 09:20:11 +00:00
2024-08-19 14:10:00 +00:00
// @ts-expect-error
const result = botLevelGenerator.getRelativeBotLevelRange(botGenDetails, levelDetails, 79);
2023-11-05 09:20:11 +00:00
2024-08-19 14:10:00 +00:00
expect(result.max).toBe(79);
2023-11-05 09:20:11 +00:00
});
});
});