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({}); }); });