27 lines
1.3 KiB
TypeScript
27 lines
1.3 KiB
TypeScript
import { campaignMailProfileReferenceOnly } 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.");
|