import { beforeEach, describe, expect, it } from "vitest"; import { listPendingVouchedDevices, removePendingVouchedDevice, } from "./pending-vouched-devices"; function makeStorageStub() { const local = new Map(); (globalThis as unknown as { chrome: unknown }).chrome = { storage: { local: { async get(key?: string | string[] | null) { if (key == null) { const all: Record = {}; for (const [k, v] of local) all[k] = v; return all; } const keys = Array.isArray(key) ? key : [key]; const out: Record = {}; for (const k of keys) if (local.has(k)) out[k] = local.get(k); return out; }, async set(values: Record) { for (const [k, v] of Object.entries(values)) local.set(k, v); }, async remove(key: string | string[]) { for (const k of Array.isArray(key) ? key : [key]) local.delete(k); }, }, }, }; } const SAMPLE = { deviceId: "VVV-1", deviceName: "Vouched Pixel", deviceType: "android", longTermPublicKeyHex: "a".repeat(64), signingPublicKeyHex: "b".repeat(64), pairedAt: 1, receivedAt: 2, vouchedByDeviceId: "issuer-1", }; describe("pending vouched devices", () => { beforeEach(() => makeStorageStub()); it("lists and removes a pending record created by an older build", async () => { await chrome.storage.local.set({ peach_pending_vouched_devices_v1: [SAMPLE] }); expect(await listPendingVouchedDevices()).toEqual([SAMPLE]); await removePendingVouchedDevice(SAMPLE.deviceId); expect(await listPendingVouchedDevices()).toEqual([]); }); });