Files
multica/packages/core/notification-preferences/patch.test.ts
Jiayuan Zhang 19e52e007c MUL-4798: make Inbox notification preference updates atomic (#5451)
* fix(notifications): make preference updates atomic

Co-authored-by: multica-agent <github@multica.ai>

* fix(notifications): serialize preference mutations

Co-authored-by: multica-agent <github@multica.ai>

---------

Co-authored-by: Lambda <lambda@multica.ai>
Co-authored-by: multica-agent <github@multica.ai>
2026-07-15 17:52:10 +08:00

54 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
applyNotificationPreferencePatch,
deriveNotificationPreferencePatch,
rollbackNotificationPreferencePatch,
} from "./patch";
describe("notification preference patches", () => {
it("sends only the changed key when another muted preference is present", () => {
expect(
deriveNotificationPreferencePatch(
{ status_changes: "muted" },
{ status_changes: "muted", comments: "muted" },
),
).toEqual({ comments: "muted" });
});
it("uses an explicit all value when enabling a previously muted group", () => {
expect(
deriveNotificationPreferencePatch(
{ status_changes: "muted", comments: "muted" },
{ comments: "muted" },
),
).toEqual({ status_changes: "all" });
});
it("merges optimistic patches without dropping unrelated preferences", () => {
expect(
applyNotificationPreferencePatch(
{ status_changes: "muted" },
{ comments: "muted" },
),
).toEqual({ status_changes: "muted", comments: "muted" });
});
it("does not roll back a key that a later mutation already changed", () => {
expect(
rollbackNotificationPreferencePatch(
{ comments: "muted" },
{ comments: "muted" },
{},
),
).toEqual({});
expect(
rollbackNotificationPreferencePatch(
{},
{ comments: "muted" },
{},
),
).toEqual({});
});
});