Files
go-sms-V2/internal/api/http/v1/channel_link_receipts_test.go
T

41 lines
1.6 KiB
Go

// channel_link_receipts_test.go(原 Day39):链路状态/回执复核端点(发送真实性 WEB 验收)。
package v1
import (
"net/http"
"strings"
"testing"
)
// TestAPI_LinkStatusAndReceipts link-status(未建链 running=false)/receipts(空列表)/404。
func TestAPI_LinkStatusAndReceipts(t *testing.T) {
r := newD35Router(t)
adminTok := d25Token(t, 1, "admin")
// 建一条 http 通道(未建链)。
w := doReqBody(r, http.MethodPost, "/api/v1/channels", adminTok, "application/json",
[]byte(`{"name":"d39","code":"d39-ch","protocol":"http","host":"http://127.0.0.1:1"}`))
if w.Code != http.StatusOK {
t.Fatalf("创建通道 = %d: %s", w.Code, w.Body.String())
}
// link-status:未建链 → running=false 视图。
w = doReq(r, http.MethodGet, "/api/v1/channels/1/link-status", adminTok)
if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), `"running":false`) {
t.Fatalf("link-status = %d: %s", w.Code, w.Body.String())
}
// receipts:空列表。
w = doReq(r, http.MethodGet, "/api/v1/channels/1/receipts?limit=10", adminTok)
if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), `"list":[]`) {
t.Fatalf("receipts = %d: %s", w.Code, w.Body.String())
}
// 不存在通道 → 404 业务错误。
w = doReq(r, http.MethodGet, "/api/v1/channels/999/link-status", adminTok)
if w.Code != http.StatusNotFound {
t.Fatalf("999 link-status = %d, 期望 404", w.Code)
}
w = doReq(r, http.MethodGet, "/api/v1/channels/999/receipts", adminTok)
if w.Code != http.StatusNotFound {
t.Fatalf("999 receipts = %d, 期望 404", w.Code)
}
}