Files
manyangles/apps/web/src/lib/slug.test.ts
T

19 lines
674 B
TypeScript

import { describe, expect, test } from "bun:test";
import { slugify } from "./slug";
import { eventSlugSchema } from "@album/contracts";
describe("slugify", () => {
test("keeps long generated slugs valid when truncation lands on a hyphen", () => {
const slug = slugify(`${"a".repeat(63)} next word`);
expect(slug).toBe("a".repeat(63));
expect(eventSlugSchema.safeParse(slug).success).toBe(true);
});
test("lowercases and hyphenates titles", () => {
expect(slugify("Summer Block Party")).toBe("summer-block-party");
});
test("falls back when the title has no letters", () => {
expect(slugify("!!!").startsWith("event-")).toBe(true);
});
});