fix/login-verification-email-template #26

Merged
moyin merged 9 commits from fix/login-verification-email-template into main 2025-12-25 20:57:25 +08:00
Showing only changes of commit 841a58886e - Show all commits

View File

@@ -221,6 +221,30 @@ describe('EmailService', () => {
);
});
it('应该成功发送登录验证码', async () => {
const options: VerificationEmailOptions = {
email: 'test@example.com',
code: '789012',
nickname: '测试用户',
purpose: 'login_verification'
};
mockTransporter.sendMail.mockResolvedValue({ messageId: 'test-id' });
configService.get.mockReturnValue('"Test Sender" <noreply@test.com>');
const result = await service.sendVerificationCode(options);
expect(result.success).toBe(true);
expect(result.isTestMode).toBe(false);
expect(mockTransporter.sendMail).toHaveBeenCalledWith(
expect.objectContaining({
to: 'test@example.com',
subject: '【Whale Town】登录验证码',
text: '您的验证码是7890125分钟内有效请勿泄露给他人。'
})
);
});
it('应该在发送失败时返回false', async () => {
const options: VerificationEmailOptions = {
email: 'test@example.com',
@@ -323,6 +347,26 @@ describe('EmailService', () => {
await service.sendVerificationCode(options);
});
it('应该生成包含验证码的登录验证模板', async () => {
const options: VerificationEmailOptions = {
email: 'test@example.com',
code: '789012',
nickname: '测试用户',
purpose: 'login_verification'
};
mockTransporter.sendMail.mockImplementation((mailOptions: any) => {
expect(mailOptions.html).toContain('789012');
expect(mailOptions.html).toContain('测试用户');
expect(mailOptions.html).toContain('登录验证码');
expect(mailOptions.html).toContain('您正在使用验证码登录');
expect(mailOptions.html).toContain('🔐');
return Promise.resolve({ messageId: 'test-id' });
});
await service.sendVerificationCode(options);
});
it('应该生成包含用户昵称的欢迎邮件模板', async () => {
mockTransporter.sendMail.mockImplementation((mailOptions: any) => {
expect(mailOptions.html).toContain('测试用户');