Files
govoplan-campaign/webui/tests/policy-ui.test.ts
T
zemion c51fc180fb
Module Package Release / publish-packages (push) Successful in 12s
Release govoplan-campaign v0.1.28: stabilize saving, review and delivery recovery
2026-09-08 01:32:26 +02:00

58 lines
3.7 KiB
TypeScript

import { campaignMailProfileListOptions, campaignMailProfileReferenceOnly, campaignMailReferencesUnchanged } from "../src/features/campaigns/utils/mailProfileReference";
function assert(condition: unknown, message: string): void {
if (!condition) throw new Error(message);
}
const source = {
campaign: { id: "campaign-1" },
server: {
mail_profile_id: " profile-1 ",
smtp: { host: "smtp.example.test", password: "smtp-secret" },
imap: { host: "imap.example.test", password: "imap-secret" },
credentials: { smtp: { username: "sender", password: "legacy-secret" } },
inherit_smtp_credentials: false
}
};
const normalized = campaignMailProfileReferenceOnly(source);
const server = normalized.server as Record<string, unknown>;
assert(server.mail_profile_id === "profile-1", "The stable Mail profile reference must be retained and trimmed.");
assert(Object.keys(server).length === 1, "All campaign-local transport settings and credentials must be removed.");
assert((source.server.smtp as Record<string, unknown>).password === "smtp-secret", "Normalization must not mutate the loaded audit representation.");
const withoutProfile = campaignMailProfileReferenceOnly({ server: { smtp: { host: "legacy" } } });
assert(Object.keys(withoutProfile.server as Record<string, unknown>).length === 0, "Legacy settings without a profile must normalize to an empty reference object.");
const campaignChoices = campaignMailProfileListOptions("settings", "campaign-1");
assert(campaignChoices.campaignId === "campaign-1", "Mail settings must load profiles authorized for this campaign.");
assert(!campaignChoices.includeInactive, "Inactive profiles cannot become campaign delivery choices.");
const policyChoices = campaignMailProfileListOptions("policy", "campaign-1");
assert(policyChoices.campaignId === undefined, "Policy management must not restrict its catalogue to the current campaign allowance.");
assert(policyChoices.includeInactive, "Policy management may inspect its authorized inactive catalogue independently of delivery selection.");
const mixedLegacy = campaignMailProfileReferenceOnly({ server: {
mail_profile_id: "profile-1",
smtp_server_id: "server-smtp",
smtp_credential_id: "credential-smtp",
imap_server_id: "server-imap",
imap_credential_id: "credential-imap",
smtp: { password: "never-resubmit" },
imap: { password: "never-resubmit" },
credentials: { password: "never-resubmit" },
inherit_smtp_credentials: true,
inherit_imap_credentials: true
} });
assert(Object.keys(mixedLegacy.server as Record<string, unknown>).length === 5, "Migration must preserve all five stable Mail references and no legacy transport fields.");
assert(!JSON.stringify(mixedLegacy).includes("never-resubmit"), "Migration must not resubmit transport secrets.");
assert(campaignMailReferencesUnchanged(normalized, {
...normalized, attachments: { zip: { archives: [{ method: "aes" }] } }
}), "Unchanged public Mail references allow an independent archive policy repair.");
assert(campaignMailReferencesUnchanged({ server: {} }, { server: {}, template: { text: "Repair" } }), "A legacy version without a selected profile can still save unrelated repairs.");
assert(!campaignMailReferencesUnchanged(normalized, { server: { mail_profile_id: "profile-2" } }), "Selecting another Mail profile requires explicit migration.");
assert(!campaignMailReferencesUnchanged(normalized, { server: {} }), "Removing a Mail reference is not an unchanged save.");
assert(!campaignMailReferencesUnchanged(normalized, { server: { ...server, smtp: {} } }), "Inline transport cannot be submitted as an unrelated repair.");
assert(!campaignMailReferencesUnchanged(mixedLegacy, { server: { ...(mixedLegacy.server as object), smtp_credential_id: "other" } }), "Changing a Mail credential requires explicit migration.");