import assert from "node:assert/strict"; import { applyPresentationValues, presentationFieldName, readPresentationValue, } from "../src/features/brand/presentation-bindings.ts"; const config = { founder: "阿成", visualPresentation: { home: { worksTitle: "原标题", preserveMe: "保留" }, inquiry: { subtitle: "原说明" }, }, unrelatedSetting: true, }; const sections = [ { key: "home", fields: [ { key: "founder", binding: "brand.config.founder" }, { key: "worksTitle", binding: "brand.config.visualPresentation.home.worksTitle" }, ], }, ]; const next = applyPresentationValues(config, sections, { [presentationFieldName("home", "founder")]: "阿成主理人", [presentationFieldName("home", "worksTitle")]: "今日套餐", }); assert.equal(readPresentationValue(next, "brand.config.founder"), "阿成主理人"); assert.equal( readPresentationValue(next, "brand.config.visualPresentation.home.worksTitle"), "今日套餐", ); assert.equal(next.visualPresentation.home.preserveMe, "保留"); assert.equal(next.visualPresentation.inquiry.subtitle, "原说明"); assert.equal(next.unrelatedSetting, true); assert.equal(config.founder, "阿成"); const unsafe = applyPresentationValues( { founder: "原主理人" }, [ { key: "unsafe", fields: [ { key: "tenant", binding: "brand.id" }, { key: "prototype", binding: "brand.config.__proto__.polluted" }, ], }, ], { [presentationFieldName("unsafe", "tenant")]: "other-brand", [presentationFieldName("unsafe", "prototype")]: "yes", }, ); assert.deepEqual(unsafe, { founder: "原主理人" }); assert.equal({}.polluted, undefined);