import { describe, expect, test } from "bun:test"; describe("batch commands", () => { // Note: These are integration tests that would require mocking JMAP client // For now, we'll test the argument parsing logic test("parseArgs handles positional IDs", () => { const args = ["ID1", "ID2", "ID3"]; const parsed = parseArgs(args); expect(parsed._0).toBe("ID1"); expect(parsed._1).toBe("ID2"); expect(parsed._2).toBe("ID3"); expect(parsed._length).toBe(3); }); test("parseArgs handles --ids flag", () => { const args = ["--ids", "ID1,ID2,ID3"]; const parsed = parseArgs(args); expect(parsed.ids).toBe("ID1,ID2,ID3"); }); test("parseArgs handles --mailbox flag", () => { const args = ["--mailbox", "Inbox"]; const parsed = parseArgs(args); expect(parsed.mailbox).toBe("Inbox"); }); test("parseArgs handles --query flag", () => { const args = ["--query", "from:newsletter"]; const parsed = parseArgs(args); expect(parsed.query).toBe("from:newsletter"); }); test("parseArgs handles --limit flag", () => { const args = ["--limit", "100"]; const parsed = parseArgs(args); expect(parsed.limit).toBe("100"); }); test("parseArgs handles --dry-run flag", () => { const args = ["--dry-run", "--mailbox", "Inbox"]; const parsed = parseArgs(args); expect(parsed["dry-run"]).toBe(true); expect(parsed.mailbox).toBe("Inbox"); }); test("parseArgs handles --to and --from flags for move", () => { const args = ["--to", "Archive", "--from", "Inbox"]; const parsed = parseArgs(args); expect(parsed.to).toBe("Archive"); expect(parsed.from).toBe("Inbox"); }); test("parseArgs handles --permanent flag for delete", () => { const args = ["--permanent", "--mailbox", "Spam"]; const parsed = parseArgs(args); expect(parsed.permanent).toBe(true); expect(parsed.mailbox).toBe("Spam"); }); test("parseArgs handles modification flags for modify command", () => { const args = [ "--add-keyword", "$flagged", "--remove-keyword", "$seen", "--add-mailbox", "Archive", "--remove-mailbox", "Inbox", ]; const parsed = parseArgs(args); expect(parsed["add-keyword"]).toBe("$flagged"); expect(parsed["remove-keyword"]).toBe("$seen"); expect(parsed["add-mailbox"]).toBe("Archive"); expect(parsed["remove-mailbox"]).toBe("Inbox"); }); test("parseArgs handles help flags", () => { const args1 = ["--help"]; const parsed1 = parseArgs(args1); expect(parsed1.help).toBe(true); const args2 = ["-h"]; const parsed2 = parseArgs(args2); expect(parsed2.h).toBe(true); }); }); // Helper function copied from batch.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; }