39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
|
|
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"]);
|
||
|
|
});
|