package handler import ( "encoding/json" "net/http/httptest" "strconv" "strings" "testing" "time" "affiliate_dash/internal/service" "github.com/gin-gonic/gin" ) func TestDCAuthAuthorizeOldClientVersionReturns426(t *testing.T) { gin.SetMode(gin.TestMode) h := NewDCAuthHandler(service.NewDCAuthService(nil)) r := gin.New() r.POST("/api/dcauth/authorize", h.Authorize) body := `{ "app":"affiliate_dash", "challengeId":"challenge-id", "challenge":"challenge-value", "deviceId":"D1-ABCDEFGH", "publicKey":"YWJj", "signature":"ZGVm", "timestamp":` + strconv.FormatInt(time.Now().Unix(), 10) + `, "clientVersion":"1.9.9" }` req := httptest.NewRequest("POST", "/api/dcauth/authorize", strings.NewReader(body)) req.Header.Set("Content-Type", "application/json") w := httptest.NewRecorder() r.ServeHTTP(w, req) if w.Code != 426 { t.Fatalf("expected 426, got %d: %s", w.Code, w.Body.String()) } var payload struct { Code string `json:"code"` Message string `json:"message"` } if err := json.Unmarshal(w.Body.Bytes(), &payload); err != nil { t.Fatalf("decode body: %v", err) } if payload.Code != "client_outdated" { t.Fatalf("expected client_outdated, got %q", payload.Code) } }