feat: 完成PHP到NestJS的100%功能迁移

- 迁移25个模块,包含95个控制器和160个服务
- 新增验证码管理、登录配置、云编译等模块
- 完善认证授权、会员管理、支付系统等核心功能
- 实现完整的队列系统、配置管理、监控体系
- 确保100%功能对齐和命名一致性
- 支持生产环境部署
This commit is contained in:
万物街
2025-09-10 08:04:28 +08:00
parent a2d6a47601
commit 7a20a0c50a
551 changed files with 35628 additions and 2025 deletions

View File

@@ -93,7 +93,10 @@ describe('IndexManagerService', () => {
it('should create composite index successfully', async () => {
mockQueryRunner.query.mockResolvedValue(undefined);
await service.createIndex('test_table', 'test_composite_index', ['column1', 'column2']);
await service.createIndex('test_table', 'test_composite_index', [
'column1',
'column2',
]);
expect(mockQueryRunner.query).toHaveBeenCalledWith(
'CREATE INDEX test_composite_index ON test_table (column1, column2)',
@@ -101,10 +104,14 @@ describe('IndexManagerService', () => {
});
it('should handle index creation errors gracefully', async () => {
mockQueryRunner.query.mockRejectedValue(new Error('Index creation failed'));
mockQueryRunner.query.mockRejectedValue(
new Error('Index creation failed'),
);
// 应该不抛出异常,而是记录日志
await expect(service.createIndex('test_table', 'test_index', ['column1'])).resolves.not.toThrow();
await expect(
service.createIndex('test_table', 'test_index', ['column1']),
).resolves.not.toThrow();
});
});
@@ -182,7 +189,9 @@ describe('IndexManagerService', () => {
expect(result).toEqual(mockStats);
expect(mockQueryRunner.query).toHaveBeenCalledWith(
expect.stringContaining('performance_schema.table_io_waits_summary_by_index_usage'),
expect.stringContaining(
'performance_schema.table_io_waits_summary_by_index_usage',
),
);
});
@@ -200,8 +209,12 @@ describe('IndexManagerService', () => {
// 模拟所有索引都不存在
mockQueryRunner.query.mockResolvedValue([]);
const createIndexSpy = jest.spyOn(service, 'createIndex').mockResolvedValue(undefined);
const checkIndexSpy = jest.spyOn(service, 'checkIndexExists').mockResolvedValue(false);
const createIndexSpy = jest
.spyOn(service, 'createIndex')
.mockResolvedValue(undefined);
const checkIndexSpy = jest
.spyOn(service, 'checkIndexExists')
.mockResolvedValue(false);
await service.checkAndCreateIndexes();
@@ -214,8 +227,12 @@ describe('IndexManagerService', () => {
});
it('should skip creating existing indexes', async () => {
const createIndexSpy = jest.spyOn(service, 'createIndex').mockResolvedValue(undefined);
const checkIndexSpy = jest.spyOn(service, 'checkIndexExists').mockResolvedValue(true);
const createIndexSpy = jest
.spyOn(service, 'createIndex')
.mockResolvedValue(undefined);
const checkIndexSpy = jest
.spyOn(service, 'checkIndexExists')
.mockResolvedValue(true);
await service.checkAndCreateIndexes();
@@ -229,7 +246,9 @@ describe('IndexManagerService', () => {
describe('analyzeHotTables', () => {
it('should analyze all hot tables', async () => {
const analyzeTableSpy = jest.spyOn(service, 'analyzeTable').mockResolvedValue(undefined);
const analyzeTableSpy = jest
.spyOn(service, 'analyzeTable')
.mockResolvedValue(undefined);
await service.analyzeHotTables();
@@ -242,4 +261,4 @@ describe('IndexManagerService', () => {
analyzeTableSpy.mockRestore();
});
});
});
});

View File

@@ -65,7 +65,9 @@ describe('PerformanceMonitorService', () => {
expect(result).toEqual(mockSlowQueries);
expect(mockQueryRunner.query).toHaveBeenCalledWith(
expect.stringContaining('performance_schema.events_statements_summary_by_digest'),
expect.stringContaining(
'performance_schema.events_statements_summary_by_digest',
),
);
});
@@ -196,7 +198,9 @@ describe('PerformanceMonitorService', () => {
},
];
jest.spyOn(service, 'getQueryExecutionPlan').mockResolvedValue(mockExecutionPlan);
jest
.spyOn(service, 'getQueryExecutionPlan')
.mockResolvedValue(mockExecutionPlan);
const sql = 'SELECT * FROM member WHERE status = 1';
const result = await service.analyzeQueryPerformance(sql);
@@ -224,14 +228,18 @@ describe('PerformanceMonitorService', () => {
},
];
jest.spyOn(service, 'getQueryExecutionPlan').mockResolvedValue(mockExecutionPlan);
jest
.spyOn(service, 'getQueryExecutionPlan')
.mockResolvedValue(mockExecutionPlan);
const sql = 'SELECT * FROM member WHERE name LIKE "%test%"';
const result = await service.analyzeQueryPerformance(sql);
expect(result.analysis.hasFullTableScan).toBe(true);
expect(result.analysis.usesIndex).toBe(false);
expect(result.recommendations).toContain('查询执行了全表扫描,建议添加适当的索引');
expect(result.recommendations).toContain(
'查询执行了全表扫描,建议添加适当的索引',
);
});
});
@@ -300,11 +308,21 @@ describe('PerformanceMonitorService', () => {
describe('performanceCheck', () => {
it('should perform complete performance check', async () => {
const checkSlowQueriesSpy = jest.spyOn(service, 'checkSlowQueries').mockResolvedValue([]);
const checkTableSizesSpy = jest.spyOn(service, 'checkTableSizes').mockResolvedValue([]);
const checkIndexEfficiencySpy = jest.spyOn(service, 'checkIndexEfficiency').mockResolvedValue([]);
const getConnectionStatusSpy = jest.spyOn(service, 'getConnectionStatus').mockResolvedValue({});
const getPerformanceMetricsSpy = jest.spyOn(service, 'getPerformanceMetrics').mockResolvedValue({});
const checkSlowQueriesSpy = jest
.spyOn(service, 'checkSlowQueries')
.mockResolvedValue([]);
const checkTableSizesSpy = jest
.spyOn(service, 'checkTableSizes')
.mockResolvedValue([]);
const checkIndexEfficiencySpy = jest
.spyOn(service, 'checkIndexEfficiency')
.mockResolvedValue([]);
const getConnectionStatusSpy = jest
.spyOn(service, 'getConnectionStatus')
.mockResolvedValue({});
const getPerformanceMetricsSpy = jest
.spyOn(service, 'getPerformanceMetrics')
.mockResolvedValue({});
await service.performanceCheck();
@@ -322,7 +340,9 @@ describe('PerformanceMonitorService', () => {
});
it('should handle errors during performance check', async () => {
jest.spyOn(service, 'checkSlowQueries').mockRejectedValue(new Error('Check failed'));
jest
.spyOn(service, 'checkSlowQueries')
.mockRejectedValue(new Error('Check failed'));
jest.spyOn(service, 'checkTableSizes').mockResolvedValue([]);
jest.spyOn(service, 'checkIndexEfficiency').mockResolvedValue([]);
jest.spyOn(service, 'getConnectionStatus').mockResolvedValue({});
@@ -332,4 +352,4 @@ describe('PerformanceMonitorService', () => {
await expect(service.performanceCheck()).resolves.not.toThrow();
});
});
});
});