1import { beforeEach, describe, expect, it } from "vitest";2import {3 listPendingVouchedDevices,4 removePendingVouchedDevice,5} from "./pending-vouched-devices";67function makeStorageStub() {8 const local = new Map<string, unknown>();9 (globalThis as unknown as { chrome: unknown }).chrome = {10 storage: {11 local: {12 async get(key?: string | string[] | null) {13 if (key == null) {14 const all: Record<string, unknown> = {};15 for (const [k, v] of local) all[k] = v;16 return all;17 }18 const keys = Array.isArray(key) ? key : [key];19 const out: Record<string, unknown> = {};20 for (const k of keys) if (local.has(k)) out[k] = local.get(k);21 return out;22 },23 async set(values: Record<string, unknown>) {24 for (const [k, v] of Object.entries(values)) local.set(k, v);25 },26 async remove(key: string | string[]) {27 for (const k of Array.isArray(key) ? key : [key]) local.delete(k);28 },29 },30 },31 };32}3334const SAMPLE = {35 deviceId: "VVV-1",36 deviceName: "Vouched Pixel",37 deviceType: "android",38 longTermPublicKeyHex: "a".repeat(64),39 signingPublicKeyHex: "b".repeat(64),40 pairedAt: 1,41 receivedAt: 2,42 vouchedByDeviceId: "issuer-1",43};4445describe("pending vouched devices", () => {46 beforeEach(() => makeStorageStub());4748 it("lists and removes a pending record created by an older build", async () => {49 await chrome.storage.local.set({ peach_pending_vouched_devices_v1: [SAMPLE] });50 expect(await listPendingVouchedDevices()).toEqual([SAMPLE]);51 await removePendingVouchedDevice(SAMPLE.deviceId);52 expect(await listPendingVouchedDevices()).toEqual([]);53 });54});