Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 12s
Test / e2e-test (push) Failing after 2m14s
根本原因: 所有测试硬编码了只在生产环境有效的admin token, CI创建新数据库时token不同导致全部认证失败。 修复: - CI: 设置已知ADMIN_TOKEN环境变量传给后端和Cypress - cypress/support/e2e.js: 新增cy.getAdminToken()动态获取token - 24个spec文件: 硬编码token改为cy.getAdminToken() - UI选择器: 适配管理页面从tab移到UserMenu、编辑器DOM变化 - API: create_recipe→share_recipe、ingredients格式、权限变化 - 超时: 300s→420s适应32个spec Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
describe('API Health Check', () => {
|
|
let adminToken
|
|
|
|
before(() => {
|
|
cy.getAdminToken().then(token => { adminToken = token })
|
|
})
|
|
|
|
it('GET /api/version returns version', () => {
|
|
cy.request('/api/version').then(res => {
|
|
expect(res.status).to.eq(200)
|
|
expect(res.body).to.have.property('version')
|
|
})
|
|
})
|
|
|
|
it('GET /api/oils returns oil list', () => {
|
|
cy.request('/api/oils').then(res => {
|
|
expect(res.status).to.eq(200)
|
|
expect(res.body).to.be.an('array')
|
|
expect(res.body.length).to.be.gte(1)
|
|
const oil = res.body[0]
|
|
expect(oil).to.have.property('name')
|
|
expect(oil).to.have.property('bottle_price')
|
|
expect(oil).to.have.property('drop_count')
|
|
})
|
|
})
|
|
|
|
it('GET /api/recipes returns recipe list', () => {
|
|
cy.request('/api/recipes').then(res => {
|
|
expect(res.status).to.eq(200)
|
|
expect(res.body).to.be.an('array')
|
|
if (res.body.length > 0) {
|
|
const recipe = res.body[0]
|
|
expect(recipe).to.have.property('name')
|
|
expect(recipe).to.have.property('ingredients')
|
|
}
|
|
})
|
|
})
|
|
|
|
it('GET /api/tags returns tags array', () => {
|
|
cy.request('/api/tags').then(res => {
|
|
expect(res.status).to.eq(200)
|
|
expect(res.body).to.be.an('array')
|
|
})
|
|
})
|
|
|
|
it('GET /api/me returns anonymous user without auth', () => {
|
|
cy.request('/api/me').then(res => {
|
|
expect(res.status).to.eq(200)
|
|
expect(res.body.username).to.eq('anonymous')
|
|
expect(res.body.role).to.eq('viewer')
|
|
})
|
|
})
|
|
|
|
it('GET /api/me returns authenticated user with valid token', () => {
|
|
cy.request({
|
|
url: '/api/me',
|
|
headers: { Authorization: `Bearer ${adminToken}` }
|
|
}).then(res => {
|
|
expect(res.status).to.eq(200)
|
|
expect(res.body.id).to.not.be.null
|
|
expect(res.body.username).to.not.eq('anonymous')
|
|
})
|
|
})
|
|
})
|