Loading cli/inbox.test.ts 0 → 100644 +84 −0 Original line number Diff line number Diff line import { assertEquals } from "@std/assert"; import type { InboxOptions } from "./inbox.tsx"; // mock of the tunnel disabling logic function shouldDisableTunnel(options: InboxOptions): boolean { return options.tunnel === false || options.noTunnel === true; } Deno.test("handles --no-tunnel flag correctly", () => { const optionsWithNoTunnel: InboxOptions = { tunnel: false, follow: undefined, acceptFollow: undefined, }; assertEquals( shouldDisableTunnel(optionsWithNoTunnel), true, "--no-tunnel flag should disable tunnel", ); }); Deno.test("set noTunnel true, should handles -T flag correctly", () => { const optionsWithT: InboxOptions = { tunnel: true, noTunnel: true, follow: undefined, acceptFollow: undefined, }; assertEquals( shouldDisableTunnel(optionsWithT), true, "-T flag should disable tunnel", ); }); Deno.test("handles default behavior (no flags)", () => { const optionsDefault: InboxOptions = { tunnel: true, follow: undefined, acceptFollow: undefined, }; assertEquals( shouldDisableTunnel(optionsDefault), false, "Default behavior should enable tunnel", ); }); Deno.test("handles both flags together", () => { const optionsBothFlags: InboxOptions = { tunnel: false, noTunnel: true, follow: undefined, acceptFollow: undefined, }; assertEquals( shouldDisableTunnel(optionsBothFlags), true, "Both flags should disable tunnel", ); }); Deno.test("Various InboxOptions combinations", () => { // Valid option combinations const validOptions: InboxOptions[] = [ { tunnel: true }, { tunnel: false }, { tunnel: true, noTunnel: true }, { tunnel: false, noTunnel: false }, { tunnel: true, follow: ["@user@example.com"] }, { tunnel: true, acceptFollow: ["*"] }, { tunnel: true, follow: [], acceptFollow: [] }, ]; // Test that all valid options work with shouldDisableTunnel for (const options of validOptions) { const result = shouldDisableTunnel(options); assertEquals( typeof result, "boolean", "shouldDisableTunnel must return boolean", ); } }); cli/inbox.tsx +18 −2 Original line number Diff line number Diff line Loading @@ -37,6 +37,22 @@ import { spawnTemporaryServer, type TemporaryServer } from "./tempserver.ts"; const logger = getLogger(["fedify", "cli", "inbox"]); /** * Options for the inbox command. */ export interface InboxOptions { follow?: string[]; acceptFollow?: string[]; tunnel: boolean; noTunnel?: boolean; // for -T shorthand support } export const TunnelConfig = { shouldDisableTunnel: (opts: InboxOptions): boolean => { return opts.tunnel === false || opts.noTunnel === true; } } as const; export const command = new Command() .description( "Spins up an ephemeral server that serves the ActivityPub inbox with " + Loading @@ -61,13 +77,13 @@ export const command = new Command() "-T, --no-tunnel", "Do not tunnel the ephemeral ActivityPub server to the public Internet.", ) .action(async (options) => { .action(async (options: InboxOptions) => { const spinner = ora({ text: "Spinning up an ephemeral ActivityPub server...", discardStdin: false, }).start(); const server = await spawnTemporaryServer(fetch, { noTunnel: !options.tunnel, noTunnel: TunnelConfig.shouldDisableTunnel(options), }); spinner.succeed( `The ephemeral ActivityPub server is up and running: ${ Loading Loading
cli/inbox.test.ts 0 → 100644 +84 −0 Original line number Diff line number Diff line import { assertEquals } from "@std/assert"; import type { InboxOptions } from "./inbox.tsx"; // mock of the tunnel disabling logic function shouldDisableTunnel(options: InboxOptions): boolean { return options.tunnel === false || options.noTunnel === true; } Deno.test("handles --no-tunnel flag correctly", () => { const optionsWithNoTunnel: InboxOptions = { tunnel: false, follow: undefined, acceptFollow: undefined, }; assertEquals( shouldDisableTunnel(optionsWithNoTunnel), true, "--no-tunnel flag should disable tunnel", ); }); Deno.test("set noTunnel true, should handles -T flag correctly", () => { const optionsWithT: InboxOptions = { tunnel: true, noTunnel: true, follow: undefined, acceptFollow: undefined, }; assertEquals( shouldDisableTunnel(optionsWithT), true, "-T flag should disable tunnel", ); }); Deno.test("handles default behavior (no flags)", () => { const optionsDefault: InboxOptions = { tunnel: true, follow: undefined, acceptFollow: undefined, }; assertEquals( shouldDisableTunnel(optionsDefault), false, "Default behavior should enable tunnel", ); }); Deno.test("handles both flags together", () => { const optionsBothFlags: InboxOptions = { tunnel: false, noTunnel: true, follow: undefined, acceptFollow: undefined, }; assertEquals( shouldDisableTunnel(optionsBothFlags), true, "Both flags should disable tunnel", ); }); Deno.test("Various InboxOptions combinations", () => { // Valid option combinations const validOptions: InboxOptions[] = [ { tunnel: true }, { tunnel: false }, { tunnel: true, noTunnel: true }, { tunnel: false, noTunnel: false }, { tunnel: true, follow: ["@user@example.com"] }, { tunnel: true, acceptFollow: ["*"] }, { tunnel: true, follow: [], acceptFollow: [] }, ]; // Test that all valid options work with shouldDisableTunnel for (const options of validOptions) { const result = shouldDisableTunnel(options); assertEquals( typeof result, "boolean", "shouldDisableTunnel must return boolean", ); } });
cli/inbox.tsx +18 −2 Original line number Diff line number Diff line Loading @@ -37,6 +37,22 @@ import { spawnTemporaryServer, type TemporaryServer } from "./tempserver.ts"; const logger = getLogger(["fedify", "cli", "inbox"]); /** * Options for the inbox command. */ export interface InboxOptions { follow?: string[]; acceptFollow?: string[]; tunnel: boolean; noTunnel?: boolean; // for -T shorthand support } export const TunnelConfig = { shouldDisableTunnel: (opts: InboxOptions): boolean => { return opts.tunnel === false || opts.noTunnel === true; } } as const; export const command = new Command() .description( "Spins up an ephemeral server that serves the ActivityPub inbox with " + Loading @@ -61,13 +77,13 @@ export const command = new Command() "-T, --no-tunnel", "Do not tunnel the ephemeral ActivityPub server to the public Internet.", ) .action(async (options) => { .action(async (options: InboxOptions) => { const spinner = ora({ text: "Spinning up an ephemeral ActivityPub server...", discardStdin: false, }).start(); const server = await spawnTemporaryServer(fetch, { noTunnel: !options.tunnel, noTunnel: TunnelConfig.shouldDisableTunnel(options), }); spinner.succeed( `The ephemeral ActivityPub server is up and running: ${ Loading