Something went wrong. Try again.
CLI for FastMail via JMAP
Something went wrong. Try again.
3.5 kB · 131 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132import { 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 testingfunction parseArgs(args: string[]): Record<string, string | boolean | number> { const parsed: Record<string, string | boolean | number> = {}; 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;}