2026-03-20 18:32:58 +08:00
|
|
|
const test = require('node:test')
|
|
|
|
|
const assert = require('node:assert/strict')
|
|
|
|
|
const request = require('supertest')
|
|
|
|
|
const { createApp } = require('../../src/index')
|
2026-03-20 22:13:06 +08:00
|
|
|
|
|
|
|
|
test('POST /api/health 仍返回统一结构', async () => {
|
2026-03-20 18:32:58 +08:00
|
|
|
const app = createApp()
|
|
|
|
|
const response = await request(app).post('/api/health').send({})
|
|
|
|
|
|
|
|
|
|
assert.equal(response.status, 200)
|
|
|
|
|
assert.equal(response.body.code, 200)
|
|
|
|
|
assert.equal(response.body.msg, '服务运行正常')
|
|
|
|
|
assert.equal(response.body.data.status, 'healthy')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('未匹配路由返回统一 404', async () => {
|
|
|
|
|
const app = createApp()
|
|
|
|
|
const response = await request(app).get('/not-found-route')
|
|
|
|
|
|
|
|
|
|
assert.equal(response.status, 404)
|
|
|
|
|
assert.equal(response.body.code, 404)
|
|
|
|
|
assert.equal(response.body.msg, 'Route not found')
|
|
|
|
|
assert.equal(response.body.data.path, '/not-found-route')
|
|
|
|
|
})
|