75 lines
3.1 KiB
TypeScript
75 lines
3.1 KiB
TypeScript
import { content } from "@deadhead/content";
|
|
import { describe, expect, it } from "vitest";
|
|
import { completedGoals, type GoalProgress } from "../src/index";
|
|
|
|
const goals = content.onboardingGoals;
|
|
|
|
/** Just after the deal: the Courier and the Clipper, an Earth bay and the full loan (CR-013). */
|
|
const fresh: GoalProgress = {
|
|
ownShipDeliveries: 0,
|
|
skillPointsSpent: 0,
|
|
shipsOwned: 2,
|
|
marketShipsBought: 0,
|
|
pilotsHired: 1,
|
|
priorityDeliveries: 0,
|
|
locationsDiscovered: 0,
|
|
dealAccepted: true,
|
|
loanBalance: content.dealLoanAmount,
|
|
};
|
|
|
|
const isComplete = (id: string, progress: GoalProgress) =>
|
|
completedGoals(goals, progress).includes(id);
|
|
|
|
/** For each goal: a summary just short of its condition, and one that meets it. */
|
|
const cases: [string, Partial<GoalProgress>, Partial<GoalProgress>][] = [
|
|
["first-own-delivery", { ownShipDeliveries: 0 }, { ownShipDeliveries: 1 }],
|
|
["first-skill-point", { skillPointsSpent: 0 }, { skillPointsSpent: 1 }],
|
|
["market-ship", { marketShipsBought: 0 }, { marketShipsBought: 1, shipsOwned: 3 }],
|
|
["priority-contract", { priorityDeliveries: 0 }, { priorityDeliveries: 1 }],
|
|
["first-discovery", { locationsDiscovered: 0 }, { locationsDiscovered: 1 }],
|
|
["loan-paid-off", { loanBalance: 1 }, { loanBalance: 0 }],
|
|
];
|
|
|
|
describe("onboarding goal evaluation", () => {
|
|
it("covers every goal in content, in order", () => {
|
|
expect(cases.map(([id]) => id)).toEqual(goals.map((g) => g.id));
|
|
});
|
|
|
|
it.each(cases)(
|
|
"%s: incomplete just short of the condition, complete once met",
|
|
(id, short, met) => {
|
|
expect(isComplete(id, { ...fresh, ...short })).toBe(false);
|
|
expect(isComplete(id, { ...fresh, ...met })).toBe(true);
|
|
},
|
|
);
|
|
|
|
it("doesn't count the deal's two ships as a Market purchase; a bought Lighter does (CR-013)", () => {
|
|
expect(isComplete("market-ship", fresh)).toBe(false);
|
|
expect(goals.find((g) => g.id === "market-ship")?.title).toBe("Buy a ship from the Market");
|
|
// After buying a Lighter: three ships, one of them from the Market.
|
|
expect(isComplete("market-ship", { ...fresh, shipsOwned: 3, marketShipsBought: 1 })).toBe(true);
|
|
});
|
|
|
|
it("needs a Priority delivery, not just any deliveries (CR-013)", () => {
|
|
expect(isComplete("priority-contract", { ...fresh, ownShipDeliveries: 12 })).toBe(false);
|
|
expect(
|
|
isComplete("priority-contract", { ...fresh, ownShipDeliveries: 1, priorityDeliveries: 1 }),
|
|
).toBe(true);
|
|
expect(goals.find((g) => g.id === "priority-contract")?.title).toBe(
|
|
"Complete a Priority contract",
|
|
);
|
|
});
|
|
|
|
it("does not count a loan as paid off before the deal", () => {
|
|
expect(isComplete("loan-paid-off", { ...fresh, dealAccepted: false, loanBalance: 0 })).toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
it("returns completed goals in content order, identically for identical inputs", () => {
|
|
const progress: GoalProgress = { ...fresh, priorityDeliveries: 3, ownShipDeliveries: 5 };
|
|
expect(completedGoals(goals, progress)).toEqual(["first-own-delivery", "priority-contract"]);
|
|
expect(completedGoals(goals, progress)).toEqual(completedGoals(goals, { ...progress }));
|
|
});
|
|
});
|