0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:10:43 -05:00
server/project/tests/__factories__/ProfileInsurance.factory.ts
Refringe 0368a230fb
BunJS Runtime, Updated Build System, and... (#992)
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.
2024-12-21 22:46:39 +00:00

81 lines
2.7 KiB
TypeScript

import "reflect-metadata";
import type { ItemHelper } from "@spt/helpers/ItemHelper";
import type { IInsurance } from "@spt/models/eft/profile/ISptProfile";
import { profileInsuranceFixture } from "@tests/__fixture__/profileInsurance.fixture";
import { format } from "date-fns";
import { container } from "tsyringe";
type DateInput = number | number[] | { [index: number]: number };
export class ProfileInsuranceFactory {
private profileInsuranceFixture: IInsurance[];
constructor() {
this.init();
}
public init(): this {
this.profileInsuranceFixture = JSON.parse(JSON.stringify(profileInsuranceFixture)); // Deep clone.
return this;
}
/**
* Adjusts the scheduledTime, messageContent.systemData.date, and messageContent.systemData.time, otherwise the
* dates in the original fixture will likely be expired.
*/
public adjustPackageDates(dateInput?: DateInput): this {
this.profileInsuranceFixture = this.profileInsuranceFixture.map((insurance, index) => {
// Default to 1 hour ago.
const defaultDate = Math.floor(Date.now() / 1000 - 1 * 60 * 60);
let date: number;
if (Array.isArray(dateInput) || typeof dateInput === "object") {
date = dateInput[index] || defaultDate;
} else {
date = dateInput || defaultDate;
}
insurance.scheduledTime = date;
insurance.systemData.date = format(date, "MM.dd.yyyy");
insurance.systemData.time = format(date, "HH:mm");
return insurance;
});
return this;
}
/**
* Removes all attachment items that are currently attached to their parent, leaving the "normal" base items.
*/
public removeAttachmentItems(): this {
const itemHelper = container.resolve<ItemHelper>("ItemHelper");
this.profileInsuranceFixture = this.profileInsuranceFixture.map((insurance) => {
insurance.items = insurance.items.filter((item) => !itemHelper.isAttachmentAttached(item));
return insurance;
});
return this;
}
/**
* Removes all normal base items leaving only attachment items that are currently attached to their parent.
* This *will* cause orphaned attachments.
*/
public removeRegularItems(): this {
const itemHelper = container.resolve<ItemHelper>("ItemHelper");
this.profileInsuranceFixture = this.profileInsuranceFixture.map((insurance) => {
insurance.items = insurance.items.filter((item) => itemHelper.isAttachmentAttached(item));
return insurance;
});
return this;
}
public get(): IInsurance[] {
return this.profileInsuranceFixture;
}
}