test: cover email provider paths in SendExternal and TestProvider

Two unit tests cover the code paths introduced when email was registered
as a recognised notification provider type in Stage 2.

- TestSendExternal_EmailProviderSkipsJSONTemplate exercises the goroutine
  warn path where an enabled email provider passes isDispatchEnabled but
  fails supportsJSONTemplates, producing a warning log without panicking
- TestTestProvider_EmailRejectsJSONTemplateStep asserts TestProvider
  returns a clear error for email providers because the JSON template
  dispatch path does not apply to email delivery

Patch coverage: 6/6 changed lines covered (100%)
This commit is contained in:
GitHub Actions
2026-03-05 06:57:37 +00:00
parent 367943b543
commit ddc79865bc
@@ -2341,6 +2341,52 @@ func TestIsDispatchEnabled_EmailDefaultFalse(t *testing.T) {
assert.True(t, svc.isDispatchEnabled("email"))
}
// TestSendExternal_EmailProviderSkipsJSONTemplate covers the goroutine branch where
// an email provider is dispatch-enabled but not in supportsJSONTemplates — it logs
// a warning and returns without calling sendJSONPayload.
func TestSendExternal_EmailProviderSkipsJSONTemplate(t *testing.T) {
db := setupNotificationTestDB(t)
_ = db.AutoMigrate(&models.Setting{})
svc := NewNotificationService(db)
// Enable the email feature flag so isDispatchEnabled("email") returns true.
require.NoError(t, db.Create(&models.Setting{
Key: notifications.FlagEmailServiceEnabled,
Value: "true",
}).Error)
provider := models.NotificationProvider{
Name: "Email Provider",
Type: "email",
URL: "recipient@example.com",
Enabled: true,
NotifyProxyHosts: true,
}
require.NoError(t, db.Create(&provider).Error)
// Must not panic; goroutine hits supportsJSONTemplates("email") == false → Warn → return.
svc.SendExternal(context.Background(), "proxy_host", "Title", "Message", nil)
time.Sleep(50 * time.Millisecond)
}
// TestTestProvider_EmailRejectsJSONTemplateStep covers the TestProvider branch where
// a supported-but-non-JSON-template type (email) returns a clear error rather than
// attempting an HTTP send.
func TestTestProvider_EmailRejectsJSONTemplateStep(t *testing.T) {
db := setupNotificationTestDB(t)
svc := NewNotificationService(db)
provider := models.NotificationProvider{
Type: "email",
URL: "recipient@example.com",
Template: "minimal",
}
err := svc.TestProvider(provider)
require.Error(t, err)
assert.Contains(t, err.Error(), "does not support JSON templates")
}
func TestTestProvider_GotifyWorksWithoutFeatureFlag(t *testing.T) {
db := setupNotificationTestDB(t)
_ = db.AutoMigrate(&models.Setting{})