85a227e7d5
- Created profileInsurance test fixture.
- Created ProfileInsurance test factory class.
- Improved many of the InsuranceController method tests by utilizing the factory and fixture. Still some left to do here.
- Adds the `date-fns` package as a development dependancy for easy date manipulation.
- Cleaned up some comments.
Bug Fixes 🐞
- Resolved an issue where `ItemHelper.getAttachmentMainParent()` was not returning null when it should have.
- Resolved an issue where `InsuranceController.populateParentAttachmentsMap()` would continue to process when the parent could not be found.
93 lines
2.8 KiB
TypeScript
93 lines
2.8 KiB
TypeScript
import "reflect-metadata";
|
|
import { container } from "tsyringe";
|
|
import { format } from "date-fns";
|
|
import { profileInsuranceFixture } from "@tests/__fixture__/profileInsurance.fixture";
|
|
import { Insurance } from "@spt-aki/models/eft/profile/IAkiProfile";
|
|
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
|
|
|
type DateInput = number | number[] | { [index: number]: number };
|
|
|
|
export class ProfileInsuranceFactory
|
|
{
|
|
private profileInsuranceFixture: Insurance[];
|
|
|
|
constructor()
|
|
{
|
|
this.init();
|
|
}
|
|
|
|
public init(): this
|
|
{
|
|
this.profileInsuranceFixture = JSON.parse(JSON.stringify(profileInsuranceFixture)); // Deep clone.
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Adjusts the scheduledTime and 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) =>
|
|
{
|
|
const defaultDate = Date.now() - 3600000; // One hour ago.
|
|
|
|
let date: number;
|
|
if (Array.isArray(dateInput) || typeof dateInput === "object")
|
|
{
|
|
date = dateInput[index] || defaultDate;
|
|
}
|
|
else
|
|
{
|
|
date = dateInput || defaultDate;
|
|
}
|
|
|
|
insurance.scheduledTime = date;
|
|
insurance.messageContent.systemData.date = format(date, "MM.dd.yyyy");
|
|
insurance.messageContent.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(): Insurance[]
|
|
{
|
|
return this.profileInsuranceFixture;
|
|
}
|
|
}
|