-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand-runner.test.ts
More file actions
109 lines (85 loc) · 4.05 KB
/
command-runner.test.ts
File metadata and controls
109 lines (85 loc) · 4.05 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
103
104
105
106
107
108
109
import { afterEach, describe, expect, it, vi } from "vitest";
import { CommandContext } from "./types";
const {
findMappedFunctionMock,
runMappedDomainCommandMock,
runAuctionBidCommandMock,
runAuctionBidUnbidCommandMock,
runAuctionSubgraphCommandMock,
runBaazaarListingSubgraphCommandMock,
} = vi.hoisted(() => ({
findMappedFunctionMock: vi.fn(),
runMappedDomainCommandMock: vi.fn(),
runAuctionBidCommandMock: vi.fn(),
runAuctionBidUnbidCommandMock: vi.fn(),
runAuctionSubgraphCommandMock: vi.fn(),
runBaazaarListingSubgraphCommandMock: vi.fn(),
}));
vi.mock("./commands/mapped", () => ({
findMappedFunction: findMappedFunctionMock,
runMappedDomainCommand: runMappedDomainCommandMock,
}));
vi.mock("./commands/auction-bid", () => ({
runAuctionBidCommand: runAuctionBidCommandMock,
runAuctionBidUnbidCommand: runAuctionBidUnbidCommandMock,
}));
vi.mock("./commands/auction-subgraph", () => ({
runAuctionSubgraphCommand: runAuctionSubgraphCommandMock,
}));
vi.mock("./commands/baazaar-subgraph", () => ({
runBaazaarListingSubgraphCommand: runBaazaarListingSubgraphCommandMock,
}));
import { executeCommand } from "./command-runner";
function createCtx(path: string[]): CommandContext {
return {
commandPath: path,
args: { positionals: path, flags: {} },
globals: { mode: "agent", json: true, yes: true },
};
}
describe("command runner routing", () => {
afterEach(() => {
vi.clearAllMocks();
});
it("routes auction active to subgraph wrapper before mapped fallback", async () => {
findMappedFunctionMock.mockReturnValue("unexpectedMapping");
runAuctionSubgraphCommandMock.mockResolvedValue({ auctions: [] });
const result = await executeCommand(createCtx(["auction", "active"]));
expect(result.commandName).toBe("auction active");
expect(result.data).toEqual({ auctions: [] });
expect(runAuctionSubgraphCommandMock).toHaveBeenCalledTimes(1);
expect(runMappedDomainCommandMock).not.toHaveBeenCalled();
});
it("routes baazaar listing get to subgraph wrapper", async () => {
runBaazaarListingSubgraphCommandMock.mockResolvedValue({ listing: null });
const result = await executeCommand(createCtx(["baazaar", "listing", "get"]));
expect(result.commandName).toBe("baazaar listing get");
expect(result.data).toEqual({ listing: null });
expect(runBaazaarListingSubgraphCommandMock).toHaveBeenCalledTimes(1);
});
it("keeps mapped writes working for auction buy-now", async () => {
findMappedFunctionMock.mockReturnValue("buyNow");
runMappedDomainCommandMock.mockResolvedValue({ mappedMethod: "buyNow" });
const result = await executeCommand(createCtx(["auction", "buy-now"]));
expect(result.commandName).toBe("auction buy-now");
expect(result.data).toEqual({ mappedMethod: "buyNow" });
expect(runAuctionSubgraphCommandMock).not.toHaveBeenCalled();
expect(runMappedDomainCommandMock).toHaveBeenCalledTimes(1);
});
it("routes auction bid to first-class command before mapped fallback", async () => {
findMappedFunctionMock.mockReturnValue("commitBid");
runAuctionBidCommandMock.mockResolvedValue({ status: "simulated" });
const result = await executeCommand(createCtx(["auction", "bid"]));
expect(result.commandName).toBe("auction bid");
expect(result.data).toEqual({ status: "simulated" });
expect(runAuctionBidCommandMock).toHaveBeenCalledTimes(1);
expect(runMappedDomainCommandMock).not.toHaveBeenCalled();
});
it("routes auction bid-unbid to first-class batch command", async () => {
runAuctionBidUnbidCommandMock.mockResolvedValue({ summary: { success: 1 } });
const result = await executeCommand(createCtx(["auction", "bid-unbid"]));
expect(result.commandName).toBe("auction bid-unbid");
expect(result.data).toEqual({ summary: { success: 1 } });
expect(runAuctionBidUnbidCommandMock).toHaveBeenCalledTimes(1);
});
});