Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

test(web): add parseAiResponse and legacy title tests

Richie McIlroy900f0318af39
diff --git a/apps/web/__tests__/unit/generate-ai-title.test.ts b/apps/web/__tests__/unit/generate-ai-title.test.ts
index c330a9749..7ebbbd04f 100644
--- a/apps/web/__tests__/unit/generate-ai-title.test.ts
+++ b/apps/web/__tests__/unit/generate-ai-title.test.ts
@@ -34,9 +34,37 @@ vi.mock("server-only", () => ({}));
import {
getAiContentGuidelines,
getAiLanguageInstruction,
+ parseAiResponse,
shouldReplaceVideoTitle,
} from "@/workflows/generate-ai";
+describe("parseAiResponse", () => {
+ it("parses JSON wrapped in model prose", () => {
+ expect(
+ parseAiResponse(
+ 'Here is the requested JSON:\n{"title":"Workflow review","summary":"I explain the workflow.","chapters":[]}',
+ ),
+ ).toEqual({
+ title: "Workflow review",
+ summary: "I explain the workflow.",
+ chapters: [],
+ });
+ });
+
+ it("rejects malformed or incomplete AI output", () => {
+ expect(() => parseAiResponse("I could not produce JSON")).toThrow();
+ expect(() =>
+ parseAiResponse('{"title":"Workflow review","summary":"'),
+ ).toThrow();
+ });
+
+ it("rejects empty required fields instead of inventing fallbacks", () => {
+ expect(() =>
+ parseAiResponse('{"title":"Generated Title","summary":"","chapters":[]}'),
+ ).toThrow();
+ });
+});
+
describe("shouldReplaceVideoTitle", () => {
it("replaces default Cap titles", () => {
expect(
@@ -75,6 +103,15 @@ describe("shouldReplaceVideoTitle", () => {
).toBe(true);
});
+ it("replaces the legacy fallback after retry metadata is cleared", () => {
+ expect(
+ shouldReplaceVideoTitle({
+ currentTitle: "Generated Title",
+ nextAiTitle: "Quarterly Roadmap Review",
+ }),
+ ).toBe(true);
+ });
+
it("replaces source-derived desktop titles", () => {
expect(
shouldReplaceVideoTitle({
@@ -113,6 +150,13 @@ describe("shouldReplaceVideoTitle", () => {
titleManuallyEdited: true,
}),
).toBe(false);
+ expect(
+ shouldReplaceVideoTitle({
+ currentTitle: "Generated Title",
+ nextAiTitle: "New Generated Title",
+ titleManuallyEdited: true,
+ }),
+ ).toBe(false);
});
it("does not replace with a blank generated title", () => {