Files
moteva/frontend/tests/canvasImportUpload.test.mjs
T

39 lines
1.3 KiB
JavaScript
Raw Normal View History

import assert from "node:assert/strict";
import test from "node:test";
import { uploadPreparedCanvasImportAsset } from "../src/ui/lib/canvasImportUpload.ts";
test("commits source and transparent render texture only after both uploads succeed", async () => {
const source = { name: "drawing.svg" };
const render = { name: "drawing.render.webp" };
const uploaded = await uploadPreparedCanvasImportAsset(
{ file: source, renderFile: render },
async (file) => `https://assets.example/${file.name}`,
async () => {
throw new Error("cleanup should not run");
}
);
assert.deepEqual(uploaded, {
content: "https://assets.example/drawing.svg",
renderContent: "https://assets.example/drawing.render.webp"
});
});
test("removes a partial source upload when the render texture upload fails", async () => {
const cleaned = [];
await assert.rejects(
uploadPreparedCanvasImportAsset(
{ file: { name: "drawing.svg" }, renderFile: { name: "drawing.render.webp" } },
async (file) => {
if (file.name.endsWith(".webp")) throw new Error("preview upload failed");
return "https://assets.example/drawing.svg";
},
async (url) => cleaned.push(url)
),
/preview upload failed/
);
assert.deepEqual(cleaned, ["https://assets.example/drawing.svg"]);
});