forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconversion.test.ts
More file actions
64 lines (56 loc) · 1.96 KB
/
Copy pathconversion.test.ts
File metadata and controls
64 lines (56 loc) · 1.96 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
import { describe, it, expect } from "vitest";
import { convertGqlOutputToMessages } from "../conversion";
describe("getPartialArguments non-object guard", () => {
function makeActionOutput(argsFragments: string[]) {
return [
{
__typename: "ActionExecutionMessageOutput" as const,
id: "msg-1",
name: "myAction",
arguments: argsFragments,
parentMessageId: undefined,
status: { code: "Pending" },
},
];
}
it("passes through valid object arguments", () => {
const messages = convertGqlOutputToMessages(
makeActionOutput(['{"key":"val"}']) as any,
);
expect((messages[0] as any).arguments).toEqual({ key: "val" });
});
it("replaces a string argument with an empty object", () => {
const messages = convertGqlOutputToMessages(
makeActionOutput(['""']) as any,
);
expect((messages[0] as any).arguments).toEqual({});
});
it("replaces an array argument with an empty object", () => {
const messages = convertGqlOutputToMessages(
makeActionOutput(["[1,2]"]) as any,
);
expect((messages[0] as any).arguments).toEqual({});
});
it("replaces null with an empty object", () => {
const messages = convertGqlOutputToMessages(
makeActionOutput(["null"]) as any,
);
expect((messages[0] as any).arguments).toEqual({});
});
it("replaces a number with an empty object", () => {
const messages = convertGqlOutputToMessages(
makeActionOutput(["99"]) as any,
);
expect((messages[0] as any).arguments).toEqual({});
});
it("returns empty object for empty arguments array", () => {
const messages = convertGqlOutputToMessages(makeActionOutput([]) as any);
expect((messages[0] as any).arguments).toEqual({});
});
it("returns empty object for unparseable JSON", () => {
const messages = convertGqlOutputToMessages(
makeActionOutput(["{broken"]) as any,
);
expect((messages[0] as any).arguments).toEqual({});
});
});