Skip to content

Commit 1a47599

Browse files
authored
test: add test for createDoneEvent() and improve test for transformPayloadForOpenAICompatibility() (#36)
1 parent 8d6b1e0 commit 1a47599

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

test/parse.test.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,23 @@ suite("request parsing", () => {
2828

2929
test("transformPayloadForOpenAICompatibility()", (t) => {
3030
const payload = transformPayloadForOpenAICompatibility({
31-
messages: [],
31+
messages: [
32+
{
33+
role: "role",
34+
name: "name",
35+
content: "content",
36+
someCopilotKey: "value",
37+
},
38+
],
3239
someCopilotKey: "value",
3340
});
34-
t.assert.deepStrictEqual(payload.messages, []);
41+
t.assert.deepStrictEqual(payload.messages, [
42+
{
43+
role: "role",
44+
name: "name",
45+
content: "content",
46+
},
47+
]);
3548
});
3649

3750
test("verifyAndParseRequest()", async (t) => {

test/response.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ suite("response", () => {
2828
t.assert.snapshot(event.toString());
2929
});
3030

31+
test("createTextEvent()", (t) => {
32+
const event = createTextEvent("test");
33+
t.assert.equal(undefined, event.event);
34+
t.assert.snapshot(event.data);
35+
t.assert.snapshot(event.toString());
36+
});
37+
3138
test("createConfirmationEvent()", (t) => {
3239
const event = createConfirmationEvent({
3340
id: "123",

test/response.test.js.snapshot

+17
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,20 @@ exports[`response > createReferencesEvent() 1`] = `
9999
exports[`response > createReferencesEvent() 2`] = `
100100
"event: copilot_references\\ndata: [{\\"type\\":\\"test.story\\",\\"id\\":\\"test\\",\\"data\\":{\\"file\\":\\"test.js\\",\\"start\\":\\"1\\",\\"end\\":\\"42\\",\\"content\\":\\"function test() {...}\\"},\\"is_implicit\\":false,\\"metadata\\":{\\"display_name\\":\\"Lines 1-42 from test.js\\",\\"display_icon\\":\\"test-icon\\",\\"display_url\\":\\"http://github.com/monalisa/hello-world/blob/main/test.js#L1-L42\\"}}]\\n\\n"
101101
`;
102+
103+
exports[`response > createTextEvent() 1`] = `
104+
{
105+
"choices": [
106+
{
107+
"delta": {
108+
"content": "test",
109+
"role": "assistant"
110+
}
111+
}
112+
]
113+
}
114+
`;
115+
116+
exports[`response > createTextEvent() 2`] = `
117+
"data: {\\"choices\\":[{\\"delta\\":{\\"content\\":\\"test\\",\\"role\\":\\"assistant\\"}}]}\\n\\n"
118+
`;

0 commit comments

Comments
 (0)