mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:42:43 +00:00
test(agents): dedupe cron tool mock wiring
This commit is contained in:
@@ -1,15 +1,6 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it } from "vitest";
|
||||||
|
|
||||||
const callGatewayMock = vi.fn();
|
|
||||||
vi.mock("../../gateway/call.js", () => ({
|
|
||||||
callGateway: (opts: unknown) => callGatewayMock(opts),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("../agent-scope.js", () => ({
|
|
||||||
resolveSessionAgentId: () => "agent-123",
|
|
||||||
}));
|
|
||||||
|
|
||||||
import { createCronTool } from "./cron-tool.js";
|
import { createCronTool } from "./cron-tool.js";
|
||||||
|
import { callGatewayMock, resetCronToolGatewayMock } from "./cron-tool.test-helpers.js";
|
||||||
|
|
||||||
describe("cron tool", () => {
|
describe("cron tool", () => {
|
||||||
async function executeAddAndReadDelivery(params: {
|
async function executeAddAndReadDelivery(params: {
|
||||||
@@ -35,8 +26,7 @@ describe("cron tool", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
callGatewayMock.mockReset();
|
resetCronToolGatewayMock();
|
||||||
callGatewayMock.mockResolvedValue({ ok: true });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
|
|||||||
@@ -1,20 +1,10 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it } from "vitest";
|
||||||
|
|
||||||
const callGatewayMock = vi.fn();
|
|
||||||
vi.mock("../../gateway/call.js", () => ({
|
|
||||||
callGateway: (opts: unknown) => callGatewayMock(opts),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("../agent-scope.js", () => ({
|
|
||||||
resolveSessionAgentId: () => "agent-123",
|
|
||||||
}));
|
|
||||||
|
|
||||||
import { createCronTool } from "./cron-tool.js";
|
import { createCronTool } from "./cron-tool.js";
|
||||||
|
import { callGatewayMock, resetCronToolGatewayMock } from "./cron-tool.test-helpers.js";
|
||||||
|
|
||||||
describe("cron tool flat-params", () => {
|
describe("cron tool flat-params", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
callGatewayMock.mockReset();
|
resetCronToolGatewayMock();
|
||||||
callGatewayMock.mockResolvedValue({ ok: true });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("preserves explicit top-level sessionKey during flat-params recovery", async () => {
|
it("preserves explicit top-level sessionKey during flat-params recovery", async () => {
|
||||||
|
|||||||
16
src/agents/tools/cron-tool.test-helpers.ts
Normal file
16
src/agents/tools/cron-tool.test-helpers.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { vi } from "vitest";
|
||||||
|
|
||||||
|
export const callGatewayMock = vi.fn();
|
||||||
|
|
||||||
|
vi.mock("../../gateway/call.js", () => ({
|
||||||
|
callGateway: (opts: unknown) => callGatewayMock(opts),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../agent-scope.js", () => ({
|
||||||
|
resolveSessionAgentId: () => "agent-123",
|
||||||
|
}));
|
||||||
|
|
||||||
|
export function resetCronToolGatewayMock() {
|
||||||
|
callGatewayMock.mockReset();
|
||||||
|
callGatewayMock.mockResolvedValue({ ok: true });
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user