feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
This commit is contained in:
34
internal/response/response_test.go
Normal file
34
internal/response/response_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package response
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestWithDataWrapsSlicesAndMergesExtra(t *testing.T) {
|
||||
resp := WithData([]string{"a", "b"}, map[string]interface{}{
|
||||
"total": 2,
|
||||
"page": 1,
|
||||
})
|
||||
|
||||
data, ok := resp.Data.(map[string]interface{})
|
||||
if !ok {
|
||||
t.Fatalf("expected map payload, got %T", resp.Data)
|
||||
}
|
||||
if data["total"] != 2 {
|
||||
t.Fatalf("expected total=2, got %v", data["total"])
|
||||
}
|
||||
items, ok := data["items"].([]string)
|
||||
if !ok || len(items) != 2 {
|
||||
t.Fatalf("expected items slice to be preserved, got %#v", data["items"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithDataPreservesMapPayload(t *testing.T) {
|
||||
resp := WithData(map[string]interface{}{"user": "alice"}, map[string]interface{}{"page": 1})
|
||||
|
||||
data := resp.Data.(map[string]interface{})
|
||||
if data["user"] != "alice" {
|
||||
t.Fatalf("expected user=alice, got %v", data["user"])
|
||||
}
|
||||
if data["page"] != 1 {
|
||||
t.Fatalf("expected page=1, got %v", data["page"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user