Merge branch '3.8.1-DEV' of https://dev.sp-tarkov.com/SPT-AKI/Server into 3.8.1-DEV
This commit is contained in:
commit
fc6d84ad7d
@ -157,6 +157,7 @@ export class ProfileFixerService
|
||||
}
|
||||
|
||||
this.fixNullTraderSalesSums(pmcProfile);
|
||||
this.fixNullTraderNextResupply(pmcProfile);
|
||||
this.updateProfileQuestDataValues(pmcProfile);
|
||||
}
|
||||
|
||||
@ -1430,4 +1431,20 @@ export class ProfileFixerService
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If someone has run a mod from pre-3.8.0, it results in an invalid `nextResupply` value
|
||||
* Resolve this by setting the nextResupply to 0 if it's null
|
||||
*/
|
||||
protected fixNullTraderNextResupply(pmcProfile: IPmcData): void
|
||||
{
|
||||
for (const [traderId, trader] of Object.entries(pmcProfile.TradersInfo))
|
||||
{
|
||||
if (trader && trader.nextResupply === null)
|
||||
{
|
||||
this.logger.warning(`trader ${traderId} has a null nextResupply value, resetting to 0`);
|
||||
trader.nextResupply = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
39
project/tests/services/ProfileFixerService.test.ts
Normal file
39
project/tests/services/ProfileFixerService.test.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { ProfileFixerService } from "@spt-aki/services/ProfileFixerService";
|
||||
import { container } from "tsyringe";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
describe("ProfileFixerService", () =>
|
||||
{
|
||||
let profileFixerService: any; // Using "any" to access private/protected methods without type errors.
|
||||
|
||||
beforeEach(() =>
|
||||
{
|
||||
profileFixerService = container.resolve<ProfileFixerService>("ProfileFixerService");
|
||||
});
|
||||
|
||||
afterEach(() =>
|
||||
{
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("FixPmcProfileIssues", () =>
|
||||
{
|
||||
it("should reset nextResupply to 0 when it is null", () =>
|
||||
{
|
||||
const pmcProfile = { TradersInfo: { traderId: { nextResupply: null } } };
|
||||
|
||||
profileFixerService.fixNullTraderNextResupply(pmcProfile);
|
||||
|
||||
expect(pmcProfile.TradersInfo.traderId.nextResupply).toBe(0);
|
||||
});
|
||||
|
||||
it("should not reset nextResupply to 0 when it is not null", () =>
|
||||
{
|
||||
const pmcProfile = { TradersInfo: { traderId: { nextResupply: 1234 } } };
|
||||
|
||||
profileFixerService.fixNullTraderNextResupply(pmcProfile);
|
||||
|
||||
expect(pmcProfile.TradersInfo.traderId.nextResupply).toBe(1234);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user