Server/project/tests/RepairHelper.test.ts

216 lines
7.8 KiB
TypeScript
Raw Normal View History

2023-03-03 16:23:46 +01:00
import "reflect-metadata";
import { RepairHelper } from "@spt-aki/helpers/RepairHelper";
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
import { ITemplateItem } from "@spt-aki/models/eft/common/tables/ITemplateItem";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
import { LocalisationService } from "@spt-aki/services/LocalisationService";
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
import { RandomUtil } from "@spt-aki/utils/RandomUtil";
2023-03-03 16:23:46 +01:00
import { TestHelper } from "./common/TestHelper";
let testHelper: TestHelper;
let logger: ILogger;
let jsonUtil: JsonUtil;
let randomUtil: RandomUtil;
let configServer: ConfigServer;
let localisationService: LocalisationService;
let databaseServer: DatabaseServer;
let helper: RepairHelper;
describe("BotHelper", () => {
beforeAll(async () => {
testHelper = await TestHelper.fetchTestHelper();
logger = testHelper.getTestLogger();
jsonUtil = testHelper.getTestJsonUtil();
randomUtil = testHelper.getTestRandomUtil();
configServer = testHelper.getTestConfigServer();
localisationService = testHelper.getTestLocalisationService();
databaseServer = testHelper.getTestDatabaseServer();
})
beforeEach(() => {
2023-03-03 16:23:46 +01:00
helper = new RepairHelper(
logger,
jsonUtil,
randomUtil,
databaseServer,
configServer);
});
it("RepairHelper type check", () =>
{
expect(helper).toBeInstanceOf(RepairHelper);
});
it("updateItemDurability() repairkit with slick armor with max dura degredation", () =>
{
const slickTpl = "5e4abb5086f77406975c9342";
const itemToRepair: Item = {
_id: "12345",
_tpl: slickTpl,
upd: {
Repairable: {
Durability: 60,
MaxDurability: 80
}
}
};
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[slickTpl];
const isArmor = true;
const useRepairKit = true;
const useDegridation = true;
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, 5, useRepairKit, 1, useDegridation);
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(80);
});
it("updateItemDurability() trader with slick armor with max dura degredation - partial repair", () =>
{
const slickTpl = "5e4abb5086f77406975c9342";
const itemToRepair: Item = {
_id: "12345",
_tpl: slickTpl,
upd: {
Repairable: {
Durability: 60,
MaxDurability: 80
}
}
};
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[slickTpl];
const isArmor = true;
const useRepairKit = false;
const useDegridation = true;
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, 5, useRepairKit, 1.2, useDegridation);
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(80);
expect(itemToRepair.upd?.Repairable?.Durability).toBeGreaterThan(60);
});
it("updateItemDurability() trader with slick armor, no dura degredation", () =>
{
const slickTpl = "5e4abb5086f77406975c9342";
const itemToRepair: Item = {
_id: "12345",
_tpl: slickTpl,
upd: {
Repairable: {
Durability: 60,
MaxDurability: 80
}
}
};
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[slickTpl];
const isArmor = true;
const useRepairKit = false;
const useDegridation = false;
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, 20, useRepairKit, 1.2, useDegridation);
expect(itemToRepair.upd?.Repairable?.Durability).toBe(80);
expect(itemToRepair.upd?.Repairable?.Durability).toBe(itemToRepair.upd?.Repairable?.MaxDurability);
});
it("updateItemDurability() repairkit with g36 with max dura degredation - Full repair", () =>
{
const itemCurrentDura = 68;
const itemCurrentMaxDura = 100;
const duraDifference = itemCurrentMaxDura - itemCurrentDura;
const g36Tpl = "623063e994fc3f7b302a9696";
const itemToRepair: Item = {
_id: "12345",
_tpl: g36Tpl,
upd: {
Repairable: {
Durability: itemCurrentDura,
MaxDurability: itemCurrentMaxDura
}
}
};
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[g36Tpl];
const isArmor = false;
const useRepairKit = true;
const useDegridation = true;
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, duraDifference, useRepairKit, 1, useDegridation);
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(100);
expect(itemToRepair.upd?.Repairable?.Durability).toBe(itemToRepair.upd?.Repairable?.MaxDurability);
});
it("updateItemDurability() trader with g36 with max dura degredation - Full repair", () =>
{
const itemCurrentDura = 68;
const itemCurrentMaxDura = 100;
const duraDifference = itemCurrentMaxDura - itemCurrentDura;
const g36Tpl = "623063e994fc3f7b302a9696";
const itemToRepair: Item = {
_id: "12345",
_tpl: g36Tpl,
upd: {
Repairable: {
Durability: itemCurrentDura,
MaxDurability: itemCurrentMaxDura
}
}
};
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[g36Tpl];
const isArmor = false;
const useRepairKit = false;
const useDegridation = true;
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, duraDifference, useRepairKit, 1.2, useDegridation);
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(100);
expect(itemToRepair.upd?.Repairable?.Durability).toBe(itemToRepair.upd?.Repairable?.MaxDurability);
});
it("updateItemDurability() faceshield broken use repairkit with max dura degredation", () =>
{
const twExfilBallisticFaceShieldTpl = "5e00cdd986f7747473332240";
const itemToRepair: Item = {
_id: "12345",
_tpl: twExfilBallisticFaceShieldTpl,
upd: {
Repairable: {
Durability: 30,
MaxDurability: 45
},
FaceShield: {
Hits: 2
}
}
};
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[twExfilBallisticFaceShieldTpl];
const isArmor = true;
const useRepairKit = true;
const useDegridation = true;
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, 5, useRepairKit, 1, useDegridation);
expect(itemToRepair.upd?.FaceShield?.Hits).toBe(0);
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(45);
expect(itemToRepair.upd?.Repairable?.Durability).toBe(itemToRepair.upd?.Repairable?.MaxDurability);
});
it("isWeaponTemplate() g36 weapon", () =>
{
const result = helper.isWeaponTemplate("623063e994fc3f7b302a9696");
expect(result).toBe(true);
});
it("isWeaponTemplate() slick armor", () =>
{
const result = helper.isWeaponTemplate("5e4abb5086f77406975c9342");
expect(result).toBe(false);
});
});