-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.test.ts
More file actions
102 lines (82 loc) · 2.83 KB
/
index.test.ts
File metadata and controls
102 lines (82 loc) · 2.83 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { describe, expect, it, vi } from "vitest";
import register from "./index.js";
function createMockApi(config: Record<string, unknown> = {}) {
return {
pluginConfig: config,
config: {},
runtime: { state: { resolveStateDir: () => "/tmp/openclaw-test" } },
logger: { info: vi.fn(), warn: vi.fn(), debug: vi.fn(), error: vi.fn() },
registerService: vi.fn(),
registerTool: vi.fn(),
on: vi.fn(),
};
}
describe("b2-backup plugin", () => {
it("registers service and gateway_stop hook when config is provided", () => {
const api = createMockApi({
keyId: "test-key",
applicationKey: "test-secret",
bucket: "test-bucket",
});
register.register(api as any);
expect(api.registerService).toHaveBeenCalledTimes(1);
expect(api.registerService).toHaveBeenCalledWith(
expect.objectContaining({ id: "b2-backup" }),
);
expect(api.on).toHaveBeenCalledWith("gateway_stop", expect.any(Function));
});
it("warns and skips when config is missing", () => {
const api = createMockApi();
register.register(api as any);
expect(api.logger.warn).toHaveBeenCalledWith(
expect.stringContaining("missing required config"),
);
expect(api.registerService).not.toHaveBeenCalled();
expect(api.on).not.toHaveBeenCalled();
});
it("exports correct plugin metadata", () => {
expect(register.id).toBe("openclaw-b2-backup");
expect(register.name).toBe("Backblaze B2 Backup");
});
it("registers before_compaction hook", () => {
const api = createMockApi({
keyId: "test-key",
applicationKey: "test-secret",
bucket: "test-bucket",
});
register.register(api as any);
expect(api.on).toHaveBeenCalledWith("before_compaction", expect.any(Function));
});
it("registers b2_rollback agent tool", () => {
const api = createMockApi({
keyId: "test-key",
applicationKey: "test-secret",
bucket: "test-bucket",
});
register.register(api as any);
expect(api.registerTool).toHaveBeenCalledTimes(1);
expect(api.registerTool).toHaveBeenCalledWith(
expect.objectContaining({
name: "b2_rollback",
execute: expect.any(Function),
}),
);
});
it("registers both gateway_stop and before_compaction hooks", () => {
const api = createMockApi({
keyId: "test-key",
applicationKey: "test-secret",
bucket: "test-bucket",
});
register.register(api as any);
expect(api.on).toHaveBeenCalledTimes(2);
const hookNames = api.on.mock.calls.map((c: unknown[]) => c[0]);
expect(hookNames).toContain("gateway_stop");
expect(hookNames).toContain("before_compaction");
});
it("does not register tool when config is missing", () => {
const api = createMockApi();
register.register(api as any);
expect(api.registerTool).not.toHaveBeenCalled();
});
});