feat(housekeeping): persist operator preferences
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createHousekeepingPreferencesRepository,
|
||||
type HousekeepingPreferencesStorage,
|
||||
} from "./repository";
|
||||
import { defaultHousekeepingPreferences } from "./schema";
|
||||
|
||||
describe("housekeeping preferences repository", () => {
|
||||
it("returns a fresh default when no row exists", async () => {
|
||||
const storage: HousekeepingPreferencesStorage = {
|
||||
findByUserId: vi.fn().mockResolvedValue(null),
|
||||
upsert: vi.fn(),
|
||||
};
|
||||
const repository = createHousekeepingPreferencesRepository(storage);
|
||||
|
||||
expect(await repository.read(42)).toEqual(defaultHousekeepingPreferences());
|
||||
expect(storage.findByUserId).toHaveBeenCalledWith(42);
|
||||
});
|
||||
|
||||
it("reads validated JSON and writes the schema-versioned payload through the injected adapter", async () => {
|
||||
const value = {
|
||||
...defaultHousekeepingPreferences(),
|
||||
pinnedRouteIds: ["people.users"],
|
||||
};
|
||||
const storage: HousekeepingPreferencesStorage = {
|
||||
findByUserId: vi.fn().mockResolvedValue({
|
||||
schemaVersion: 1,
|
||||
payload: JSON.stringify(value),
|
||||
}),
|
||||
upsert: vi.fn(),
|
||||
};
|
||||
const repository = createHousekeepingPreferencesRepository(storage);
|
||||
|
||||
expect(await repository.read(42)).toEqual(value);
|
||||
await repository.upsert(42, value);
|
||||
expect(storage.upsert).toHaveBeenCalledWith({
|
||||
userId: 42,
|
||||
schemaVersion: 1,
|
||||
payload: JSON.stringify(value),
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user