- Expand batch upload list area and optimize preview image layout - Improve upload speed tracking and display (server-side & client-side) - Reduce network detection log noise - Optimize Docker build process (caching, env validation) - Add shadow environment deployment support
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
/**
|
|
* R22 测试:健康检查端点
|
|
*
|
|
* 验证:
|
|
* 1. 端点文件存在
|
|
* 2. 支持 GET 和 HEAD 方法
|
|
* 3. 检查数据库连接
|
|
* 4. 返回正确的状态结构
|
|
*/
|
|
|
|
describe('R22: 健康检查端点', () => {
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const healthPath = path.join(__dirname, '..', '..', 'app', 'api', 'health', 'route.ts')
|
|
|
|
it('健康检查端点文件应该存在', () => {
|
|
expect(fs.existsSync(healthPath)).toBe(true)
|
|
})
|
|
|
|
it('应该导出 GET 方法', () => {
|
|
const content = fs.readFileSync(healthPath, 'utf-8')
|
|
expect(content).toContain('export async function GET')
|
|
})
|
|
|
|
it('应该导出 HEAD 方法', () => {
|
|
const content = fs.readFileSync(healthPath, 'utf-8')
|
|
expect(content).toContain('export async function HEAD')
|
|
})
|
|
|
|
it('应该检查数据库连接', () => {
|
|
const content = fs.readFileSync(healthPath, 'utf-8')
|
|
// 检查是否使用 prisma 进行数据库检查
|
|
expect(content).toContain('prisma')
|
|
expect(content).toContain('SELECT 1')
|
|
})
|
|
|
|
it('应该返回健康状态结构', () => {
|
|
const content = fs.readFileSync(healthPath, 'utf-8')
|
|
// 检查返回的状态结构
|
|
expect(content).toContain("status: 'healthy'")
|
|
expect(content).toContain('timestamp')
|
|
expect(content).toContain('uptime')
|
|
expect(content).toContain('checks')
|
|
})
|
|
|
|
it('不健康时应该返回 503 状态码', () => {
|
|
const content = fs.readFileSync(healthPath, 'utf-8')
|
|
// 检查错误处理
|
|
expect(content).toContain("status === 'unhealthy'")
|
|
expect(content).toContain('503')
|
|
})
|
|
|
|
it('应该有 R22 修复说明', () => {
|
|
const content = fs.readFileSync(healthPath, 'utf-8')
|
|
expect(content).toContain('R22修复')
|
|
})
|
|
|
|
it('应该禁止缓存', () => {
|
|
const content = fs.readFileSync(healthPath, 'utf-8')
|
|
expect(content).toContain('Cache-Control')
|
|
expect(content).toContain('no-store')
|
|
})
|
|
})
|