A CLI tool to post to Grain.social
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130import { describe, expect, test } from "bun:test";import { parseContentWarnings, validateUploadOptions } from "./gallery";import type { MediaInput } from "./types";
const agent = {} as unknown;const did = "did:plc:123";
describe("parseContentWarnings", () => { test("normalizes comma-separated labels", () => { expect(parseContentWarnings(" nudity, sexual , nudity ")).toEqual(["nudity", "sexual"]); });
test("returns empty list for undefined", () => { expect(parseContentWarnings(undefined)).toEqual([]); });});
describe("validateUploadOptions", () => { const onePathMedia: MediaInput[] = [{ kind: "path", value: "a.jpg" }];
test("rejects empty title", () => { expect(() => validateUploadOptions({ agent: agent as never, did, title: " ", mediaInputs: onePathMedia, }), ).toThrow("--title is required."); });
test("rejects when no images", () => { expect(() => validateUploadOptions({ agent: agent as never, did, title: "hello", mediaInputs: [], }), ).toThrow("Provide at least one image"); });
test("rejects more than 20 images", () => { const mediaInputs: MediaInput[] = Array.from({ length: 21 }, (_, i) => ({ kind: "path", value: `${i}.jpg` })); expect(() => validateUploadOptions({ agent: agent as never, did, title: "hello", mediaInputs, }), ).toThrow("at most 20 images"); });
test("requires location name/value pair", () => { expect(() => validateUploadOptions({ agent: agent as never, did, title: "hello", mediaInputs: onePathMedia, locationName: "St Ouen", }), ).toThrow("must be provided together"); });
test("rejects invalid image URL", () => { expect(() => validateUploadOptions({ agent: agent as never, did, title: "hello", mediaInputs: [{ kind: "url", value: "notaurl" }], }), ).toThrow("Invalid image URL"); });
test("rejects non-http image URL", () => { expect(() => validateUploadOptions({ agent: agent as never, did, title: "hello", mediaInputs: [{ kind: "url", value: "ftp://example.com/a.jpg" }], }), ).toThrow("must use http or https"); });
test("accepts valid shape", () => { expect(() => validateUploadOptions({ agent: agent as never, did, title: "hello", mediaInputs: [ { kind: "path", value: "a.jpg" }, { kind: "url", value: "https://example.com/a.jpg" }, ], locationName: "St Ouen", locationValue: "8a1862806aa7fff", exifMode: "include", }), ).not.toThrow(); });
test("rejects invalid exif mode", () => { expect(() => validateUploadOptions({ agent: agent as never, did, title: "hello", mediaInputs: [{ kind: "path", value: "a.jpg" }], exifMode: "invalid" as "include", }), ).toThrow("--exif must be either"); });
test("accepts exclude exif mode", () => { expect(() => validateUploadOptions({ agent: agent as never, did, title: "hello", mediaInputs: [{ kind: "path", value: "a.jpg" }], exifMode: "exclude", }), ).not.toThrow(); });});