hi-server/internal/logic/common/sendEmailCodeLogic_test.go
shanshanzhong a98fcbfe73
Some checks failed
Build docker and publish / build (20.15.1) (push) Has been cancelled
下载
2026-01-23 03:48:30 -08:00

54 lines
1.6 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.

package common
import (
"fmt"
"testing"
"github.com/perfect-panel/server/internal/config"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/pkg/constant"
"github.com/stretchr/testify/assert"
)
func TestSendEmailCodeLogic_DeleteAccountContent(t *testing.T) {
// 这是一个模拟测试,主要展示逻辑判断是否正确
// 实际运行需要 Mock Redis 和 asynq
_ = &SendEmailCodeLogic{
svcCtx: &svc.ServiceContext{
Config: config.Config{
VerifyCode: config.VerifyCode{ExpireTime: 900},
Site: config.SiteConfig{
SiteLogo: "logo.png",
SiteName: "PPanel",
},
},
},
}
code := "123456"
expireMinutes := 15
// 模拟逻辑中的覆盖逻辑
// 注意:这里我们不能直接测试 SendEmailCode 函数(因为它依赖 Redis/Asynq
// 但我们可以验证我们写的覆盖逻辑片段是否符合预期。
taskPayloadSubject := "Verification code"
taskPayloadContent := map[string]interface{}{
"Type": uint8(4),
"SiteLogo": "logo.png",
"SiteName": "PPanel",
"Expire": expireMinutes,
"Code": code,
}
// 触发我们的逻辑
if constant.ParseVerifyType(uint8(4)) == constant.DeleteAccount {
taskPayloadSubject = "注销账号验证"
taskPayloadContent["Content"] = fmt.Sprintf("您正在申请注销账号,验证码为:%s有效期 %d 分钟。如非本人操作,请忽略。", code, expireMinutes)
}
assert.Equal(t, "注销账号验证", taskPayloadSubject)
assert.Contains(t, taskPayloadContent["Content"].(string), "注销账号")
assert.Contains(t, taskPayloadContent["Content"].(string), code)
}