30 lines
2.0 KiB
TypeScript
30 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { commissionRequestIssues } from "./request-validation";
|
|
import type { CommissionRequest } from "./request";
|
|
|
|
const member = (key: string) => ({ characterKey: key, weaponKey: "weapon", artifactKey: "artifact", constellation: "0", refinement: "1" } as const);
|
|
|
|
describe("commission request feedback", () => {
|
|
it("identifies missing custom stats in each comparison", () => {
|
|
const issues = commissionRequestIssues({ teams: [],
|
|
weapons: [{ characterKey: "a", weaponKeys: ["one", "two"], customStats: "" }],
|
|
constellations: [{ characterKey: "a", levels: [0], customStats: " " }],
|
|
});
|
|
expect(issues.map((issue) => issue.path)).toEqual(["weapons.0.customStats", "constellations.0.customStats"]);
|
|
expect(issues.every((issue) => issue.message.includes("ค่าสเตตัส"))).toBe(true);
|
|
});
|
|
it("identifies each missing selection so errors can appear beside their pickers", () => {
|
|
const request: CommissionRequest = { teams: [{ members: [member("a"), member("b"), { ...member("c"), weaponKey: "", artifactKey: "" }, member("d")] }], weapons: [], constellations: [] };
|
|
expect(commissionRequestIssues(request)).toEqual([
|
|
{ path: "teams.0.members.2.weaponKey", message: "ทีม 1: เลือกอาวุธให้ตัวละครที่ 3" },
|
|
{ path: "teams.0.members.2.artifactKey", message: "ทีม 1: เลือกอาร์ติแฟกต์ให้ตัวละครที่ 3" },
|
|
]);
|
|
});
|
|
it("reports duplicate characters at their team rather than at an unrelated picker", () => {
|
|
expect(commissionRequestIssues({ teams: [{ members: [member("a"), member("a"), member("c"), member("d")] }], weapons: [], constellations: [] })[0].path).toBe("teams.0");
|
|
});
|
|
it("accepts a valid comparison without requiring a team", () => {
|
|
expect(commissionRequestIssues({ teams: [], weapons: [{ characterKey: "a", weaponKeys: ["one", "two"] }], constellations: [] })).toEqual([]);
|
|
});
|
|
});
|