refactor(webui): select Mail-owned profiles for campaigns
This commit is contained in:
@@ -1,42 +1,26 @@
|
||||
import { campaignMailSettingsPolicyState } from "../src/features/campaigns/policyUi";
|
||||
import { campaignMailProfileReferenceOnly } from "../src/features/campaigns/utils/mailProfileReference";
|
||||
|
||||
function assert(condition: unknown, message: string): void {
|
||||
if (!condition) throw new Error(message);
|
||||
}
|
||||
|
||||
const blockedInline = campaignMailSettingsPolicyState({
|
||||
effectivePolicy: { allow_campaign_profiles: false },
|
||||
selectedProfileId: ""
|
||||
});
|
||||
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
|
||||
}
|
||||
};
|
||||
|
||||
assert(blockedInline.campaignProfilesAllowed === false, "Blocked policy must not allow campaign-local settings.");
|
||||
assert(blockedInline.inlineMailSettingsBlocked === true, "Inline SMTP/IMAP must be blocked when no reusable profile is selected.");
|
||||
assert(blockedInline.inlineOptionDisabled === true, "Inline option must be disabled under a blocking policy.");
|
||||
assert(blockedInline.canSelectInlineSettings === false, "Blocked inline option must not be selectable.");
|
||||
const normalized = campaignMailProfileReferenceOnly(source);
|
||||
const server = normalized.server as Record<string, unknown>;
|
||||
|
||||
const blockedWithReusableProfile = campaignMailSettingsPolicyState({
|
||||
effectivePolicy: { allow_campaign_profiles: false },
|
||||
selectedProfileId: "tenant-profile"
|
||||
});
|
||||
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.");
|
||||
|
||||
assert(blockedWithReusableProfile.inlineMailSettingsBlocked === false, "Reusable profiles must remain usable when campaign-local settings are blocked.");
|
||||
assert(blockedWithReusableProfile.inlineOptionDisabled === true, "Inline option remains disabled even while a reusable profile is selected.");
|
||||
|
||||
const allowedInline = campaignMailSettingsPolicyState({
|
||||
effectivePolicy: { allow_campaign_profiles: true },
|
||||
selectedProfileId: ""
|
||||
});
|
||||
|
||||
assert(allowedInline.campaignProfilesAllowed === true, "Allowed policy must allow campaign-local settings.");
|
||||
assert(allowedInline.inlineMailSettingsBlocked === false, "Inline SMTP/IMAP must be available when campaign-local settings are allowed.");
|
||||
assert(allowedInline.inlineOptionDisabled === false, "Inline option must be enabled under an allowing policy.");
|
||||
assert(allowedInline.canSelectInlineSettings === true, "Allowed inline option must be selectable.");
|
||||
|
||||
const lockedInline = campaignMailSettingsPolicyState({
|
||||
effectivePolicy: { allow_campaign_profiles: true },
|
||||
selectedProfileId: "",
|
||||
locked: true
|
||||
});
|
||||
|
||||
assert(lockedInline.inlineOptionDisabled === false, "Policy does not disable inline settings when the policy allows them.");
|
||||
assert(lockedInline.canSelectInlineSettings === false, "A locked version still must not allow selecting inline settings.");
|
||||
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.");
|
||||
|
||||
Reference in New Issue
Block a user