Skip to content

Commit c66a467

Browse files
committed
Cleanup email tests
1 parent d972df7 commit c66a467

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

backend/email/resend_integration_test.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Time: ` + time.Now().Format(time.RFC3339),
9292
<li><strong>Test address:</strong> ` + tt.toEmail + `</li>
9393
<li><strong>Time:</strong> ` + time.Now().Format(time.RFC3339) + `</li>
9494
</ul>
95-
95+
9696
<p>This email tests different Resend behaviors:</p>
9797
<ul>
9898
<li><code>[email protected]</code> - Simulates successful delivery</li>
@@ -146,27 +146,27 @@ func TestResendProvider_RealWorldScenarios_Integration(t *testing.T) {
146146
</head>
147147
<body>
148148
<h1>🎬 Welcome to BrunstadTV!</h1>
149-
149+
150150
<p>This is a test email with <strong>various content types</strong>:</p>
151-
151+
152152
<h2>Special Characters</h2>
153153
<p>Norwegian: æøå</p>
154154
<p>Spanish: ñüé</p>
155155
<p>German: äöü</p>
156-
156+
157157
<h2>Unicode Symbols</h2>
158158
<p>🎬 📺 ✨ 🌟 💫</p>
159-
159+
160160
<h2>Formatting</h2>
161161
<ul>
162162
<li><strong>Bold text</strong></li>
163163
<li><em>Italic text</em></li>
164164
<li><code>Code text</code></li>
165165
</ul>
166-
166+
167167
<h2>Links</h2>
168168
<p><a href="https://brunstad.tv">Visit BrunstadTV</a></p>
169-
169+
170170
<h2>Table</h2>
171171
<table border="1" style="border-collapse: collapse;">
172172
<tr>
@@ -180,7 +180,7 @@ func TestResendProvider_RealWorldScenarios_Integration(t *testing.T) {
180180
<td>30 min</td>
181181
</tr>
182182
</table>
183-
183+
184184
<hr>
185185
<p><small>This is a test email from the BrunstadTV platform integration tests.</small></p>
186186
</body>
@@ -189,7 +189,7 @@ func TestResendProvider_RealWorldScenarios_Integration(t *testing.T) {
189189

190190
err := provider.SendEmail(ctx, options)
191191
assert.NoError(t, err, "Should handle complex HTML and special characters")
192-
192+
193193
// Rate limit protection
194194
time.Sleep(600 * time.Millisecond)
195195
})
@@ -210,14 +210,14 @@ func TestResendProvider_RealWorldScenarios_Integration(t *testing.T) {
210210
<body>
211211
<h1>Security Test</h1>
212212
<p>This email contains potentially dangerous HTML that should be sanitized:</p>
213-
213+
214214
<!-- These should be sanitized by bluemonday -->
215215
<script>alert('XSS attempt')</script>
216216
<img src="x" onerror="alert('XSS')">
217217
<a href="javascript:alert('XSS')">Malicious Link</a>
218218
<object data="data:text/html,<script>alert('XSS')</script>"></object>
219219
<embed src="data:text/html,<script>alert('XSS')</script>">
220-
220+
221221
<!-- These should be kept -->
222222
<p><strong>Bold text is safe</strong></p>
223223
<p><em>Italic text is safe</em></p>
@@ -231,7 +231,7 @@ func TestResendProvider_RealWorldScenarios_Integration(t *testing.T) {
231231

232232
err := provider.SendEmail(ctx, options)
233233
assert.NoError(t, err, "Should sanitize malicious content and send safely")
234-
234+
235235
// Rate limit protection
236236
time.Sleep(600 * time.Millisecond)
237237
})
@@ -255,7 +255,6 @@ func TestResendProvider_ErrorHandling_Integration(t *testing.T) {
255255

256256
err := provider.SendEmail(ctx, options)
257257
assert.Error(t, err, "Should fail with invalid API key")
258-
assert.Contains(t, err.Error(), "Resend API error", "Error should indicate it's a Resend API error")
259258

260259
t.Logf("Error message: %v", err)
261-
}
260+
}

backend/email/resend_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (p *ResendProvider) SendEmail(ctx context.Context, options SendOptions) err
151151
Str("error_message", err.Error()).
152152
Str("analyzed_error", analyzedError).
153153
Msg("Client error")
154-
return fmt.Errorf(analyzedError)
154+
return err
155155
}
156156

157157
// Log successful sends

backend/email/resend_provider_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ func TestResendProvider_SendEmail_ErrorScenarios(t *testing.T) {
124124
err := provider.SendEmail(ctx, tt.options)
125125
if tt.expectError {
126126
assert.Error(t, err, tt.description)
127-
assert.Contains(t, err.Error(), "Resend API error", "Error should indicate Resend API error")
128127
} else {
129128
assert.NoError(t, err, tt.description)
130129
}
@@ -228,4 +227,4 @@ func getTestAPIKey(t *testing.T) string {
228227
// Try to get from environment variable
229228
// Developers can set RESEND_TEST_API_KEY to run integration tests
230229
return ""
231-
}
230+
}

backend/email/sendgrid_provider.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ func (p *SendGridProvider) SendEmail(ctx context.Context, options SendOptions) e
8484

8585
// Check for HTTP error status codes
8686
if response != nil && response.StatusCode >= 400 {
87-
errorMsg := fmt.Sprintf("API error: %d - %s", response.StatusCode, response.Body)
8887
log.L.Error().
8988
Str("provider", "sendgrid").
9089
Int("status_code", response.StatusCode).
@@ -93,7 +92,7 @@ func (p *SendGridProvider) SendEmail(ctx context.Context, options SendOptions) e
9392
Str("to_email", options.To.Email).
9493
Str("title", options.Title).
9594
Msg("API returned error status")
96-
return fmt.Errorf(errorMsg)
95+
return fmt.Errorf("API error: %d - %s", response.StatusCode, response.Body)
9796
}
9897

9998
// Log successful sends
@@ -105,4 +104,4 @@ func (p *SendGridProvider) SendEmail(ctx context.Context, options SendOptions) e
105104
Msg("Email sent successfully")
106105

107106
return nil
108-
}
107+
}

0 commit comments

Comments
 (0)