Files
SnapOtter/tests/unit/web/settings-payload.test.ts
T
SnapOtterandGitHub 23efce9df0 fix(analytics): harden analytics opt-out and feedback surfaces (#423)
Server stops phoning Sentry home after opt-out (release-health sessions + client reports off); settings saves diff-send only changed keys so a stale tab cannot revert an instance-wide opt-out; disabling analytics hides the feedback UI immediately; optIn resumes PostHog after re-enable; onboarding survey writes time out at 15s; inline tool-feedback prompt arms a shown-cooldown.
2026-07-04 14:02:28 +08:00

41 lines
1.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { changedSettings, writableSettings } from "@/lib/settings-payload";
describe("writableSettings", () => {
it("strips server-managed read-only keys that the PUT rejects", () => {
expect(
writableSettings({ instance_id: "abc", cookie_secret: "shh", defaultTheme: "dark" }),
).toEqual({ defaultTheme: "dark" });
});
it("strips masked secret placeholders so a real secret is never overwritten by the mask", () => {
expect(writableSettings({ oidc_client_secret: "********", fileUploadLimitMb: "100" })).toEqual({
fileUploadLimitMb: "100",
});
});
});
describe("changedSettings", () => {
it("returns only keys whose value differs from the original snapshot", () => {
const original = { analyticsEnabled: "true", defaultTheme: "system" };
const current = { analyticsEnabled: "true", defaultTheme: "dark" };
expect(changedSettings(original, current)).toEqual({ defaultTheme: "dark" });
});
it("omits an unchanged analyticsEnabled so a stale save cannot revert an instance-wide opt-out", () => {
const original = { analyticsEnabled: "true", fileUploadLimitMb: "100" };
const current = { analyticsEnabled: "true", fileUploadLimitMb: "250" };
expect("analyticsEnabled" in changedSettings(original, current)).toBe(false);
});
it("includes a key the user actually toggled", () => {
expect(changedSettings({ analyticsEnabled: "true" }, { analyticsEnabled: "false" })).toEqual({
analyticsEnabled: "false",
});
});
it("includes keys added since the snapshot was taken", () => {
expect(changedSettings({}, { defaultLocale: "fr" })).toEqual({ defaultLocale: "fr" });
});
});