File size: 4,594 Bytes
453b50d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { describe, it, expect, vi, beforeEach } from "vitest";
import { generateMarketingContent } from "./contentGenerator";

// Mock the invokeLLM function
vi.mock("./_core/llm", () => ({
  invokeLLM: vi.fn(),
}));

describe("contentGenerator", () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it("should generate sales copy with required fields", async () => {
    const { invokeLLM } = await import("./_core/llm");
    
    (invokeLLM as any).mockResolvedValue({
      choices: [
        {
          message: {
            content:
              "Introducing the Ultimate Product! Transform your life with our revolutionary solution. Limited time offer - get 50% off today!",
          },
        },
      ],
    });

    const result = await generateMarketingContent({
      contentType: "sales_copy",
      productName: "Amazing Widget",
      productDescription: "A revolutionary product that changes everything",
      targetAudience: "Tech enthusiasts",
      tone: "Energetic",
    });

    expect(result.content).toBeTruthy();
    expect(result.prompt).toContain("Amazing Widget");
    expect(result.prompt).toContain("Tech enthusiasts");
  });

  it("should generate product description", async () => {
    const { invokeLLM } = await import("./_core/llm");
    
    (invokeLLM as any).mockResolvedValue({
      choices: [
        {
          message: {
            content:
              "The Amazing Widget is a state-of-the-art device designed for modern consumers. Features include durability, ease of use, and exceptional performance.",
          },
        },
      ],
    });

    const result = await generateMarketingContent({
      contentType: "product_description",
      productName: "Amazing Widget",
      keyFeatures: "Durable, Easy to use, High performance",
    });

    expect(result.content).toContain("Amazing Widget");
    expect(result.prompt).toContain("product description");
  });

  it("should generate ad text", async () => {
    const { invokeLLM } = await import("./_core/llm");
    
    (invokeLLM as any).mockResolvedValue({
      choices: [
        {
          message: {
            content:
              "Headline: Transform Your Life Today\nBody: Discover the power of our innovative solution. Click now for exclusive savings!",
          },
        },
      ],
    });

    const result = await generateMarketingContent({
      contentType: "ad_text",
      productName: "Life Transformer Pro",
      targetAudience: "Busy professionals",
    });

    expect(result.content).toBeTruthy();
    expect(result.prompt).toContain("ad copy");
  });

  it("should generate email template", async () => {
    const { invokeLLM } = await import("./_core/llm");
    
    (invokeLLM as any).mockResolvedValue({
      choices: [
        {
          message: {
            content:
              "Subject: Exclusive Offer Just for You!\n\nDear Valued Customer,\n\nWe're excited to introduce our latest product...\n\nBest regards,\nThe Team",
          },
        },
      ],
    });

    const result = await generateMarketingContent({
      contentType: "email_template",
      productName: "Premium Service",
      tone: "Professional",
    });

    expect(result.content).toContain("Subject:");
    expect(result.prompt).toContain("email template");
  });

  it("should handle errors gracefully", async () => {
    const { invokeLLM } = await import("./_core/llm");
    
    (invokeLLM as any).mockRejectedValue(new Error("API Error"));

    await expect(
      generateMarketingContent({
        contentType: "sales_copy",
        productName: "Test Product",
      })
    ).rejects.toThrow("Failed to generate marketing content");
  });

  it("should include all optional parameters in prompt", async () => {
    const { invokeLLM } = await import("./_core/llm");
    
    (invokeLLM as any).mockResolvedValue({
      choices: [
        {
          message: {
            content: "Generated content",
          },
        },
      ],
    });

    const result = await generateMarketingContent({
      contentType: "sales_copy",
      productName: "Premium Widget",
      productDescription: "High-quality widget",
      targetAudience: "Luxury buyers",
      tone: "Sophisticated",
      keyFeatures: "Premium, Durable, Elegant",
    });

    expect(result.prompt).toContain("Premium Widget");
    expect(result.prompt).toContain("High-quality widget");
    expect(result.prompt).toContain("Luxury buyers");
    expect(result.prompt).toContain("Sophisticated");
    expect(result.prompt).toContain("Premium, Durable, Elegant");
  });
});