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 }) }) } }) }) })