package app

import (
	"strings"
	"testing"

	"hyapp/services/gateway-service/internal/config"
	httptransport "hyapp/services/gateway-service/internal/transport/http"
)

func TestConfigureAuthRateLimitRequiresRedisAddrWhenEnabled(t *testing.T) {
	handler := httptransport.NewHandler(nil)
	_, err := configureAuthRateLimit(handler, config.AuthRateLimitConfig{
		Enabled: true,
	}, httptransport.AuthRateLimitConfig{Enabled: true})
	if err == nil || !strings.Contains(err.Error(), "redis_addr") {
		t.Fatalf("enabled auth rate limit must require redis_addr, err=%v", err)
	}
}

func TestConfigureAuthRateLimitDisabledDoesNotRequireRedis(t *testing.T) {
	handler := httptransport.NewHandler(nil)
	closeRedis, err := configureAuthRateLimit(handler, config.AuthRateLimitConfig{
		Enabled: false,
	}, httptransport.AuthRateLimitConfig{Enabled: false})
	if err != nil {
		t.Fatalf("disabled auth rate limit should not connect redis: %v", err)
	}
	if closeRedis != nil {
		t.Fatal("disabled auth rate limit must not allocate redis client")
	}
}
