Files
whale-town-end/src/core/utils/email/email.module.spec.ts
moyin 5af44f95d5 style: 完善代码规范和测试覆盖
- 新增多个模块的单元测试文件,提升测试覆盖率
- 完善AI-Reading文档系统,包含7步代码检查流程
- 新增集成测试和属性测试框架
- 优化项目结构和配置文件
- 清理过时的规范文档,统一使用新的检查标准
2026-01-12 20:09:03 +08:00

120 lines
3.3 KiB
TypeScript
Raw 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.
/**
* 邮件模块测试套件
*
* 功能描述:
* - 测试EmailModule的模块配置和依赖注入
* - 验证模块导入、提供者和导出的正确性
* - 确保邮件服务的正确配置
* - 测试模块间的依赖关系
*
* 测试覆盖范围:
* - 模块实例化:模块能够正确创建和初始化
* - 依赖注入:所有服务的正确注入
* - 服务导出EmailService的正确导出
* - 配置验证:邮件配置的正确性
*
* 最近修改:
* - 2026-01-12: 功能新增 - 创建EmailModule测试文件确保模块配置测试覆盖 (修改者: moyin)
*
* @author moyin
* @version 1.0.0
* @since 2026-01-12
* @lastModified 2026-01-12
*/
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigService } from '@nestjs/config';
import { EmailModule } from './email.module';
import { EmailService } from './email.service';
describe('EmailModule', () => {
let module: TestingModule;
let emailService: EmailService;
let configService: ConfigService;
beforeEach(async () => {
const mockConfigService = {
get: jest.fn((key: string, defaultValue?: any) => {
switch (key) {
case 'EMAIL_HOST':
return 'smtp.test.com';
case 'EMAIL_PORT':
return 587;
case 'EMAIL_USER':
return 'test@test.com';
case 'EMAIL_PASS':
return 'test-password';
default:
return defaultValue;
}
}),
};
module = await Test.createTestingModule({
providers: [
EmailService,
{
provide: ConfigService,
useValue: mockConfigService,
},
],
}).compile();
emailService = module.get<EmailService>(EmailService);
configService = module.get<ConfigService>(ConfigService);
});
afterEach(async () => {
if (module) {
await module.close();
}
});
it('should be defined', () => {
expect(module).toBeDefined();
});
describe('Service Providers', () => {
it('should provide EmailService', () => {
expect(emailService).toBeDefined();
expect(emailService).toBeInstanceOf(EmailService);
});
it('should provide ConfigService', () => {
expect(configService).toBeDefined();
expect(configService.get).toBeDefined();
});
});
describe('Module Dependencies', () => {
it('should import required modules', () => {
expect(module).toBeDefined();
expect(emailService).toBeDefined();
});
it('should not have circular dependencies', () => {
expect(module).toBeDefined();
});
});
describe('Module Exports', () => {
it('should export EmailService', () => {
expect(emailService).toBeDefined();
expect(emailService).toBeInstanceOf(EmailService);
});
it('should make EmailService available for injection', () => {
const service = module.get<EmailService>(EmailService);
expect(service).toBe(emailService);
});
});
describe('Configuration Validation', () => {
it('should validate email configuration completeness', () => {
expect(configService.get('EMAIL_HOST')).toBeDefined();
expect(configService.get('EMAIL_PORT')).toBeDefined();
expect(configService.get('EMAIL_USER')).toBeDefined();
expect(configService.get('EMAIL_PASS')).toBeDefined();
});
});
});