Files
golib/notify/notifications_test.go
2026-01-24 20:35:40 +11:00

90 lines
2.7 KiB
Go

package notify
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestLevelConstants verifies that all Level constants have the expected values.
func TestLevelConstants(t *testing.T) {
tests := []struct {
name string
level Level
expected string
}{
{"success level", LevelSuccess, "success"},
{"info level", LevelInfo, "info"},
{"warn level", LevelWarn, "warn"},
{"error level", LevelError, "error"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, string(tt.level))
})
}
}
// TestNotification_AllFields verifies that a Notification can be created
// with all fields populated correctly.
func TestNotification_AllFields(t *testing.T) {
action := map[string]string{"type": "redirect", "url": "/dashboard"}
notification := Notification{
Target: Target("test-target-123"),
Level: LevelSuccess,
Title: "Test Title",
Message: "Test Message",
Details: "Test Details",
Action: action,
}
assert.Equal(t, Target("test-target-123"), notification.Target)
assert.Equal(t, LevelSuccess, notification.Level)
assert.Equal(t, "Test Title", notification.Title)
assert.Equal(t, "Test Message", notification.Message)
assert.Equal(t, "Test Details", notification.Details)
assert.Equal(t, action, notification.Action)
}
// TestNotification_MinimalFields verifies that a Notification can be created
// with minimal required fields and optional fields left empty.
func TestNotification_MinimalFields(t *testing.T) {
notification := Notification{
Level: LevelInfo,
Message: "Minimal notification",
}
assert.Equal(t, Target(""), notification.Target)
assert.Equal(t, LevelInfo, notification.Level)
assert.Equal(t, "", notification.Title)
assert.Equal(t, "Minimal notification", notification.Message)
assert.Equal(t, "", notification.Details)
assert.Nil(t, notification.Action)
}
// TestNotification_EmptyFields verifies that a Notification with all empty
// fields can be created (edge case).
func TestNotification_EmptyFields(t *testing.T) {
notification := Notification{}
assert.Equal(t, Target(""), notification.Target)
assert.Equal(t, Level(""), notification.Level)
assert.Equal(t, "", notification.Title)
assert.Equal(t, "", notification.Message)
assert.Equal(t, "", notification.Details)
assert.Nil(t, notification.Action)
}
// TestTarget_Type verifies that Target is a distinct type based on string.
func TestTarget_Type(t *testing.T) {
var target Target = "test-id"
assert.Equal(t, "test-id", string(target))
}
// TestLevel_Type verifies that Level is a distinct type based on string.
func TestLevel_Type(t *testing.T) {
var level Level = "custom"
assert.Equal(t, "custom", string(level))
}