mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-28 01:21:36 +00:00
test(cli): share nodes ios fixture helpers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createIosNodeListResponse } from "./program.nodes-test-helpers.js";
|
||||
import { callGateway, installBaseProgramMocks, runTui, runtime } from "./program.test-mocks.js";
|
||||
|
||||
installBaseProgramMocks();
|
||||
@@ -42,17 +43,7 @@ describe("cli program (nodes basics)", () => {
|
||||
callGateway.mockImplementation(async (...args: unknown[]) => {
|
||||
const opts = (args[0] ?? {}) as { method?: string };
|
||||
if (opts.method === "node.list") {
|
||||
return {
|
||||
ts: Date.now(),
|
||||
nodes: [
|
||||
{
|
||||
nodeId: "ios-node",
|
||||
displayName: "iOS Node",
|
||||
remoteIp: "192.168.0.88",
|
||||
connected: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
return createIosNodeListResponse();
|
||||
}
|
||||
if (opts.method === method) {
|
||||
return result;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as fs from "node:fs/promises";
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { parseCameraSnapPayload, parseCameraClipPayload } from "./nodes-camera.js";
|
||||
import { IOS_NODE, createIosNodeListResponse } from "./program.nodes-test-helpers.js";
|
||||
import { callGateway, installBaseProgramMocks, runTui, runtime } from "./program.test-mocks.js";
|
||||
|
||||
installBaseProgramMocks();
|
||||
@@ -48,21 +49,11 @@ function expectParserRejectsMissingMedia(
|
||||
expect(() => parse(payload)).toThrow(expectedMessage);
|
||||
}
|
||||
|
||||
const IOS_NODE = {
|
||||
nodeId: "ios-node",
|
||||
displayName: "iOS Node",
|
||||
remoteIp: "192.168.0.88",
|
||||
connected: true,
|
||||
} as const;
|
||||
|
||||
function mockNodeGateway(command?: string, payload?: Record<string, unknown>) {
|
||||
callGateway.mockImplementation(async (...args: unknown[]) => {
|
||||
const opts = (args[0] ?? {}) as { method?: string };
|
||||
if (opts.method === "node.list") {
|
||||
return {
|
||||
ts: Date.now(),
|
||||
nodes: [IOS_NODE],
|
||||
};
|
||||
return createIosNodeListResponse();
|
||||
}
|
||||
if (opts.method === "node.invoke" && command) {
|
||||
return {
|
||||
|
||||
12
src/cli/program.nodes-test-helpers.test.ts
Normal file
12
src/cli/program.nodes-test-helpers.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { IOS_NODE, createIosNodeListResponse } from "./program.nodes-test-helpers.js";
|
||||
|
||||
describe("program.nodes-test-helpers", () => {
|
||||
it("builds a node.list response with iOS node fixture", () => {
|
||||
const response = createIosNodeListResponse(1234);
|
||||
expect(response).toEqual({
|
||||
ts: 1234,
|
||||
nodes: [IOS_NODE],
|
||||
});
|
||||
});
|
||||
});
|
||||
13
src/cli/program.nodes-test-helpers.ts
Normal file
13
src/cli/program.nodes-test-helpers.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const IOS_NODE = {
|
||||
nodeId: "ios-node",
|
||||
displayName: "iOS Node",
|
||||
remoteIp: "192.168.0.88",
|
||||
connected: true,
|
||||
} as const;
|
||||
|
||||
export function createIosNodeListResponse(ts: number = Date.now()) {
|
||||
return {
|
||||
ts,
|
||||
nodes: [IOS_NODE],
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user