| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { PromptTemplate } from ".."; |
| 3 | import { serializePromptTemplates } from "./util"; |
| 4 | |
| 5 | describe("serializePromptTemplates", () => { |
| 6 | it("should return undefined for undefined input", () => { |
| 7 | expect(serializePromptTemplates(undefined)).toBeUndefined(); |
| 8 | }); |
| 9 | |
| 10 | it("should convert function templates to empty strings", () => { |
| 11 | const functionTemplate: PromptTemplate = () => "Generated template"; |
| 12 | const templates: Record<string, PromptTemplate> = { |
| 13 | template1: functionTemplate, |
| 14 | }; |
| 15 | |
| 16 | const result = serializePromptTemplates(templates); |
| 17 | |
| 18 | expect(result).toEqual({ template1: "" }); |
| 19 | }); |
| 20 | |
| 21 | it("should pass through string templates unchanged", () => { |
| 22 | const templates: Record<string, PromptTemplate> = { |
| 23 | template1: "This is a static template", |
| 24 | template2: "Another static template", |
| 25 | }; |
| 26 | |
| 27 | const result = serializePromptTemplates(templates); |
| 28 | |
| 29 | expect(result).toEqual(templates); |
| 30 | }); |
| 31 | |
| 32 | it("should handle mixed template types", () => { |
| 33 | const functionTemplate: PromptTemplate = () => "Generated template"; |
| 34 | const templates: Record<string, PromptTemplate> = { |
| 35 | function: functionTemplate, |
| 36 | string: "This is a static template", |
| 37 | }; |
| 38 | |
| 39 | const result = serializePromptTemplates(templates); |
| 40 | |
| 41 | expect(result).toEqual({ |
| 42 | function: "", |
| 43 | string: "This is a static template", |
| 44 | }); |
| 45 | }); |
| 46 | }); |