Files
SnapOtter/tests/integration/platform/preferences.test.ts
T
SnapOtterandGitHub 63a03d26f2 feat: pipeline templates, analytics opt-out, 83 conversion presets, positioning + e2e modernization
Lands five integrated branches: pipeline templates (#355), analytics opt-out (#354), 83 conversion presets bringing the catalog to 240 tools (#356), self-hosted positioning (#353), and e2e modernization (#351).

Integration fixes: aligned stale web analytics tests with the opt-out/allow-list model, closed 3 CodeQL incomplete-sanitization alerts in the i18n generator, resolved settings/index/docs/format-matrix conflicts, and corrected tool counts to 240.
2026-06-28 18:57:53 +08:00

72 lines
2.3 KiB
TypeScript

/**
* Integration tests for per-user preferences (GET/PUT /api/v1/preferences).
*
* Preferences are writable by any authenticated user (unlike the admin-only
* /v1/settings), so the default home view can be saved per-user.
*/
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { buildTestApp, loginAsAdmin, type TestApp } from "../test-server.js";
let testApp: TestApp;
let app: TestApp["app"];
let adminToken: string;
beforeAll(async () => {
testApp = await buildTestApp();
app = testApp.app;
adminToken = await loginAsAdmin(app);
}, 30_000);
afterAll(async () => {
await testApp.cleanup();
}, 10_000);
describe("per-user preferences", () => {
it("requires authentication", async () => {
const res = await app.inject({ method: "GET", url: "/api/v1/preferences" });
expect(res.statusCode).toBe(401);
});
it("returns an empty map before anything is saved", async () => {
const res = await app.inject({
method: "GET",
url: "/api/v1/preferences",
headers: { authorization: `Bearer ${adminToken}` },
});
expect(res.statusCode).toBe(200);
expect(JSON.parse(res.body)).toEqual({ preferences: {} });
});
it("saves and reads back a preference", async () => {
const put = await app.inject({
method: "PUT",
url: "/api/v1/preferences",
headers: { authorization: `Bearer ${adminToken}`, "content-type": "application/json" },
payload: { defaultToolView: "fullscreen" },
});
expect(put.statusCode).toBe(200);
const get = await app.inject({
method: "GET",
url: "/api/v1/preferences",
headers: { authorization: `Bearer ${adminToken}` },
});
expect(JSON.parse(get.body).preferences.defaultToolView).toBe("fullscreen");
});
it("upserts an existing preference rather than duplicating it", async () => {
await app.inject({
method: "PUT",
url: "/api/v1/preferences",
headers: { authorization: `Bearer ${adminToken}`, "content-type": "application/json" },
payload: { defaultToolView: "sidebar" },
});
const get = await app.inject({
method: "GET",
url: "/api/v1/preferences",
headers: { authorization: `Bearer ${adminToken}` },
});
expect(JSON.parse(get.body).preferences.defaultToolView).toBe("sidebar");
});
});