ed8dbbd195
Boogidy, boogidy, boogidy. Let's go racing! 🏎️ Removes the over-complicated and super-slow setup we had with ESLint & Prettier in favour of Biome. The largest change with the formatting is moving from Allman braces to 1TBS braces. Other than that, it's *pretty much* the same. Ah, and that Biome runs formatting and linting on the entire project about x10 faster than the old system ran formatting on one file. Seriously, the guy who came up with that last solution should be fired. :runs: I've kept all of the formatting and linting commands the same as before, with the main mamma-jamma being: `npm run format`, which applies formatting and linting changes to the entire project. Formatting-on-save works (quickly!) by (1) ensuring that you're working within the VSC workspace (as you should be), and (2) have the recommended Biome VSC extension installed. The link to the Biome extension is in the README. This limits our options on code formatting going forward; Biome, like prettier, is very opinionated with very few formatting options available. But I see this as a good thing. I'd rather spend my time arguing about which gun in Tarkov is the best, rather than coding brace styles... ...It's the TOZ, and it always will be. Don't DM me. Co-authored-by: chomp <chomp@noreply.dev.sp-tarkov.com> Reviewed-on: https://dev.sp-tarkov.com/SPT/Server/pulls/383 Co-authored-by: Refringe <me@refringe.com> Co-committed-by: Refringe <me@refringe.com>
192 lines
7.1 KiB
TypeScript
192 lines
7.1 KiB
TypeScript
import "reflect-metadata";
|
|
|
|
import { container } from "tsyringe";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { HealthController } from "@spt/controllers/HealthController";
|
|
import { IPmcData } from "@spt/models/eft/common/IPmcData";
|
|
import { IHealthTreatmentRequestData } from "@spt/models/eft/health/IHealthTreatmentRequestData";
|
|
|
|
describe("HealthController", () =>
|
|
{
|
|
let healthController: HealthController; // Using "any" to access private/protected methods without type errors.
|
|
|
|
beforeEach(() =>
|
|
{
|
|
healthController = container.resolve<HealthController>("HealthController");
|
|
});
|
|
|
|
afterEach(() =>
|
|
{
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe("healthTreatment", () =>
|
|
{
|
|
it("Should Heal Players heavy bleed and heal chest to full hp", () =>
|
|
{
|
|
const maxHealth = 100;
|
|
const pmcData = {
|
|
Health: {
|
|
BodyParts: {
|
|
Chest: {
|
|
Health: {
|
|
Current: 50, // Has damage
|
|
Maximum: maxHealth,
|
|
},
|
|
Effects: { HeavyBleeding: { Time: 20 } },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
const bleedRemovalAndLimbHealRequest = {
|
|
Action: "RestoreHealth",
|
|
trader: "54cb57776803fa99248b456e", // Therapist
|
|
difference: {
|
|
BodyParts: {
|
|
Chest: {
|
|
Health: 23, // > 0 value means it will heal
|
|
Effects: ["HeavyBleeding"], // non-null means it will remove effect from player
|
|
},
|
|
},
|
|
},
|
|
};
|
|
const sessionId = "12345";
|
|
|
|
// Mock output generation
|
|
vi.spyOn((healthController as any).eventOutputHolder, "getOutput").mockReturnValue({
|
|
warnings: {},
|
|
profileChanges: { 12345: { health: {} } },
|
|
});
|
|
|
|
// Mock payment
|
|
vi.spyOn((healthController as any).paymentService, "payMoney").mockReturnValue({
|
|
warnings: {},
|
|
profileChanges: { 12345: { health: {} } },
|
|
});
|
|
|
|
const result = healthController.healthTreatment(
|
|
pmcData as unknown as IPmcData,
|
|
bleedRemovalAndLimbHealRequest as IHealthTreatmentRequestData,
|
|
sessionId,
|
|
);
|
|
|
|
// Has healed chest to full
|
|
expect(result.profileChanges[sessionId].health.BodyParts.Chest.Health.Current).equals(maxHealth);
|
|
|
|
// Has removed Heavy bleed effect from chest
|
|
expect(result.profileChanges[sessionId].health.BodyParts.Chest).not.toHaveProperty("Effects");
|
|
});
|
|
|
|
it("Should Heal Players heavy bleed and leave limb health at existing value", () =>
|
|
{
|
|
const maxHealth = 100;
|
|
const pmcData = {
|
|
Health: {
|
|
BodyParts: {
|
|
Chest: {
|
|
Health: {
|
|
Current: 50, // Has damage
|
|
Maximum: maxHealth,
|
|
},
|
|
Effects: { HeavyBleeding: { Time: 20 } },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
const limbOnlyHealRequest = {
|
|
Action: "RestoreHealth",
|
|
trader: "54cb57776803fa99248b456e", // Therapist
|
|
difference: {
|
|
BodyParts: {
|
|
Chest: {
|
|
Health: 23, // > 0 value means it will heal limb to full
|
|
Effects: null, // null means no healing of effects
|
|
},
|
|
},
|
|
},
|
|
};
|
|
const sessionId = "12345";
|
|
|
|
// Mock output generation
|
|
vi.spyOn((healthController as any).eventOutputHolder, "getOutput").mockReturnValue({
|
|
warnings: {},
|
|
profileChanges: { 12345: { health: {} } },
|
|
});
|
|
|
|
// Mock payment
|
|
vi.spyOn((healthController as any).paymentService, "payMoney").mockReturnValue({
|
|
warnings: {},
|
|
profileChanges: { 12345: { health: {} } },
|
|
});
|
|
|
|
const result = healthController.healthTreatment(
|
|
pmcData as unknown as IPmcData,
|
|
limbOnlyHealRequest as IHealthTreatmentRequestData,
|
|
sessionId,
|
|
);
|
|
|
|
// Has healed chest to full
|
|
expect(result.profileChanges[sessionId].health.BodyParts.Chest.Health.Current).equals(maxHealth);
|
|
|
|
// Has not removed Heavy bleed effect from chest
|
|
expect(result.profileChanges[sessionId].health.BodyParts.Chest).toHaveProperty("Effects");
|
|
});
|
|
|
|
it("Should Heal Players heavy bleed and leave limb health at existing value", () =>
|
|
{
|
|
const maxHealth = 100;
|
|
const currentHealth = 50;
|
|
const pmcData = {
|
|
Health: {
|
|
BodyParts: {
|
|
Chest: {
|
|
Health: {
|
|
Current: currentHealth, // Has damage
|
|
Maximum: maxHealth,
|
|
},
|
|
Effects: { HeavyBleeding: { Time: 20 } },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
const limbOnlyHealRequest = {
|
|
Action: "RestoreHealth",
|
|
trader: "54cb57776803fa99248b456e", // Therapist
|
|
difference: {
|
|
BodyParts: {
|
|
Chest: {
|
|
Health: 0, // 0 value means it will not heal and damage
|
|
Effects: null, // null means no healing of effects
|
|
},
|
|
},
|
|
},
|
|
};
|
|
const sessionId = "12345";
|
|
|
|
// Mock output generation
|
|
vi.spyOn((healthController as any).eventOutputHolder, "getOutput").mockReturnValue({
|
|
warnings: {},
|
|
profileChanges: { 12345: { health: {} } },
|
|
});
|
|
|
|
// Mock payment
|
|
vi.spyOn((healthController as any).paymentService, "payMoney").mockReturnValue({
|
|
warnings: {},
|
|
profileChanges: { 12345: { health: {} } },
|
|
});
|
|
|
|
const result = healthController.healthTreatment(
|
|
pmcData as unknown as IPmcData,
|
|
limbOnlyHealRequest as IHealthTreatmentRequestData,
|
|
sessionId,
|
|
);
|
|
|
|
// Has not healed chest to full
|
|
expect(result.profileChanges[sessionId].health.BodyParts.Chest.Health.Current).equals(currentHealth);
|
|
|
|
// Has not removed Heavy bleed effect from chest
|
|
expect(result.profileChanges[sessionId].health.BodyParts.Chest).toHaveProperty("Effects");
|
|
});
|
|
});
|
|
});
|