mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 05: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:
parent
e327df7504
commit
047884e9c7
@ -17,6 +17,7 @@
|
|||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"test:watch": "vitest",
|
"test:watch": "vitest",
|
||||||
"test:coverage": "vitest run --coverage",
|
"test:coverage": "vitest run --coverage",
|
||||||
|
"test:ui": "vitest --ui",
|
||||||
"build:release": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:release",
|
"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:debug": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:debug",
|
||||||
"build:bleeding": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:bleeding",
|
"build:bleeding": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:bleeding",
|
||||||
@ -55,6 +56,8 @@
|
|||||||
"@types/ws": "8.5.7",
|
"@types/ws": "8.5.7",
|
||||||
"@typescript-eslint/eslint-plugin": "6.7.5",
|
"@typescript-eslint/eslint-plugin": "6.7.5",
|
||||||
"@typescript-eslint/parser": "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",
|
"c8": "^8.0.1",
|
||||||
"cross-env": "7.0.3",
|
"cross-env": "7.0.3",
|
||||||
"date-fns": "^2.30.0",
|
"date-fns": "^2.30.0",
|
||||||
|
@ -114,7 +114,7 @@ export class InsuranceController
|
|||||||
*/
|
*/
|
||||||
protected processInsuredItems(insuranceDetails: Insurance[], sessionID: string): void
|
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.
|
// Iterate over each of the insurance packages.
|
||||||
insuranceDetails.forEach(insured =>
|
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.
|
* 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
|
protected fetchHideoutItemParent(items: Item[]): string
|
||||||
{
|
{
|
||||||
const hideoutItem = items.find(item => item.slotId === "hideout");
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +30,8 @@ export class ProfileInsuranceFactory
|
|||||||
{
|
{
|
||||||
this.profileInsuranceFixture = this.profileInsuranceFixture.map((insurance, index) =>
|
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;
|
let date: number;
|
||||||
if (Array.isArray(dateInput) || typeof dateInput === "object")
|
if (Array.isArray(dateInput) || typeof dateInput === "object")
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -5,9 +5,18 @@ import { defineConfig } from "vitest/config";
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
test: {
|
test: {
|
||||||
name: "spt-server",
|
name: "spt-server",
|
||||||
|
api: 51204,
|
||||||
|
reporters: ["default"],
|
||||||
root: "./tests",
|
root: "./tests",
|
||||||
|
cache: false,
|
||||||
environment: "./CustomEnvironment.ts",
|
environment: "./CustomEnvironment.ts",
|
||||||
globals: true,
|
globals: true,
|
||||||
|
coverage: {
|
||||||
|
enabled: true,
|
||||||
|
provider: "v8",
|
||||||
|
reporter: ["text", "html"],
|
||||||
|
reportsDirectory: "./__coverage__"
|
||||||
|
},
|
||||||
typecheck: {
|
typecheck: {
|
||||||
enabled: true
|
enabled: true
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user