const test = require('node:test')
const assert = require('node:assert/strict')
const request = require('supertest')
const { createApp } = require('../../src/index')

test('POST /api/health 仍返回统一结构', async () => {
    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')
})
