package auth

import (
	"strconv"
	"testing"

	jwt "github.com/golang-jwt/jwt/v5"
)

func TestVerifierParsesLargeUserIDStringWithoutPrecisionLoss(t *testing.T) {
	t.Parallel()

	const userID int64 = 399999999999990001
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
		"user_id":  strconv.FormatInt(userID, 10),
		"app_code": "lalu",
	})
	signed, err := token.SignedString([]byte("secret"))
	if err != nil {
		t.Fatalf("sign token failed: %v", err)
	}

	claims, err := NewVerifier("secret").Verify("Bearer " + signed)
	if err != nil {
		t.Fatalf("Verify failed: %v", err)
	}
	if claims.UserID != userID {
		t.Fatalf("user_id lost precision: got %d want %d", claims.UserID, userID)
	}
}
