Files
Reactive-Resume/packages/resume/src/social-meta.test.ts
T
Amruth Pillai 9d0dc36706 feat(seo): render social card metadata for public resumes
Public resume pages only produced their OpenGraph and Twitter tags client side,
so a shared link had no card at all. The server now injects them into the shell
and swaps in the resume's own title and description.

The lookup is scoped to public, password-free resumes and deliberately avoids
resumeService.getBySlug: that counts a view and would expose a protected
resume's summary to an unauthenticated crawler. User-authored values are escaped
before they reach the HTML, and any lookup failure falls back to the plain shell.

getResumeSocialMeta is shared with the client route head so the two cannot drift.
2026-08-17 22:19:52 +02:00

49 lines
1.9 KiB
TypeScript

import type { ResumeData } from "@reactive-resume/schema/resume/data";
import { describe, expect, it } from "vitest";
import { getResumeSocialMeta } from "./social-meta";
const buildData = (overrides: { name?: string; headline?: string; summary?: string; template?: string }): ResumeData =>
({
basics: { name: overrides.name ?? "", headline: overrides.headline ?? "" },
summary: { content: overrides.summary ?? "" },
metadata: { template: overrides.template ?? "azurill" },
}) as ResumeData;
describe("getResumeSocialMeta", () => {
it("combines the name and headline into the social title", () => {
const meta = getResumeSocialMeta(buildData({ name: "Jane Doe", headline: "Staff Engineer" }));
expect(meta.title).toBe("Jane Doe — Staff Engineer");
expect(meta.name).toBe("Jane Doe");
});
it("falls back to the resume name when the basics name is blank", () => {
const meta = getResumeSocialMeta(buildData({}), "Untitled Resume");
expect(meta.name).toBe("Untitled Resume");
expect(meta.title).toBe("Untitled Resume");
expect(meta.description).toBe("Untitled Resume");
});
it("strips markup and collapses whitespace out of the summary", () => {
const meta = getResumeSocialMeta(
buildData({ name: "Jane", summary: "<p>Builds <strong>systems</strong>\n\nat scale.</p>" }),
);
expect(meta.description).toBe("Builds systems at scale.");
});
it("prefers the headline when the summary is empty markup", () => {
const meta = getResumeSocialMeta(buildData({ name: "Jane", headline: "Staff Engineer", summary: "<p></p>" }));
expect(meta.description).toBe("Staff Engineer");
});
it("truncates a long summary on a word boundary", () => {
const meta = getResumeSocialMeta(buildData({ name: "Jane", summary: "word ".repeat(80) }));
expect(meta.description.length).toBeLessThanOrEqual(161);
expect(meta.description.endsWith("word…")).toBe(true);
});
});