-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.test.ts
More file actions
44 lines (40 loc) · 1.34 KB
/
bootstrap.test.ts
File metadata and controls
44 lines (40 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { describe, expect, test } from "bun:test";
import { restoreNip46Connections } from "../src/bootstrap";
describe("bootstrap", () => {
test("restoreNip46Connections attempts all persisted connections", async () => {
const started: string[] = [];
const errors: unknown[][] = [];
const originalError = console.error;
console.error = (...args: unknown[]) => {
errors.push(args);
};
try {
const repoStub = {
list: () => [
{ id: "c1", restore_failure_count: 0 },
{ id: "c2", restore_failure_count: 0 },
{ id: "c3", restore_failure_count: 0 },
],
incrementRestoreFailureCount: (_id: string) => {},
} as any;
const gatewayStub = {
startConnection: async (connectionId: string) => {
started.push(connectionId);
if (connectionId === "c2") throw new Error("boom");
},
};
await restoreNip46Connections(repoStub, gatewayStub);
expect(started).toEqual(["c1", "c2", "c3"]);
expect(errors.length).toBe(1);
const firstError = errors[0];
expect(String(firstError?.[0])).toBe(
"failed to restore nip46 connection",
);
expect((firstError?.[1] as { connectionId?: string })?.connectionId).toBe(
"c2",
);
} finally {
console.error = originalError;
}
});
});