fix: unify handler response format in log, permission, webhook handlers
- log_handler.go: Fix GetMyLoginLogs/GetMyOperationLogs/GetLoginLogs/GetOperationLogs to use {code, message, data}
- permission_handler.go: Fix all error responses to use {code, message}
- webhook_handler.go: Add missing "message" field in success responses, wrap data in data object with list/total/page/page_size
- webhook_handler_test.go: Update test to match new response format
Standardize all JSON responses to {code: 0, message: "success", data: ...} for success
and {code: XXX, message: "..."} for errors.
This commit is contained in:
@@ -255,10 +255,8 @@ func TestWebhookHandler_ListWebhooks_Success(t *testing.T) {
|
||||
if result["code"].(float64) != 0 {
|
||||
t.Fatalf("expected code 0, got %v", result["code"])
|
||||
}
|
||||
if result["data"] == nil {
|
||||
t.Fatal("expected data in response")
|
||||
}
|
||||
if result["total"] == nil {
|
||||
data := result["data"].(map[string]interface{})
|
||||
if data["total"] == nil {
|
||||
t.Fatal("expected total in response")
|
||||
}
|
||||
}
|
||||
@@ -436,15 +434,16 @@ func TestWebhookHandler_ListWebhooks_Pagination(t *testing.T) {
|
||||
var result map[string]interface{}
|
||||
json.NewDecoder(resp.Body).Decode(&result)
|
||||
|
||||
data := result["data"].([]interface{})
|
||||
if len(data) != 2 {
|
||||
t.Fatalf("expected 2 webhooks per page, got %d", len(data))
|
||||
data := result["data"].(map[string]interface{})
|
||||
list := data["list"].([]interface{})
|
||||
if len(list) != 2 {
|
||||
t.Fatalf("expected 2 webhooks per page, got %d", len(list))
|
||||
}
|
||||
|
||||
if result["page"].(float64) != 1 {
|
||||
t.Fatalf("expected page 1, got %v", result["page"])
|
||||
if data["page"].(float64) != 1 {
|
||||
t.Fatalf("expected page 1, got %v", data["page"])
|
||||
}
|
||||
if result["page_size"].(float64) != 2 {
|
||||
t.Fatalf("expected page_size 2, got %v", result["page_size"])
|
||||
if data["page_size"].(float64) != 2 {
|
||||
t.Fatalf("expected page_size 2, got %v", data["page_size"])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user