Skip to content

Commit c64566f

Browse files
committed
refactor: extract named backups list facade
1 parent 6b594b9 commit c64566f

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

lib/storage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {
6161
collectNamedBackups,
6262
type NamedBackupSummary,
6363
} from "./storage/named-backups.js";
64+
import { getNamedBackupsEntry } from "./storage/named-backups-entry.js";
6465
import {
6566
findProjectRoot,
6667
getConfigDir,
@@ -794,7 +795,9 @@ export function buildNamedBackupPath(name: string): string {
794795
}
795796

796797
export async function getNamedBackups(): Promise<NamedBackupSummary[]> {
797-
return collectNamedBackups(getStoragePath(), {
798+
return getNamedBackupsEntry({
799+
getStoragePath,
800+
collectNamedBackups,
798801
loadAccountsFromPath: (path) =>
799802
loadAccountsFromPath(path, {
800803
normalizeAccountStorage,

lib/storage/named-backups-entry.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { NamedBackupSummary } from "../storage.js";
2+
3+
export async function getNamedBackupsEntry(params: {
4+
getStoragePath: () => string;
5+
collectNamedBackups: (
6+
storagePath: string,
7+
deps: {
8+
loadAccountsFromPath: (
9+
path: string,
10+
) => Promise<{ normalized: { accounts: unknown[] } | null }>;
11+
logDebug: (message: string, details: Record<string, unknown>) => void;
12+
},
13+
) => Promise<NamedBackupSummary[]>;
14+
loadAccountsFromPath: (
15+
path: string,
16+
) => Promise<{ normalized: { accounts: unknown[] } | null }>;
17+
logDebug: (message: string, details: Record<string, unknown>) => void;
18+
}): Promise<NamedBackupSummary[]> {
19+
return params.collectNamedBackups(params.getStoragePath(), {
20+
loadAccountsFromPath: params.loadAccountsFromPath,
21+
logDebug: params.logDebug,
22+
});
23+
}

test/named-backups-entry.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import { getNamedBackupsEntry } from "../lib/storage/named-backups-entry.js";
3+
4+
describe("named backups entry", () => {
5+
it("passes storage path and dependencies through to named backup collection", async () => {
6+
const collectNamedBackups = vi.fn(async () => []);
7+
const loadAccountsFromPath = vi.fn(async () => ({ normalized: null }));
8+
const logDebug = vi.fn();
9+
10+
const result = await getNamedBackupsEntry({
11+
getStoragePath: () => "/tmp/accounts.json",
12+
collectNamedBackups,
13+
loadAccountsFromPath,
14+
logDebug,
15+
});
16+
17+
expect(collectNamedBackups).toHaveBeenCalledWith("/tmp/accounts.json", {
18+
loadAccountsFromPath,
19+
logDebug,
20+
});
21+
expect(result).toEqual([]);
22+
});
23+
});

0 commit comments

Comments
 (0)