|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import { restoreAccountsFromBackupEntry } from "../lib/storage/restore-backup-entry.js"; |
| 3 | + |
| 4 | +describe("restore backup entry", () => { |
| 5 | + it("passes path, options, and injected deps through to the restore helper", async () => { |
| 6 | + const restoreAccountsFromBackupPath = vi.fn(async () => ({ |
| 7 | + version: 3, |
| 8 | + accounts: [], |
| 9 | + activeIndex: 0, |
| 10 | + activeIndexByFamily: {}, |
| 11 | + })); |
| 12 | + const loadAccountsFromPath = vi.fn(async () => ({ normalized: null })); |
| 13 | + const saveAccounts = vi.fn(async () => undefined); |
| 14 | + |
| 15 | + const result = await restoreAccountsFromBackupEntry({ |
| 16 | + path: "/tmp/backup.json", |
| 17 | + options: { persist: false }, |
| 18 | + restoreAccountsFromBackupPath, |
| 19 | + getNamedBackupRoot: () => "/tmp/backups", |
| 20 | + getStoragePath: () => "/tmp/accounts.json", |
| 21 | + realpath: vi.fn(async (path) => path), |
| 22 | + loadAccountsFromPath, |
| 23 | + saveAccounts, |
| 24 | + }); |
| 25 | + |
| 26 | + expect(restoreAccountsFromBackupPath).toHaveBeenCalledWith( |
| 27 | + "/tmp/backup.json", |
| 28 | + expect.objectContaining({ |
| 29 | + persist: false, |
| 30 | + backupRoot: "/tmp/backups", |
| 31 | + loadAccountsFromPath, |
| 32 | + saveAccounts, |
| 33 | + }), |
| 34 | + ); |
| 35 | + expect(result).toEqual({ |
| 36 | + version: 3, |
| 37 | + accounts: [], |
| 38 | + activeIndex: 0, |
| 39 | + activeIndexByFamily: {}, |
| 40 | + }); |
| 41 | + }); |
| 42 | +}); |
0 commit comments