feat(report): improve daily intelligence UX and price tracking
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -46,3 +48,34 @@ func TestIsRetriableSubscriptionFetchErrorRecognizesForbidden(t *testing.T) {
|
||||
t.Fatalf("403 应被视作可重试错误")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchSubscriptionPageFallsBackToMarkdownSuffixOnForbidden(t *testing.T) {
|
||||
attempts := map[string]int{}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
attempts[r.URL.Path]++
|
||||
switch r.URL.Path {
|
||||
case "/cn/update/promotion":
|
||||
http.Error(w, "forbidden", http.StatusForbidden)
|
||||
case "/cn/update/promotion.md":
|
||||
_, _ = w.Write([]byte("# 上新活动\nGLM Coding Plan 低至20元/月"))
|
||||
default:
|
||||
http.Error(w, fmt.Sprintf("unexpected path %s", r.URL.Path), http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := &http.Client{Timeout: 2 * time.Second}
|
||||
body, err := fetchSubscriptionPage(server.URL+"/cn/update/promotion", "", client)
|
||||
if err != nil {
|
||||
t.Fatalf("fetchSubscriptionPage 返回错误: %v", err)
|
||||
}
|
||||
if !strings.Contains(body, "GLM Coding Plan 低至20元/月") {
|
||||
t.Fatalf("返回体缺少 markdown fallback 内容: %q", body)
|
||||
}
|
||||
if attempts["/cn/update/promotion"] != subscriptionFetchMaxAttempts {
|
||||
t.Fatalf("期望原始路径按重试上限请求 %d 次,实际 %d", subscriptionFetchMaxAttempts, attempts["/cn/update/promotion"])
|
||||
}
|
||||
if attempts["/cn/update/promotion.md"] != 1 {
|
||||
t.Fatalf("期望 .md 路径请求 1 次,实际 %d", attempts["/cn/update/promotion.md"])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user