package sms

import (
	"errors"
	"testing"
)

func TestIsProviderRateLimited(t *testing.T) {
	err := &ProviderError{
		Code:    "isv.BUSINESS_LIMIT_CONTROL",
		Message: "触发小时级流控Permits:5",
		Err:     ErrProviderRateLimited,
	}

	if !IsProviderRateLimited(err) {
		t.Fatalf("expected provider rate limit error")
	}
	if !errors.Is(err, ErrProviderRateLimited) {
		t.Fatalf("expected errors.Is to match provider rate limit")
	}
}

func TestProviderErrorMessage(t *testing.T) {
	err := &ProviderError{Code: "isv.INVALID_PARAMETERS", Message: "参数错误"}

	if got := err.Error(); got != "sms provider rejected: isv.INVALID_PARAMETERS: 参数错误" {
		t.Fatalf("unexpected error message: %s", got)
	}
}
