|
1 | 1 | import { describe, it, expect } from "vitest"; |
2 | | -import { InitializeDeploymentRequestBody, RunEvent } from "./api.js"; |
| 2 | +import { InitializeDeploymentRequestBody, RunEvent, ListRunEventsResponse } from "./api.js"; |
3 | 3 | import type { InitializeDeploymentRequestBody as InitializeDeploymentRequestBodyType } from "./api.js"; |
4 | 4 |
|
5 | 5 | describe("InitializeDeploymentRequestBody", () => { |
@@ -189,10 +189,47 @@ describe("RunEvent Schema", () => { |
189 | 189 | expect(result.startTime.toISOString()).toBe("2024-03-14T00:00:00.000Z"); |
190 | 190 | }); |
191 | 191 |
|
192 | | - it("allows optional parentId", () => { |
| 192 | + it("allows optional/null parentId", () => { |
193 | 193 | const eventWithoutParent = { ...validEvent }; |
194 | 194 | delete (eventWithoutParent as any).parentId; |
195 | | - const result = RunEvent.safeParse(eventWithoutParent); |
| 195 | + expect(RunEvent.safeParse(eventWithoutParent).success).toBe(true); |
| 196 | + |
| 197 | + const eventWithNullParent = { ...validEvent, parentId: null }; |
| 198 | + expect(RunEvent.safeParse(eventWithNullParent).success).toBe(true); |
| 199 | + }); |
| 200 | +}); |
| 201 | + |
| 202 | +describe("ListRunEventsResponse Schema", () => { |
| 203 | + it("parses a valid wrapped response", () => { |
| 204 | + const response = { |
| 205 | + events: [ |
| 206 | + { |
| 207 | + spanId: "span_1", |
| 208 | + runId: "run_1", |
| 209 | + message: "Event 1", |
| 210 | + style: {}, |
| 211 | + startTime: "2024-03-14T00:00:00Z", |
| 212 | + duration: 100, |
| 213 | + isError: false, |
| 214 | + isPartial: false, |
| 215 | + isCancelled: false, |
| 216 | + level: "INFO", |
| 217 | + kind: "TASK", |
| 218 | + }, |
| 219 | + ], |
| 220 | + }; |
| 221 | + |
| 222 | + const result = ListRunEventsResponse.safeParse(response); |
196 | 223 | expect(result.success).toBe(true); |
| 224 | + if (result.success) { |
| 225 | + expect(result.data.events).toHaveLength(1); |
| 226 | + expect(result.data.events[0].spanId).toBe("span_1"); |
| 227 | + } |
| 228 | + }); |
| 229 | + |
| 230 | + it("fails on plain array", () => { |
| 231 | + const response = [{ spanId: "span_1" }]; |
| 232 | + const result = ListRunEventsResponse.safeParse(response); |
| 233 | + expect(result.success).toBe(false); |
197 | 234 | }); |
198 | 235 | }); |
0 commit comments