mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:50:43 -05:00
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.
185 lines
7.1 KiB
TypeScript
185 lines
7.1 KiB
TypeScript
import "reflect-metadata";
|
|
|
|
import { HealthController } from "@spt/controllers/HealthController";
|
|
import type { IPmcData } from "@spt/models/eft/common/IPmcData";
|
|
import type { IHealthTreatmentRequestData } from "@spt/models/eft/health/IHealthTreatmentRequestData";
|
|
import { container } from "tsyringe";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
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");
|
|
});
|
|
});
|
|
});
|