Skip to content

Commit 736ea1f

Browse files
committed
fix: preserve absent Loops mailing list memberships
1 parent c2cfc70 commit 736ea1f

2 files changed

Lines changed: 17 additions & 24 deletions

File tree

packages/database/loops/sync-policy.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,5 @@ export function importContactUpdate(
7474
remote: RemoteContact,
7575
listId?: string,
7676
) {
77-
if (
78-
listId &&
79-
profile.capConsent === "subscribed" &&
80-
remote.subscribed &&
81-
remote.mailingLists[listId] === undefined
82-
) {
83-
return {
84-
...contactUpdate(
85-
profile,
86-
{ ...remote, mailingLists: { ...remote.mailingLists, [listId]: true } },
87-
listId,
88-
),
89-
mailingLists: { [listId]: true },
90-
};
91-
}
9277
return contactUpdate(profile, remote, listId);
9378
}

scripts/loops/profile.test.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,23 +244,31 @@ test("existing teammate evidence and identities survive contact enrichment", ()
244244
assert.equal(contactUpdate(profile, remote(), "tips").userId, "cap-user");
245245
});
246246

247-
test("migration joins a new list without overwriting any explicit preference", () => {
248-
const profile = classifyProfile(input());
249-
const update = importContactUpdate(profile, remote(), "new-list");
250-
assert.deepEqual("mailingLists" in update && update.mailingLists, {
251-
"new-list": true,
252-
});
247+
test("migration preserves missing, removed and unsubscribed list preferences", () => {
248+
const profile = {
249+
...classifyProfile(input()),
250+
capOnboardingEligible: true,
251+
capLifecycleEnabled: true,
252+
capLifecycleStage: "free",
253+
};
254+
const update = importContactUpdate(profile, remote(), "tips");
255+
assert.equal("mailingLists" in update, false);
253256
assert.equal(update.capPromotionalEligible, true);
254-
assert.equal(update.capLifecycleEnabled, false);
257+
assert.equal(update.capLifecycleEnabled, true);
255258
assert.equal("subscribed" in update, false);
256259
for (const contact of [
257260
{ ...remote(), subscribed: false },
258-
{ ...remote(), mailingLists: { "new-list": false } },
261+
{ ...remote(), mailingLists: {} },
262+
{ ...remote(), mailingLists: { other: true } },
263+
{ ...remote(), mailingLists: { tips: false } },
259264
]) {
260-
const held = importContactUpdate(profile, contact, "new-list");
265+
const held = importContactUpdate(profile, contact, "tips");
261266
assert.equal("mailingLists" in held, false);
262267
assert.equal("subscribed" in held, false);
263268
assert.equal(held.capPromotionalEligible, false);
269+
assert.equal(held.capOnboardingEligible, false);
270+
assert.equal(held.capLifecycleEnabled, false);
271+
assert.equal(held.capLifecycleStage, "idle");
264272
}
265273
});
266274

0 commit comments

Comments
 (0)