import { describe, expect, test } from "bun:test"; describe("thread commands", () => { // Note: These tests focus on argument parsing logic // Integration tests would require mocking JMAP client test("parseArgs handles threadId positional arg", () => { const args = ["thread-123"]; const parsed = parseArgs(args); expect(parsed._0).toBe("thread-123"); expect(parsed._length).toBe(1); }); test("parseArgs handles --body-type flag for get", () => { const args = ["thread-123", "--body-type", "text"]; const parsed = parseArgs(args); expect(parsed._0).toBe("thread-123"); expect(parsed["body-type"]).toBe("text"); }); test("parseArgs handles modify flags", () => { const args = [ "thread-123", "--add-keyword", "$flagged", "--remove-keyword", "$seen", ]; const parsed = parseArgs(args); expect(parsed._0).toBe("thread-123"); expect(parsed["add-keyword"]).toBe("$flagged"); expect(parsed["remove-keyword"]).toBe("$seen"); }); test("parseArgs handles mailbox modify flags", () => { const args = [ "thread-123", "--add-mailbox", "Archive", "--remove-mailbox", "Inbox", ]; const parsed = parseArgs(args); expect(parsed._0).toBe("thread-123"); expect(parsed["add-mailbox"]).toBe("Archive"); expect(parsed["remove-mailbox"]).toBe("Inbox"); }); test("parseArgs handles help flag", () => { const args = ["--help"]; const parsed = parseArgs(args); expect(parsed.help).toBe(true); }); test("parseArgs handles short help flag", () => { const args = ["-h"]; const parsed = parseArgs(args); expect(parsed.h).toBe(true); }); test("parseArgs handles multiple flags together", () => { const args = [ "thread-123", "--add-keyword", "$seen", "--add-mailbox", "Archive", "--remove-mailbox", "Inbox", ]; const parsed = parseArgs(args); expect(parsed._0).toBe("thread-123"); expect(parsed["add-keyword"]).toBe("$seen"); expect(parsed["add-mailbox"]).toBe("Archive"); expect(parsed["remove-mailbox"]).toBe("Inbox"); expect(parsed._length).toBe(1); }); }); // Helper function copied from thread.ts for testing function parseArgs(args: string[]): Record { const parsed: Record = {}; const positional: string[] = []; for (let i = 0; i < args.length; i++) { const arg = args[i]; if (arg?.startsWith("--")) { const key = arg.slice(2); const next = args[i + 1]; if (next && !next.startsWith("-")) { parsed[key] = next; i++; } else { parsed[key] = true; } } else if (arg?.startsWith("-")) { parsed[arg.slice(1)] = true; } else if (arg) { positional.push(arg); } } // Store positional args positional.forEach((val, idx) => { parsed[`_${idx}`] = val; }); parsed._length = positional.length; return parsed; }