|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import { |
| 3 | + clearFlaggedAccountsEntry, |
| 4 | + saveFlaggedAccountsEntry, |
| 5 | +} from "../lib/storage/flagged-entry.js"; |
| 6 | + |
| 7 | +describe("flagged entry helpers", () => { |
| 8 | + it("delegates save through the storage lock", async () => { |
| 9 | + const saveUnlocked = vi.fn(async () => undefined); |
| 10 | + await saveFlaggedAccountsEntry({ |
| 11 | + storage: { version: 1, accounts: [] }, |
| 12 | + withStorageLock: async (fn) => fn(), |
| 13 | + saveUnlocked, |
| 14 | + }); |
| 15 | + |
| 16 | + expect(saveUnlocked).toHaveBeenCalledWith({ version: 1, accounts: [] }); |
| 17 | + }); |
| 18 | + |
| 19 | + it("delegates clear through the storage lock and backup resolver", async () => { |
| 20 | + const clearFlaggedAccountsOnDisk = vi.fn(async () => undefined); |
| 21 | + await clearFlaggedAccountsEntry({ |
| 22 | + path: "/tmp/flagged.json", |
| 23 | + withStorageLock: async (fn) => fn(), |
| 24 | + markerPath: "/tmp/flagged.marker", |
| 25 | + getBackupPaths: async () => ["/tmp/flagged.json.bak"], |
| 26 | + clearFlaggedAccountsOnDisk, |
| 27 | + logError: vi.fn(), |
| 28 | + }); |
| 29 | + |
| 30 | + expect(clearFlaggedAccountsOnDisk).toHaveBeenCalledWith({ |
| 31 | + path: "/tmp/flagged.json", |
| 32 | + markerPath: "/tmp/flagged.marker", |
| 33 | + backupPaths: ["/tmp/flagged.json.bak"], |
| 34 | + logError: expect.any(Function), |
| 35 | + }); |
| 36 | + }); |
| 37 | +}); |
0 commit comments