All files / lib voiceover-script.ts

100% Statements 16/16
100% Branches 8/8
100% Functions 1/1
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54                                                9x   9x   9x   9x 6x     9x 7x 7x     9x 7x 7x     9x 7x 7x     9x   9x    
/**
 * Voiceover script generator.
 *
 * Produces a short narration script from a project's metadata (name, pro name,
 * worked areas, styles, materials, property type). Used by the Portal's
 * preview-script endpoint so a pro can see and edit the auto-generated script
 * BEFORE rendering (rather than only getting what the Worker builds at job time).
 *
 * This is the canonical API-side copy. The Worker has its own copy at
 * `apps/social-studio/src/voiceover-generator.ts` for back-compat render-time
 * fallback. A future refactor will lift both to a shared package; for now
 * keep the two identical (the Worker's copy has full test coverage).
 */
 
export interface VoiceoverScriptInput {
	projectName: string;
	proName: string;
	workedAreas: string[];
	styles: string[];
	materials: string[];
	propertyType: string | null;
}
 
export function generateVoiceoverScript(input: VoiceoverScriptInput): string {
	const { projectName, proName, workedAreas, styles, materials, propertyType } = input;
 
	const parts: string[] = [];
 
	parts.push(`Presenting ${projectName}, designed by ${proName}.`);
 
	if (propertyType) {
		parts.push(`This ${propertyType.replace(/_/g, " ")} project showcases thoughtful interior design.`);
	}
 
	if (workedAreas.length > 0) {
		const areaList = workedAreas.slice(0, 3).join(", ");
		parts.push(`Featuring beautifully designed spaces including ${areaList}.`);
	}
 
	if (styles.length > 0) {
		const styleList = styles.slice(0, 2).join(" and ");
		parts.push(`The design follows a ${styleList} style.`);
	}
 
	if (materials.length > 0) {
		const materialList = materials.slice(0, 3).join(", ");
		parts.push(`Premium materials like ${materialList} were used throughout.`);
	}
 
	parts.push(`Contact ${proName} to bring your dream interior to life.`);
 
	return parts.join(" ");
}