fix(notification): ensure BuildNotificationList returns an empty slice instead of nil
This commit is contained in:
@@ -25,9 +25,6 @@ func BuildNotification(item *models.Notification) *response.NotificationResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BuildNotificationList(list []models.Notification) []response.NotificationResponse {
|
func BuildNotificationList(list []models.Notification) []response.NotificationResponse {
|
||||||
if len(list) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
results := make([]response.NotificationResponse, 0, len(list))
|
results := make([]response.NotificationResponse, 0, len(list))
|
||||||
for i := range list {
|
for i := range list {
|
||||||
if item := BuildNotification(&list[i]); item != nil {
|
if item := BuildNotification(&list[i]); item != nil {
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package builders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"cs-agent/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBuildNotificationListReturnsEmptySlice(t *testing.T) {
|
||||||
|
results := BuildNotificationList([]models.Notification{})
|
||||||
|
|
||||||
|
if results == nil {
|
||||||
|
t.Fatalf("expected empty slice, got nil")
|
||||||
|
}
|
||||||
|
if len(results) != 0 {
|
||||||
|
t.Fatalf("expected empty slice, got %d items", len(results))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user