Something went wrong. Try again.
CLI for FastMail via JMAP
Something went wrong. Try again.
3.0 kB · 119 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120import { 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 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;}