import test from "node:test"; import assert from "node:assert/strict"; import { appDownloadURL } from "../src/lib/app-download"; import { createContext } from "../src/server/context"; import { loadSharedData } from "../src/server/services/shared"; test("download destination keeps the primary address ahead of the official fallback", () => { assert.equal(appDownloadURL({ appAddr: " https://downloads.example/app?channel=web ", officialAppAddr: "https://official.example/app" }), "https://downloads.example/app?channel=web"); assert.equal(appDownloadURL({ config: { appAddr: "https://downloads.example/config" }, newAddressInfo: { appAddr: "https://downloads.example/new" } }), "https://downloads.example/config"); }); test("empty config fields cannot erase valid address data or its official fallback", () => { assert.equal(appDownloadURL({ appAddr: "", config: { appAddr: " " }, newAddressInfo: { appAddr: "https://downloads.example/new" }, officialAppAddr: "https://official.example/app" }), "https://downloads.example/new"); assert.equal(appDownloadURL({ appAddr: " ", config: { officialAppAddr: " https://official.example/app " } }), "https://official.example/app"); assert.equal(appDownloadURL({ newAddressInfo: { officialAppAddr: "https://official.example/new" } }), "https://official.example/new"); assert.equal(appDownloadURL({ AppAddr: "https://downloads.example/legacy" }), "https://downloads.example/legacy"); }); test("missing download configuration stays empty rather than inventing a QR destination", () => { for (const value of [undefined, null, "https://downloads.example/", {}, { appAddr: " ", officialAppAddr: "" }, { appAddr: 123, config: null, newAddressInfo: { officialAppAddr: false } }]) { assert.equal(appDownloadURL(value), ""); } }); test("the installation dialog receives the same primary or official destination as the QR", async () => { for (const appConfig of [ { appAddr: "https://downloads.example/app", officialAppAddr: "https://official.example/app" }, { appAddr: "", officialAppAddr: "https://official.example/app" }, { config: { appAddr: "" }, newAddressInfo: { appAddr: "https://downloads.example/new" } }, { appAddr: "", officialAppAddr: "" }, ]) { const ctx = createContext(new Request("http://site.test/")); const data = await loadSharedData(ctx, { appConfig, categoryList: [{ name: "首页", urlValue: "/", categoryType: 1 }], themeList: [], homeConfigData: [], searchTrends: [], }); assert.equal(data.installGuide.fallbackURL, appDownloadURL(appConfig) || "/app/download/"); } });