mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-27 21:33:41 +02:00
* 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>
54 lines
1.4 KiB
TypeScript
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({});
|
|
});
|
|
});
|