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>
86 lines
2.8 KiB
JavaScript
86 lines
2.8 KiB
JavaScript
describe('Batch Operations', () => {
|
|
let adminToken
|
|
let authHeaders
|
|
|
|
before(() => {
|
|
cy.getAdminToken().then(token => {
|
|
adminToken = token
|
|
authHeaders = { Authorization: `Bearer ${token}` }
|
|
})
|
|
})
|
|
|
|
describe('Batch tag operations via API', () => {
|
|
let testRecipeIds = []
|
|
|
|
before(() => {
|
|
cy.getAdminToken().then(token => {
|
|
const headers = { Authorization: `Bearer ${token}` }
|
|
// Create 3 test recipes
|
|
const recipes = ['Cypress批量1', 'Cypress批量2', 'Cypress批量3']
|
|
recipes.forEach(name => {
|
|
cy.request({
|
|
method: 'POST', url: '/api/recipes', headers,
|
|
body: { name, note: 'batch test', ingredients: [{ oil_name: '薰衣草', drops: 5 }], tags: [] }
|
|
}).then(res => testRecipeIds.push(res.body.id))
|
|
})
|
|
})
|
|
})
|
|
|
|
it('created 3 test recipes', () => {
|
|
expect(testRecipeIds).to.have.length(3)
|
|
})
|
|
|
|
it('can update tags on each recipe', () => {
|
|
testRecipeIds.forEach(id => {
|
|
cy.request({
|
|
method: 'PUT', url: `/api/recipes/${id}`, headers: authHeaders,
|
|
body: { tags: ['cypress-batch-tag'] }
|
|
}).then(res => expect(res.status).to.eq(200))
|
|
})
|
|
})
|
|
|
|
it('verifies tags were applied', () => {
|
|
cy.request({ url: '/api/recipes', headers: authHeaders }).then(res => {
|
|
const tagged = res.body.filter(r => (r.tags || []).includes('cypress-batch-tag'))
|
|
expect(tagged.length).to.be.gte(3)
|
|
})
|
|
})
|
|
|
|
it('can delete all test recipes', () => {
|
|
testRecipeIds.forEach(id => {
|
|
cy.request({
|
|
method: 'DELETE', url: `/api/recipes/${id}`, headers: authHeaders
|
|
}).then(res => expect(res.status).to.eq(200))
|
|
})
|
|
})
|
|
|
|
it('verifies recipes are deleted', () => {
|
|
cy.request({ url: '/api/recipes', headers: authHeaders }).then(res => {
|
|
const found = res.body.filter(r => r.name && r.name.startsWith('Cypress批量'))
|
|
expect(found).to.have.length(0)
|
|
})
|
|
})
|
|
|
|
after(() => {
|
|
// Cleanup tag
|
|
cy.request({ method: 'DELETE', url: '/api/tags/cypress-batch-tag', headers: authHeaders, failOnStatusCode: false })
|
|
// Cleanup any remaining test recipes
|
|
cy.request({ url: '/api/recipes', headers: authHeaders }).then(res => {
|
|
res.body.filter(r => r.name && r.name.startsWith('Cypress批量')).forEach(r => {
|
|
cy.request({ method: 'DELETE', url: `/api/recipes/${r.id}`, headers: authHeaders, failOnStatusCode: false })
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('Recipe adopt workflow (admin)', () => {
|
|
it('lists recipes and checks for owner_id field', () => {
|
|
cy.request({ url: '/api/recipes', headers: authHeaders }).then(res => {
|
|
if (res.body.length > 0) {
|
|
expect(res.body[0]).to.have.property('owner_id')
|
|
}
|
|
})
|
|
})
|
|
})
|
|
})
|