Files
platforms/backend/api/internal/logic/common/verification_availability_test.go
czl231 3ef33b531d 已完成用户APP首期功能开发
交付用户端首期页面、配套接口、后台资源及测试文档。用户APP构建、静态分析和三个管理后台构建通过;完整测试仍有2项失败,后端模型注释检查未通过,详见交付记录。
2026-09-13 00:57:32 +08:00

35 lines
1.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 功能描述未配置短信及缓存不可用时不能返回虚假验证码成功版本1.0.0。
package common
import (
"net/http/httptest"
"strings"
"testing"
"git.apinb.com/heqiapp/platforms/backend/api/internal/config"
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
"github.com/gin-gonic/gin"
)
// TestVerificationUnavailable 覆盖关闭Mock及缺少缓存的拒绝路径不连接外部服务。
func TestVerificationUnavailable(t *testing.T) {
oldEnabled, oldCache := config.Spec.Global.MockVerificationEnabled, impl.RedisService
defer func() { config.Spec.Global.MockVerificationEnabled, impl.RedisService = oldEnabled, oldCache }()
impl.RedisService = nil
for _, enabled := range []bool{false, true} {
config.Spec.Global.MockVerificationEnabled = enabled
response := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(response)
ctx.Request = httptest.NewRequest("POST", "/auth/verification-code", strings.NewReader(`{"phone":"13800000001","purpose":"set_payment_password"}`))
ctx.Request.Header.Set("Content-Type", "application/json")
SendVerificationCode("user_app")(ctx)
body := response.Body.String()
if strings.Contains(body, "request_identity") || strings.Contains(body, `"code":0`) {
t.Fatalf("不可用服务不应创建成功请求:%s", body)
}
if !enabled && !strings.Contains(body, "2410") {
t.Fatalf("关闭Mock必须说明短信尚未配置%s", body)
}
}
}