Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: preserve absent Loops mailing list memberships

Richie McIlroy736ea1f64270
diff --git a/packages/database/loops/sync-policy.ts b/packages/database/loops/sync-policy.ts
index 346d8d8f2..f86291fb5 100644
--- a/packages/database/loops/sync-policy.ts
+++ b/packages/database/loops/sync-policy.ts
@@ -74,20 +74,5 @@ export function importContactUpdate(
remote: RemoteContact,
listId?: string,
) {
- if (
- listId &&
- profile.capConsent === "subscribed" &&
- remote.subscribed &&
- remote.mailingLists[listId] === undefined
- ) {
- return {
- ...contactUpdate(
- profile,
- { ...remote, mailingLists: { ...remote.mailingLists, [listId]: true } },
- listId,
- ),
- mailingLists: { [listId]: true },
- };
- }
return contactUpdate(profile, remote, listId);
}
diff --git a/scripts/loops/profile.test.ts b/scripts/loops/profile.test.ts
index e1b661061..2b0a58ee0 100644
--- a/scripts/loops/profile.test.ts
+++ b/scripts/loops/profile.test.ts
@@ -244,23 +244,31 @@ test("existing teammate evidence and identities survive contact enrichment", ()
assert.equal(contactUpdate(profile, remote(), "tips").userId, "cap-user");
});
-test("migration joins a new list without overwriting any explicit preference", () => {
- const profile = classifyProfile(input());
- const update = importContactUpdate(profile, remote(), "new-list");
- assert.deepEqual("mailingLists" in update && update.mailingLists, {
- "new-list": true,
- });
+test("migration preserves missing, removed and unsubscribed list preferences", () => {
+ const profile = {
+ ...classifyProfile(input()),
+ capOnboardingEligible: true,
+ capLifecycleEnabled: true,
+ capLifecycleStage: "free",
+ };
+ const update = importContactUpdate(profile, remote(), "tips");
+ assert.equal("mailingLists" in update, false);
assert.equal(update.capPromotionalEligible, true);
- assert.equal(update.capLifecycleEnabled, false);
+ assert.equal(update.capLifecycleEnabled, true);
assert.equal("subscribed" in update, false);
for (const contact of [
{ ...remote(), subscribed: false },
- { ...remote(), mailingLists: { "new-list": false } },
+ { ...remote(), mailingLists: {} },
+ { ...remote(), mailingLists: { other: true } },
+ { ...remote(), mailingLists: { tips: false } },
]) {
- const held = importContactUpdate(profile, contact, "new-list");
+ const held = importContactUpdate(profile, contact, "tips");
assert.equal("mailingLists" in held, false);
assert.equal("subscribed" in held, false);
assert.equal(held.capPromotionalEligible, false);
+ assert.equal(held.capOnboardingEligible, false);
+ assert.equal(held.capLifecycleEnabled, false);
+ assert.equal(held.capLifecycleStage, "idle");
}
});