Test - InRaidHelper

- Removes tests for missing calculateFenceStandingChangeFromKills method
- Adds a test for the resetSkillPointsEarnedDuringRaid method
This commit is contained in:
Refringe 2024-04-11 21:07:37 -04:00
parent 5aebbb9c86
commit b59ffd8ff2
No known key found for this signature in database
GPG Key ID: 7715B85B4A6306ED

View File

@ -3,7 +3,8 @@ import { container } from "tsyringe";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { InRaidHelper } from "@spt-aki/helpers/InRaidHelper";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
describe("InRaidHelper", () =>
{
@ -19,67 +20,32 @@ describe("InRaidHelper", () =>
vi.restoreAllMocks();
});
describe("calculateFenceStandingChangeFromKills", () =>
describe("resetSkillPointsEarnedDuringRaid", () =>
{
it("should return negative value when player kills 2 scavs as scav", () =>
it("should reset PointsEarnedDuringSession for each skill in profile", () =>
{
const fenceStanding = 0;
const postRaidPlayerVictims = [{ Side: "Savage", Role: "assault" }, { Side: "Savage", Role: "assault" }]; // Kills
const mockProfile = {
Skills: {
Common: [
{ Id: "BotReload", Progress: 160.543, PointsEarnedDuringSession: 42, LastAccess: 1712633904 },
{ Id: "BotSound", Progress: 145.6547, PointsEarnedDuringSession: 42, LastAccess: 1712633904 },
{
Id: "Endurance",
Progress: 223.951157,
PointsEarnedDuringSession: 42,
LastAccess: 1712633904,
},
{ Id: "Strength", Progress: 141.2618, PointsEarnedDuringSession: 42, LastAccess: 1712633904 },
],
},
};
const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
const scavStandingChangeOnKill = databaseServer.getTables().bots.types.assault.experience.standingForKill;
(inraidHelper as any).resetSkillPointsEarnedDuringRaid(<IPmcData>mockProfile);
const result = inraidHelper.calculateFenceStandingChangeFromKills(fenceStanding, postRaidPlayerVictims);
expect(result).toBe(scavStandingChangeOnKill * postRaidPlayerVictims.length); // Scav rep loss times number of scav kills
expect(result).lessThan(0);
});
it("should return positive value when player kills 2 PMCs of different sides as scav", () =>
{
const fenceStanding = 0;
const postRaidPlayerVictims = [{ Side: "Usec", Role: "sptUsec" }, { Side: "Bear", Role: "sptBear" }]; // Kills
const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
const bearStandingChangeOnKill = databaseServer.getTables().bots.types.bear.experience.standingForKill;
const usecStandingChangeOnKill = databaseServer.getTables().bots.types.bear.experience.standingForKill;
const result = inraidHelper.calculateFenceStandingChangeFromKills(fenceStanding, postRaidPlayerVictims);
expect(result).toBe(bearStandingChangeOnKill + usecStandingChangeOnKill);
expect(result).greaterThan(0);
});
it("should return negative value when player kills 1 PMC, 1 boss and 2 scavs as scav", () =>
{
const fenceStanding = 0;
const postRaidPlayerVictims = [{ Side: "Usec", Role: "sptUsec" }, { Side: "savage", Role: "assault" }, {
Side: "savage",
Role: "bossBoar",
}, { Side: "savage", Role: "assault" }]; // Kills
const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
const usecStandingChangeOnKill = databaseServer.getTables().bots.types.bear.experience.standingForKill;
const scavStandingChangeOnKill = databaseServer.getTables().bots.types.assault.experience.standingForKill;
const bossBoarStandingChangeOnKill =
databaseServer.getTables().bots.types.bossboar.experience.standingForKill;
const result = inraidHelper.calculateFenceStandingChangeFromKills(fenceStanding, postRaidPlayerVictims);
expect(result).toBe(
usecStandingChangeOnKill + (scavStandingChangeOnKill * 2) + bossBoarStandingChangeOnKill,
);
expect(result).lessThan(0);
});
it("should return 0 when player kills bot with undefined standing as scav", () =>
{
const fenceStanding = 0;
const postRaidPlayerVictims = [{ Side: "savage", Role: "testRole" }]; // Kills
// Fake getFenceStandingChangeForKillAsScav() returning null
vi.spyOn(inraidHelper, "getFenceStandingChangeForKillAsScav").mockReturnValueOnce(null).mockReturnValueOnce(
null,
);
const result = inraidHelper.calculateFenceStandingChangeFromKills(fenceStanding, postRaidPlayerVictims);
expect(result).toBe(0);
for (const skill of mockProfile.Skills.Common)
{
expect(skill.PointsEarnedDuringSession).toBe(0);
}
});
});
});