@fatagnus/convex-feedback 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,185 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { generateBugPrompt, generateFeedbackPrompt } from "./prompts";
3
+
4
+ describe("Prompt Generation", () => {
5
+ describe("generateBugPrompt", () => {
6
+ const baseBug = {
7
+ ticketNumber: "BUG-2025-0001",
8
+ title: "Login button not working",
9
+ description: "When I click the login button, nothing happens",
10
+ severity: "high" as const,
11
+ url: "https://app.example.com/login",
12
+ route: "/login",
13
+ browserInfo: JSON.stringify({ browser: "Chrome", version: "120" }),
14
+ consoleErrors: JSON.stringify(["TypeError: Cannot read property 'submit' of null"]),
15
+ viewportWidth: 1920,
16
+ viewportHeight: 1080,
17
+ createdAt: Date.now(),
18
+ };
19
+
20
+ it("generates fix template prompt", () => {
21
+ const prompt = generateBugPrompt(baseBug, "fix");
22
+
23
+ expect(prompt).toContain("BUG-2025-0001");
24
+ expect(prompt).toContain("Login button not working");
25
+ expect(prompt.toLowerCase()).toContain("high");
26
+ expect(prompt.toLowerCase()).toContain("fix");
27
+ });
28
+
29
+ it("generates analyze template prompt", () => {
30
+ const prompt = generateBugPrompt(baseBug, "analyze");
31
+
32
+ expect(prompt).toContain("BUG-2025-0001");
33
+ expect(prompt.toLowerCase()).toContain("analy"); // Analysis or analyze
34
+ });
35
+
36
+ it("generates codebuff template prompt", () => {
37
+ const prompt = generateBugPrompt(baseBug, "codebuff");
38
+
39
+ expect(prompt).toContain("BUG-2025-0001");
40
+ expect(prompt).toContain("Login button not working");
41
+ });
42
+
43
+ it("generates implement template prompt", () => {
44
+ const prompt = generateBugPrompt(baseBug, "implement");
45
+
46
+ expect(prompt).toContain("BUG-2025-0001");
47
+ });
48
+
49
+ it("includes AI analysis when available", () => {
50
+ const bugWithAI = {
51
+ ...baseBug,
52
+ aiSummary: "The login form submit handler is not properly bound",
53
+ aiRootCauseAnalysis: "React event handler not attached correctly",
54
+ aiSuggestedFix: "Check that the onClick handler is properly bound to the button element",
55
+ aiReproductionSteps: ["Navigate to /login", "Click login button", "Observe nothing happens"],
56
+ };
57
+
58
+ const prompt = generateBugPrompt(bugWithAI, "fix");
59
+
60
+ expect(prompt).toContain("The login form submit handler is not properly bound");
61
+ expect(prompt).toContain("React event handler not attached correctly");
62
+ expect(prompt).toContain("Check that the onClick handler is properly bound");
63
+ });
64
+
65
+ it("includes console errors when available", () => {
66
+ const prompt = generateBugPrompt(baseBug, "fix");
67
+
68
+ expect(prompt).toContain("TypeError: Cannot read property 'submit' of null");
69
+ });
70
+
71
+ it("handles missing optional fields gracefully", () => {
72
+ const minimalBug = {
73
+ ticketNumber: "BUG-2025-0002",
74
+ title: "Simple bug",
75
+ description: "A simple bug",
76
+ severity: "low" as const,
77
+ url: "https://example.com",
78
+ browserInfo: "{}",
79
+ viewportWidth: 1920,
80
+ viewportHeight: 1080,
81
+ createdAt: Date.now(),
82
+ };
83
+
84
+ const prompt = generateBugPrompt(minimalBug, "fix");
85
+
86
+ expect(prompt).toContain("BUG-2025-0002");
87
+ expect(prompt).toContain("Simple bug");
88
+ });
89
+ });
90
+
91
+ describe("generateFeedbackPrompt", () => {
92
+ const baseFeedback = {
93
+ ticketNumber: "FB-2025-0001",
94
+ type: "feature_request" as const,
95
+ title: "Add dark mode support",
96
+ description: "Please add a dark mode option for the app",
97
+ priority: "important" as const,
98
+ url: "https://app.example.com/settings",
99
+ route: "/settings",
100
+ createdAt: Date.now(),
101
+ };
102
+
103
+ it("generates implement template prompt", () => {
104
+ const prompt = generateFeedbackPrompt(baseFeedback, "implement");
105
+
106
+ expect(prompt).toContain("FB-2025-0001");
107
+ expect(prompt).toContain("Add dark mode support");
108
+ expect(prompt.toLowerCase()).toContain("feature"); // Feature Request
109
+ expect(prompt.toLowerCase()).toContain("important");
110
+ });
111
+
112
+ it("generates fix template prompt", () => {
113
+ const prompt = generateFeedbackPrompt(baseFeedback, "fix");
114
+
115
+ expect(prompt).toContain("FB-2025-0001");
116
+ });
117
+
118
+ it("generates analyze template prompt", () => {
119
+ const prompt = generateFeedbackPrompt(baseFeedback, "analyze");
120
+
121
+ expect(prompt).toContain("FB-2025-0001");
122
+ expect(prompt.toLowerCase()).toContain("analy"); // Analysis or analyze
123
+ });
124
+
125
+ it("generates codebuff template prompt", () => {
126
+ const prompt = generateFeedbackPrompt(baseFeedback, "codebuff");
127
+
128
+ expect(prompt).toContain("FB-2025-0001");
129
+ expect(prompt).toContain("Add dark mode support");
130
+ });
131
+
132
+ it("includes AI analysis when available", () => {
133
+ const feedbackWithAI = {
134
+ ...baseFeedback,
135
+ aiSummary: "User wants dark mode for better accessibility",
136
+ aiImpactAnalysis: "High user impact - many users have requested this",
137
+ aiActionItems: ["Add theme toggle", "Create dark color palette", "Persist preference"],
138
+ aiEstimatedEffort: "medium" as const,
139
+ };
140
+
141
+ const prompt = generateFeedbackPrompt(feedbackWithAI, "implement");
142
+
143
+ expect(prompt).toContain("User wants dark mode for better accessibility");
144
+ expect(prompt).toContain("High user impact");
145
+ });
146
+
147
+ it("handles change_request type", () => {
148
+ const changeRequest = {
149
+ ...baseFeedback,
150
+ type: "change_request" as const,
151
+ title: "Change button color",
152
+ };
153
+
154
+ const prompt = generateFeedbackPrompt(changeRequest, "implement");
155
+
156
+ expect(prompt.toLowerCase()).toContain("change"); // Change Request
157
+ expect(prompt).toContain("Change button color");
158
+ });
159
+
160
+ it("handles general feedback type", () => {
161
+ const generalFeedback = {
162
+ ...baseFeedback,
163
+ type: "general" as const,
164
+ title: "Great product!",
165
+ description: "I love using this app",
166
+ };
167
+
168
+ const prompt = generateFeedbackPrompt(generalFeedback, "analyze");
169
+
170
+ expect(prompt).toContain("general");
171
+ expect(prompt).toContain("Great product!");
172
+ });
173
+
174
+ it("handles critical priority", () => {
175
+ const criticalFeedback = {
176
+ ...baseFeedback,
177
+ priority: "critical" as const,
178
+ };
179
+
180
+ const prompt = generateFeedbackPrompt(criticalFeedback, "implement");
181
+
182
+ expect(prompt.toLowerCase()).toContain("critical");
183
+ });
184
+ });
185
+ });