mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
fix: add fallback icons for notifications (#17013)
Related: https://github.com/coder/internal/issues/522
This commit is contained in:
51
coderd/inboxnotifications_internal_test.go
Normal file
51
coderd/inboxnotifications_internal_test.go
Normal file
@ -0,0 +1,51 @@
|
||||
package coderd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/notifications"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
)
|
||||
|
||||
func TestInboxNotifications_ensureNotificationIcon(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
icon string
|
||||
templateID uuid.UUID
|
||||
expectedIcon string
|
||||
}{
|
||||
{"WorkspaceCreated", "", notifications.TemplateWorkspaceCreated, codersdk.FallbackIconWorkspace},
|
||||
{"UserAccountCreated", "", notifications.TemplateUserAccountCreated, codersdk.FallbackIconAccount},
|
||||
{"TemplateDeleted", "", notifications.TemplateTemplateDeleted, codersdk.FallbackIconTemplate},
|
||||
{"TestNotification", "", notifications.TemplateTestNotification, codersdk.FallbackIconOther},
|
||||
{"TestExistingIcon", "https://cdn.coder.com/icon_notif.png", notifications.TemplateTemplateDeleted, "https://cdn.coder.com/icon_notif.png"},
|
||||
{"UnknownTemplate", "", uuid.New(), codersdk.FallbackIconOther},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
notif := codersdk.InboxNotification{
|
||||
ID: uuid.New(),
|
||||
UserID: uuid.New(),
|
||||
TemplateID: tt.templateID,
|
||||
Title: "notification title",
|
||||
Content: "notification content",
|
||||
Icon: tt.icon,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
notif = ensureNotificationIcon(notif)
|
||||
require.Equal(t, tt.expectedIcon, notif.Icon)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user