28 lines
1016 B
JavaScript
28 lines
1016 B
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { templatePreviewUrl } from "../src/lib/template-preview.ts";
|
|
|
|
test("template preview URL is resolved from generic deployment configuration", () => {
|
|
const url = templatePreviewUrl(
|
|
"new-template",
|
|
"brand-a",
|
|
"profile",
|
|
JSON.stringify({ "new-template": "https://preview.example.test/app/" }),
|
|
"https://admin.example.test",
|
|
"/pages/profile/index",
|
|
);
|
|
assert.equal(
|
|
url,
|
|
"https://preview.example.test/app/?editor=1&parentOrigin=https%3A%2F%2Fadmin.example.test&brand=brand-a#/pages/profile/index",
|
|
);
|
|
});
|
|
|
|
test("missing, malformed or invalid template preview configuration fails closed", () => {
|
|
assert.equal(templatePreviewUrl("missing", "brand-a", "home", undefined), undefined);
|
|
assert.equal(templatePreviewUrl("missing", "brand-a", "home", "{"), undefined);
|
|
assert.equal(
|
|
templatePreviewUrl("broken", "brand-a", "home", JSON.stringify({ broken: "not a URL" })),
|
|
undefined,
|
|
);
|
|
});
|