fix: map furni imports to production gamedata
This commit is contained in:
1 parent
a81af2d71a
commit
01570874a8
6 files changed
+224
-15
No files matched your search
@@ -0,0 +1,63 @@
|
||||
// @vitest-environment node
|
||||
import { promises as fs } from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { getGamedataRootMock, getNitroFilesRootMock, settingGetMock } =
|
||||
vi.hoisted(() => ({
|
||||
getGamedataRootMock: vi.fn(),
|
||||
getNitroFilesRootMock: vi.fn(),
|
||||
settingGetMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/services/furni-asset-dirs", () => ({
|
||||
getGamedataRoot: getGamedataRootMock,
|
||||
getNitroFilesRoot: getNitroFilesRootMock,
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/services/site-settings", () => ({
|
||||
siteSettings: { get: settingGetMock },
|
||||
}));
|
||||
|
||||
import { writeFurniData } from "./furni-data";
|
||||
|
||||
describe("writeFurniData production mirror", () => {
|
||||
let tempDir: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "furni-data-paths-"));
|
||||
getNitroFilesRootMock.mockResolvedValue("");
|
||||
getGamedataRootMock.mockResolvedValue(path.join(tempDir, "Gamedata"));
|
||||
settingGetMock.mockImplementation(
|
||||
async (key: string, fallback: string | null = null) => {
|
||||
if (key === "furni_data_url") {
|
||||
return path.join(tempDir, "cms", "FurnitureData.json");
|
||||
}
|
||||
if (key === "furni_data_mirror_path") return "";
|
||||
return fallback;
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await fs.rm(tempDir, { recursive: true, force: true });
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("writes metadata into the config directory served by production", async () => {
|
||||
const data = { roomitemtypes: { furnitype: [{ id: 123 }] } };
|
||||
|
||||
await writeFurniData(data);
|
||||
|
||||
const livePath = path.join(
|
||||
tempDir,
|
||||
"Gamedata",
|
||||
"config",
|
||||
"FurnitureData.json",
|
||||
);
|
||||
await expect(fs.readFile(livePath, "utf-8")).resolves.toBe(
|
||||
JSON.stringify(data),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user