mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 08:07:40 +00:00
refactor(auto-reply): share set/unset command action parsing
This commit is contained in:
50
src/auto-reply/reply/commands-setunset.test.ts
Normal file
50
src/auto-reply/reply/commands-setunset.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseSetUnsetCommand, parseSetUnsetCommandAction } from "./commands-setunset.js";
|
||||
|
||||
describe("parseSetUnsetCommand", () => {
|
||||
it("parses unset values", () => {
|
||||
expect(
|
||||
parseSetUnsetCommand({
|
||||
slash: "/config",
|
||||
action: "unset",
|
||||
args: "foo.bar",
|
||||
}),
|
||||
).toEqual({ kind: "unset", path: "foo.bar" });
|
||||
});
|
||||
|
||||
it("parses set values", () => {
|
||||
expect(
|
||||
parseSetUnsetCommand({
|
||||
slash: "/config",
|
||||
action: "set",
|
||||
args: 'foo.bar={"x":1}',
|
||||
}),
|
||||
).toEqual({ kind: "set", path: "foo.bar", value: { x: 1 } });
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseSetUnsetCommandAction", () => {
|
||||
it("returns null for non set/unset actions", () => {
|
||||
const result = parseSetUnsetCommandAction({
|
||||
slash: "/config",
|
||||
action: "show",
|
||||
args: "",
|
||||
onSet: (path, value) => ({ action: "set", path, value }),
|
||||
onUnset: (path) => ({ action: "unset", path }),
|
||||
onError: (message) => ({ action: "error", message }),
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("maps parse errors through onError", () => {
|
||||
const result = parseSetUnsetCommandAction({
|
||||
slash: "/config",
|
||||
action: "set",
|
||||
args: "",
|
||||
onSet: (path, value) => ({ action: "set", path, value }),
|
||||
onUnset: (path) => ({ action: "unset", path }),
|
||||
onError: (message) => ({ action: "error", message }),
|
||||
});
|
||||
expect(result).toEqual({ action: "error", message: "Usage: /config set path=value" });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user