feat(campaign): complete reusable template workflow
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
|
||||
const source = readFileSync(new URL("../src/features/campaigns/TemplateDataPage.tsx", import.meta.url), "utf8");
|
||||
|
||||
assert.match(source, /checkContentLibraryCompatibility\(item\.required_fields, contentAvailableFields\)/);
|
||||
assert.match(source, /Field compatibility needs attention\./);
|
||||
assert.match(source, /requestCampaignPart\(item\)/);
|
||||
assert.match(source, /<ConfirmDialog[\s\S]*Replace current Campaign content\?/);
|
||||
assert.doesNotMatch(source, /onClick=\{\(\) => applyCampaignPart\(item\)\}/);
|
||||
|
||||
console.log("Campaign content-library compatibility and overwrite-confirmation contract passed.");
|
||||
@@ -1,4 +1,5 @@
|
||||
import { campaignJsonForAttachmentPreview } from "../src/features/campaigns/utils/templatePreviewDraft";
|
||||
import { checkContentLibraryCompatibility } from "../src/features/campaigns/utils/contentLibraryCompatibility";
|
||||
|
||||
function assert(condition: unknown, message = "assertion failed"): void {
|
||||
if (!condition) throw new Error(message);
|
||||
@@ -52,3 +53,18 @@ assert(to.length === 1 && to[0].email === "alice@example.org", "empty recipient
|
||||
assert(defaults.email === undefined, "empty defaults email is stripped");
|
||||
assert(Array.isArray(defaults.to) && (defaults.to as unknown[]).length === 0, "empty defaults recipients are removed");
|
||||
assert((asRecord(draft.entries).inline as Record<string, unknown>[])[0].email === "", "original draft is not mutated");
|
||||
|
||||
const compatibility = checkContentLibraryCompatibility([
|
||||
{ path: "local::display_name", value_type: "string", label: "Display name", required: true },
|
||||
{ path: "global.case_reference", value_type: "string", label: "Case reference", required: true },
|
||||
{ path: "count", value_type: "number", label: "Count", required: true },
|
||||
{ path: "local.to.2.email", value_type: "string", label: "Second recipient", required: true },
|
||||
{ path: "optional", value_type: "string", required: false }
|
||||
], new Map([
|
||||
["local:display_name", "string"],
|
||||
["local:to", "string"],
|
||||
["count", "boolean"]
|
||||
]));
|
||||
assert(!compatibility.compatible, "missing or wrong-typed fields are incompatible");
|
||||
assert(compatibility.missing.length === 1 && compatibility.missing[0].path === "global:case_reference", "namespaced missing fields are normalized");
|
||||
assert(compatibility.incompatible.length === 1 && compatibility.incompatible[0].actual === "boolean", "type mismatches are reported");
|
||||
|
||||
Reference in New Issue
Block a user