Files
KrisHD_AI/test/workspaceTransferUi.test.js
2026-10-06 00:32:18 +02:00

18 lines
1.0 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import {createWorkspaceTransfer} from "../public/js/workspaceTransfer.js";
test("export cancellation makes no request and failed downloads report structured server errors", async t => {
let requests = 0, format = null;
t.mock.method(globalThis, "fetch", async () => { requests++; return Response.json({error: "Session expired", code: "LOGIN_REQUIRED"}, {status: 403}); });
const notices = [];
const transfer = createWorkspaceTransfer({conversation: {activeChatId: 1, currentMessages: [{}]}, getChatById: () => ({id: 1, title: "Chat"}),
setNotice: (text, kind) => notices.push({text, kind}), promptPopup: async () => format});
await transfer.exportCurrentChat(); assert.equal(requests, 0);
format = "md";
await transfer.exportCurrentChat();
await transfer.backupWorkspace();
assert.equal(requests, 2);
assert.deepEqual(notices, [{text: "Session expired", kind: "error"}, {text: "Session expired", kind: "error"}]);
});