Files
likedream/internal/application/cpdaily/login/sms_test.go
T
2025-12-02 10:17:47 +08:00

44 lines
1.1 KiB
Go

package login
import (
"context"
"fmt"
"likedream-goframe/internal/application/cookiejar"
"testing"
"github.com/gogf/gf/v2/os/gctx"
)
const (
testSmsPhoneNumber = ""
testSmsCode = ""
)
func TestSmsLoginHandler_SendSms(t *testing.T) {
handler := SmsLoginHandler{}
data := handler.SendSms(context.Background(), testSmsPhoneNumber)
t.Logf("SendSms Data: %+v", data)
}
func TestSmsLoginHandler_LoginByCode(t *testing.T) {
handler := SmsLoginHandler{}
jar := cookiejar.NewPersistCookieJar()
data := handler.LoginByCode(context.Background(), testSmsPhoneNumber, testSmsCode, jar)
t.Logf("LoginByCode Data: %+v", data)
handler.SetLoginCookie(context.Background(), jar, data)
}
func TestLogin(t *testing.T) {
handler := SmsLoginHandler{}
ctx := gctx.GetInitCtx()
sendSmsData := handler.SendSms(ctx, testSmsPhoneNumber)
// 读取验证码手动输入
var code string
println("请输入收到的验证码:")
_, _ = fmt.Scanln(&code)
loginData := handler.LoginByCode(ctx, testSmsPhoneNumber, code, sendSmsData.CookieJar)
handler.SetLoginCookie(ctx, sendSmsData.CookieJar, loginData)
}