Server/project/tests/services/PlayerService.test.ts

68 lines
2.1 KiB
TypeScript
Raw Normal View History

import "reflect-metadata";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { PlayerService } from "@spt/services/PlayerService";
import { container } from "tsyringe";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
describe("PlayerService", () => {
2023-11-04 14:34:09 +01:00
let playerService: PlayerService;
beforeEach(() => {
playerService = container.resolve<PlayerService>("PlayerService");
});
afterEach(() => {
vi.restoreAllMocks();
});
describe("calculateLevel", () => {
it("should return 1 when player xp is 0", () => {
2023-11-04 15:53:08 +01:00
const playerProfile = {
Info: {
2023-11-10 23:21:20 +01:00
Experience: 0, // Via wiki: https://escapefromtarkov.fandom.com/wiki/Character_skills#Levels
},
2023-11-04 15:53:08 +01:00
};
const result = playerService.calculateLevel(playerProfile as IPmcData);
expect(result).toBe(1);
});
it("should return 1 when player xp is 999", () => {
const playerProfile = {
Info: {
2023-11-10 23:21:20 +01:00
Experience: 999, // Via wiki: https://escapefromtarkov.fandom.com/wiki/Character_skills#Levels
},
};
const result = playerService.calculateLevel(playerProfile as IPmcData);
expect(result).toBe(1);
});
it("should return 25 when player xp is 609,066", () => {
const playerProfile = {
Info: {
2023-11-10 23:21:20 +01:00
Experience: 609066, // Via wiki: https://escapefromtarkov.fandom.com/wiki/Character_skills#Levels
},
};
const result = playerService.calculateLevel(playerProfile as IPmcData);
expect(result).toBe(25);
});
it("should return 79 when player xp is 81,126,895", () => {
const playerProfile = {
Info: {
Experience: 81126895, // Via wiki: https://escapefromtarkov.fandom.com/wiki/Character_skills#Levels
2023-11-10 23:21:20 +01:00
},
};
const result = playerService.calculateLevel(playerProfile as IPmcData);
expect(result).toBe(79);
});
});
});