This commit is contained in:
1 parent
8efd032cc6
commit
df38dccbf1
735 files changed
+128321
-120870
No files matched your search
@@ -3,63 +3,88 @@ import { describe, expect, it, vi } from "vitest";
|
||||
const mergeSet = vi.fn(async () => {});
|
||||
const mergePalette = vi.fn(async () => {});
|
||||
const mergeLibrary = vi.fn(async () => {});
|
||||
const importSingleFigure = vi.fn(async () => ({ ok: true, lib: "", warnings: [] }));
|
||||
const importSingleFigure = vi.fn(async () => ({
|
||||
ok: true,
|
||||
lib: "",
|
||||
warnings: [],
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/services/figure-official", () => ({
|
||||
fetchOfficialFigureData: vi.fn(async () => ({
|
||||
palettes: [{ id: 3, colors: [] }],
|
||||
setTypes: [
|
||||
{
|
||||
type: "ch",
|
||||
paletteId: 3,
|
||||
sets: [
|
||||
{
|
||||
id: 5000,
|
||||
gender: "M",
|
||||
club: 0,
|
||||
colorable: true,
|
||||
selectable: true,
|
||||
preselectable: false,
|
||||
sellable: true,
|
||||
parts: [{ id: 4316, type: "ch", colorable: true, index: 0, colorindex: 1 }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})),
|
||||
fetchOfficialFigureMap: vi.fn(async () => [
|
||||
{ id: "shirt_M_x", revision: 1, parts: [{ id: 4316, type: "ch" }] },
|
||||
]),
|
||||
fetchOfficialFigureData: vi.fn(async () => ({
|
||||
palettes: [{ id: 3, colors: [] }],
|
||||
setTypes: [
|
||||
{
|
||||
type: "ch",
|
||||
paletteId: 3,
|
||||
sets: [
|
||||
{
|
||||
id: 5000,
|
||||
gender: "M",
|
||||
club: 0,
|
||||
colorable: true,
|
||||
selectable: true,
|
||||
preselectable: false,
|
||||
sellable: true,
|
||||
parts: [
|
||||
{
|
||||
id: 4316,
|
||||
type: "ch",
|
||||
colorable: true,
|
||||
index: 0,
|
||||
colorindex: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})),
|
||||
fetchOfficialFigureMap: vi.fn(async () => [
|
||||
{ id: "shirt_M_x", revision: 1, parts: [{ id: 4316, type: "ch" }] },
|
||||
]),
|
||||
}));
|
||||
vi.mock("@/lib/services/figuredata", () => ({
|
||||
mergeSet: (...a: unknown[]) => mergeSet(...(a as Parameters<typeof mergeSet>)),
|
||||
mergePalette: (...a: unknown[]) => mergePalette(...(a as Parameters<typeof mergePalette>)),
|
||||
listLocalSetIds: vi.fn(async () => new Set<number>()),
|
||||
mergeSet: (...a: unknown[]) =>
|
||||
mergeSet(...(a as Parameters<typeof mergeSet>)),
|
||||
mergePalette: (...a: unknown[]) =>
|
||||
mergePalette(...(a as Parameters<typeof mergePalette>)),
|
||||
listLocalSetIds: vi.fn(async () => new Set<number>()),
|
||||
}));
|
||||
vi.mock("@/lib/services/figuremap", () => ({
|
||||
mergeLibrary: (...a: unknown[]) => mergeLibrary(...(a as Parameters<typeof mergeLibrary>)),
|
||||
listFigureLibraries: vi.fn(async () => []),
|
||||
mergeLibrary: (...a: unknown[]) =>
|
||||
mergeLibrary(...(a as Parameters<typeof mergeLibrary>)),
|
||||
listFigureLibraries: vi.fn(async () => []),
|
||||
}));
|
||||
vi.mock("@/lib/services/figure-import", () => ({
|
||||
importSingleFigure: (...a: unknown[]) =>
|
||||
importSingleFigure(...(a as Parameters<typeof importSingleFigure>)),
|
||||
ensureFigureDirs: vi.fn(async () => {}),
|
||||
importSingleFigure: (...a: unknown[]) =>
|
||||
importSingleFigure(...(a as Parameters<typeof importSingleFigure>)),
|
||||
ensureFigureDirs: vi.fn(async () => {}),
|
||||
}));
|
||||
|
||||
import { importClothingSet } from "./clothing-set-import";
|
||||
|
||||
describe("importClothingSet", () => {
|
||||
it("imports the libraries for the set parts, then merges set + palette", async () => {
|
||||
const r = await importClothingSet({ setType: "ch", setId: 5000 });
|
||||
expect(r.ok).toBe(true);
|
||||
expect(importSingleFigure).toHaveBeenCalledWith(expect.objectContaining({ lib: "shirt_M_x" }));
|
||||
expect(mergeLibrary).toHaveBeenCalledWith(expect.objectContaining({ id: "shirt_M_x" }));
|
||||
expect(mergeSet).toHaveBeenCalledWith("ch", 3, expect.objectContaining({ id: 5000 }));
|
||||
expect(mergePalette).toHaveBeenCalledWith(expect.objectContaining({ id: 3 }));
|
||||
});
|
||||
it("imports the libraries for the set parts, then merges set + palette", async () => {
|
||||
const r = await importClothingSet({ setType: "ch", setId: 5000 });
|
||||
expect(r.ok).toBe(true);
|
||||
expect(importSingleFigure).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ lib: "shirt_M_x" }),
|
||||
);
|
||||
expect(mergeLibrary).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: "shirt_M_x" }),
|
||||
);
|
||||
expect(mergeSet).toHaveBeenCalledWith(
|
||||
"ch",
|
||||
3,
|
||||
expect.objectContaining({ id: 5000 }),
|
||||
);
|
||||
expect(mergePalette).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: 3 }),
|
||||
);
|
||||
});
|
||||
|
||||
it("fails when the set is not in official figuredata", async () => {
|
||||
const r = await importClothingSet({ setType: "ch", setId: 999999 });
|
||||
expect(r.ok).toBe(false);
|
||||
});
|
||||
it("fails when the set is not in official figuredata", async () => {
|
||||
const r = await importClothingSet({ setType: "ch", setId: 999999 });
|
||||
expect(r.ok).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user