package walletapi

import (
	"net/http/httptest"
	"testing"
)

func TestH5RechargePaymentLanguageReadsOnlyPageQuery(t *testing.T) {
	queryRequest := httptest.NewRequest("POST", "/api/v1/recharge/h5/orders?language=zh-CN", nil)
	queryRequest.Header.Set("Accept-Language", "ar,en;q=0.9")
	if got := h5RechargePaymentLanguage(h5RechargePaymentLanguageQuery(queryRequest)); got != "zh-CN" {
		t.Fatalf("language query must win over headers, got %q", got)
	}

	legacyQueryRequest := httptest.NewRequest("POST", "/api/v1/recharge/h5/orders?lang=ar", nil)
	if got := h5RechargePaymentLanguage(h5RechargePaymentLanguageQuery(legacyQueryRequest)); got != "ar" {
		t.Fatalf("legacy lang query must still be accepted, got %q", got)
	}

	headerOnlyRequest := httptest.NewRequest("POST", "/api/v1/recharge/h5/orders", nil)
	headerOnlyRequest.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
	if got := h5RechargePaymentLanguage(h5RechargePaymentLanguageQuery(headerOnlyRequest)); got != "en" {
		t.Fatalf("missing h5 language query must default to en, got %q", got)
	}
}
