85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
import * as React from "react";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import ProjectsPage from "../src/app/projects/page.js";
|
|
import { importProjectTransferAsNew } from "../src/frontend/utils/api.js";
|
|
import { importProjectTransferAsNewSchema } from "../src/shared/validation/project-transfer.schemas.js";
|
|
|
|
describe("project overview import", () => {
|
|
it("renders a dedicated import-as-new-project entry point", () => {
|
|
const globalWithReact = globalThis as typeof globalThis & {
|
|
React?: typeof React;
|
|
};
|
|
const originalReact = globalWithReact.React;
|
|
globalWithReact.React = React;
|
|
let markup: string;
|
|
try {
|
|
markup = renderToStaticMarkup(React.createElement(ProjectsPage));
|
|
} finally {
|
|
globalWithReact.React = originalReact;
|
|
}
|
|
|
|
assert.match(markup, /Projekt importieren/);
|
|
assert.match(markup, /Projektdatei auswählen/);
|
|
assert.match(markup, /Als neues Projekt importieren/);
|
|
assert.doesNotMatch(markup, /Dieses Projekt ersetzen/);
|
|
});
|
|
|
|
it("uses the collection import endpoint without a target project id", async () => {
|
|
const requests: Array<{
|
|
url: string;
|
|
method: string;
|
|
body: unknown;
|
|
}> = [];
|
|
const originalFetch = globalThis.fetch;
|
|
globalThis.fetch = async (input, init) => {
|
|
requests.push({
|
|
url: String(input),
|
|
method: init?.method ?? "GET",
|
|
body: init?.body ? JSON.parse(String(init.body)) : null,
|
|
});
|
|
return new Response(
|
|
JSON.stringify({ projectId: "project-copy", name: "Projekt (Kopie)" }),
|
|
{
|
|
status: 201,
|
|
headers: { "Content-Type": "application/json" },
|
|
}
|
|
);
|
|
};
|
|
|
|
try {
|
|
const transfer = { format: "test" };
|
|
const result = await importProjectTransferAsNew(transfer);
|
|
assert.deepEqual(result, {
|
|
projectId: "project-copy",
|
|
name: "Projekt (Kopie)",
|
|
});
|
|
assert.deepEqual(requests, [
|
|
{
|
|
url: "/api/projects/import",
|
|
method: "POST",
|
|
body: { transfer },
|
|
},
|
|
]);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|
|
|
|
it("accepts only the strict transfer wrapper", () => {
|
|
assert.equal(
|
|
importProjectTransferAsNewSchema.safeParse({ transfer: {} }).success,
|
|
true
|
|
);
|
|
assert.equal(importProjectTransferAsNewSchema.safeParse({}).success, false);
|
|
assert.equal(
|
|
importProjectTransferAsNewSchema.safeParse({
|
|
transfer: {},
|
|
mode: "replace",
|
|
}).success,
|
|
false
|
|
);
|
|
});
|
|
});
|