0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-12 22:30:43 -05:00

Additional InsuranceController Tests

- Adds tests for the remaining methods in the `InsuranceController`.
- Adds a `countAllInsuranceItems()` method to the `InsuranceController`.
- Adds the Vitest UI and coverage packages.
- Updates the `profileInsuranceFactory` to use second-epoch dates instead of millisecond-epoch dates.
- Updates the `InsuranceController.fetchHideoutItemParent()` method to log a warning when an item with a slotId of 'hideout' cannot be found.

TODO:
- The Vitest coverage options are not working.
This commit is contained in:
Refringe 2023-11-03 17:39:33 -04:00
parent e327df7504
commit 047884e9c7
No known key found for this signature in database
GPG Key ID: 64E03E5F892C6F9E
5 changed files with 814 additions and 199 deletions

View File

@ -17,6 +17,7 @@
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
"test:ui": "vitest --ui",
"build:release": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:release",
"build:debug": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:debug",
"build:bleeding": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:bleeding",
@ -55,6 +56,8 @@
"@types/ws": "8.5.7",
"@typescript-eslint/eslint-plugin": "6.7.5",
"@typescript-eslint/parser": "6.7.5",
"@vitest/coverage-v8": "1.0.0-beta.3",
"@vitest/ui": "1.0.0-beta.3",
"c8": "^8.0.1",
"cross-env": "7.0.3",
"date-fns": "^2.30.0",

View File

@ -114,7 +114,7 @@ export class InsuranceController
*/
protected processInsuredItems(insuranceDetails: Insurance[], sessionID: string): void
{
this.logger.debug(`Processing ${insuranceDetails.length} insurance packages, which includes a total of ${insuranceDetails.map(ins => ins.items.length).reduce((acc, len) => acc + len, 0)} items, in profile ${sessionID}`);
this.logger.debug(`Processing ${insuranceDetails.length} insurance packages, which includes a total of ${this.countAllInsuranceItems(insuranceDetails)} items, in profile ${sessionID}`);
// Iterate over each of the insurance packages.
insuranceDetails.forEach(insured =>
@ -136,6 +136,16 @@ export class InsuranceController
});
}
/**
* Count all items in all insurance packages.
* @param insurance
* @returns
*/
protected countAllInsuranceItems(insurance: Insurance[]): number
{
return insurance.map(ins => ins.items.length).reduce((acc, len) => acc + len, 0);
}
/**
* Remove an insurance package from a profile using the package's system data information.
*
@ -460,7 +470,14 @@ export class InsuranceController
protected fetchHideoutItemParent(items: Item[]): string
{
const hideoutItem = items.find(item => item.slotId === "hideout");
return hideoutItem ? hideoutItem?.parentId : "";
const hideoutParentId = hideoutItem ? hideoutItem?.parentId : "";
if (hideoutParentId === "")
{
this.logger.warning("Unable to find an item with slotId 'hideout' in the insured item package.");
}
return hideoutParentId;
}
/**

View File

@ -30,7 +30,8 @@ export class ProfileInsuranceFactory
{
this.profileInsuranceFixture = this.profileInsuranceFixture.map((insurance, index) =>
{
const defaultDate = Date.now() - 3600000; // One hour ago.
// 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")

File diff suppressed because it is too large Load Diff

View File

@ -5,9 +5,18 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
name: "spt-server",
api: 51204,
reporters: ["default"],
root: "./tests",
cache: false,
environment: "./CustomEnvironment.ts",
globals: true,
coverage: {
enabled: true,
provider: "v8",
reporter: ["text", "html"],
reportsDirectory: "./__coverage__"
},
typecheck: {
enabled: true
},