|
| 1 | +import { describe, it, expect } from "vitest" |
| 2 | +import { TaskCommandName, taskCommandSchema } from "../ipc.js" |
| 3 | + |
| 4 | +describe("IPC Types", () => { |
| 5 | + describe("TaskCommandName", () => { |
| 6 | + it("should include ResumeTask command", () => { |
| 7 | + expect(TaskCommandName.ResumeTask).toBe("ResumeTask") |
| 8 | + }) |
| 9 | + |
| 10 | + it("should have all expected task commands", () => { |
| 11 | + const expectedCommands = ["StartNewTask", "CancelTask", "CloseTask", "ResumeTask"] |
| 12 | + const actualCommands = Object.values(TaskCommandName) |
| 13 | + |
| 14 | + expectedCommands.forEach((command) => { |
| 15 | + expect(actualCommands).toContain(command) |
| 16 | + }) |
| 17 | + }) |
| 18 | + |
| 19 | + describe("Error Handling", () => { |
| 20 | + it("should handle ResumeTask command gracefully when task not found", () => { |
| 21 | + // This test verifies the schema validation - the actual error handling |
| 22 | + // for invalid task IDs is tested at the API level, not the schema level |
| 23 | + const resumeTaskCommand = { |
| 24 | + commandName: TaskCommandName.ResumeTask, |
| 25 | + data: "non-existent-task-id", |
| 26 | + } |
| 27 | + |
| 28 | + const result = taskCommandSchema.safeParse(resumeTaskCommand) |
| 29 | + expect(result.success).toBe(true) |
| 30 | + |
| 31 | + if (result.success) { |
| 32 | + expect(result.data.commandName).toBe("ResumeTask") |
| 33 | + expect(result.data.data).toBe("non-existent-task-id") |
| 34 | + } |
| 35 | + }) |
| 36 | + }) |
| 37 | + }) |
| 38 | + |
| 39 | + describe("taskCommandSchema", () => { |
| 40 | + it("should validate ResumeTask command with taskId", () => { |
| 41 | + const resumeTaskCommand = { |
| 42 | + commandName: TaskCommandName.ResumeTask, |
| 43 | + data: "task-123", |
| 44 | + } |
| 45 | + |
| 46 | + const result = taskCommandSchema.safeParse(resumeTaskCommand) |
| 47 | + expect(result.success).toBe(true) |
| 48 | + |
| 49 | + if (result.success) { |
| 50 | + expect(result.data.commandName).toBe("ResumeTask") |
| 51 | + expect(result.data.data).toBe("task-123") |
| 52 | + } |
| 53 | + }) |
| 54 | + |
| 55 | + it("should reject ResumeTask command with invalid data", () => { |
| 56 | + const invalidCommand = { |
| 57 | + commandName: TaskCommandName.ResumeTask, |
| 58 | + data: 123, // Should be string |
| 59 | + } |
| 60 | + |
| 61 | + const result = taskCommandSchema.safeParse(invalidCommand) |
| 62 | + expect(result.success).toBe(false) |
| 63 | + }) |
| 64 | + |
| 65 | + it("should reject ResumeTask command without data", () => { |
| 66 | + const invalidCommand = { |
| 67 | + commandName: TaskCommandName.ResumeTask, |
| 68 | + // Missing data field |
| 69 | + } |
| 70 | + |
| 71 | + const result = taskCommandSchema.safeParse(invalidCommand) |
| 72 | + expect(result.success).toBe(false) |
| 73 | + }) |
| 74 | + }) |
| 75 | +}) |
0 commit comments