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>
78 lines
2.5 KiB
JavaScript
78 lines
2.5 KiB
JavaScript
describe('Projects Flow', () => {
|
|
let adminToken
|
|
let authHeaders
|
|
let testProjectId = null
|
|
|
|
before(() => {
|
|
cy.getAdminToken().then(token => {
|
|
adminToken = token
|
|
authHeaders = { Authorization: `Bearer ${token}` }
|
|
})
|
|
})
|
|
|
|
it('creates a project', () => {
|
|
cy.request({
|
|
method: 'POST', url: '/api/projects', headers: authHeaders,
|
|
body: {
|
|
name: 'Cypress测试项目',
|
|
ingredients: [{ oil: '薰衣草', drops: 5 }, { oil: '乳香', drops: 3 }],
|
|
selling_price: 100,
|
|
note: 'E2E test project'
|
|
}
|
|
}).then(res => {
|
|
expect(res.status).to.be.oneOf([200, 201])
|
|
testProjectId = res.body.id
|
|
})
|
|
})
|
|
|
|
it('lists projects', () => {
|
|
cy.request({ url: '/api/projects', headers: authHeaders }).then(res => {
|
|
expect(res.body).to.be.an('array')
|
|
const found = res.body.find(p => p.name === 'Cypress测试项目')
|
|
expect(found).to.exist
|
|
testProjectId = found.id
|
|
})
|
|
})
|
|
|
|
it('updates the project', () => {
|
|
cy.request({ url: '/api/projects', headers: authHeaders }).then(res => {
|
|
const found = res.body.find(p => p.name === 'Cypress测试项目')
|
|
testProjectId = found.id
|
|
cy.request({
|
|
method: 'PUT', url: `/api/projects/${testProjectId}`, headers: authHeaders,
|
|
body: { selling_price: 200, note: 'updated pricing' }
|
|
}).then(r => expect(r.status).to.eq(200))
|
|
})
|
|
})
|
|
|
|
it('verifies update', () => {
|
|
cy.request({ url: '/api/projects', headers: authHeaders }).then(res => {
|
|
const found = res.body.find(p => p.name === 'Cypress测试项目')
|
|
expect(found).to.exist
|
|
expect(found.note).to.eq('updated pricing')
|
|
expect(found.selling_price).to.eq(200)
|
|
})
|
|
})
|
|
|
|
it('deletes the project', () => {
|
|
cy.request({ url: '/api/projects', headers: authHeaders }).then(res => {
|
|
const found = res.body.find(p => p.name === 'Cypress测试项目')
|
|
if (found) {
|
|
cy.request({
|
|
method: 'DELETE', url: `/api/projects/${found.id}`, headers: authHeaders
|
|
}).then(r => expect(r.status).to.eq(200))
|
|
}
|
|
})
|
|
})
|
|
|
|
after(() => {
|
|
cy.request({ url: '/api/projects', headers: authHeaders, failOnStatusCode: false }).then(res => {
|
|
if (res.status === 200 && Array.isArray(res.body)) {
|
|
res.body.filter(p => p.name && p.name.includes('Cypress')).forEach(p => {
|
|
cy.request({ method: 'DELETE', url: `/api/projects/${p.id}`, headers: authHeaders, failOnStatusCode: false })
|
|
})
|
|
}
|
|
})
|
|
})
|
|
})
|