Expand test suite to 364 tests (168 unit + 196 E2E)
Unit tests: - Volume/dilution calculation (63 tests): scaling, mode detection, ratio calculation, real recipe round-trip verification E2E tests: - Batch operations: create/tag/delete 3 recipes, adopt workflow - Projects: CRUD, pricing, profit calculation vs oil costs - Notifications: fetch, fields, mark-all-read - Account settings: profile read/update, auth rejection - Category modules: listing, tag reference - Registration: register, login, duplicate rejection - Audit log: pagination, field validation, action tracking Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
85
frontend/cypress/e2e/projects-flow.cy.js
Normal file
85
frontend/cypress/e2e/projects-flow.cy.js
Normal file
@@ -0,0 +1,85 @@
|
||||
describe('Projects Flow', () => {
|
||||
const ADMIN_TOKEN = 'c86ae7afbe10fabe3c1d5e1a7fee74feaadfd5dc7be2ab62'
|
||||
const authHeaders = { Authorization: `Bearer ${ADMIN_TOKEN}` }
|
||||
let testProjectId = null
|
||||
|
||||
it('creates a project', () => {
|
||||
cy.request({
|
||||
method: 'POST', url: '/api/projects', headers: authHeaders,
|
||||
body: {
|
||||
name: 'Cypress测试项目',
|
||||
ingredients: JSON.stringify([{ oil: '薰衣草', drops: 5 }, { oil: '乳香', drops: 3 }]),
|
||||
pricing: 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 pricing', () => {
|
||||
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: { pricing: 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.pricing).to.eq(200)
|
||||
})
|
||||
})
|
||||
|
||||
it('project profit calculation is correct', () => {
|
||||
// Fetch oils to calculate expected cost
|
||||
cy.request('/api/oils').then(oilRes => {
|
||||
const oilMap = {}
|
||||
oilRes.body.forEach(o => { oilMap[o.name] = o.bottle_price / o.drop_count })
|
||||
|
||||
cy.request({ url: '/api/projects', headers: authHeaders }).then(res => {
|
||||
const proj = res.body.find(p => p.name === 'Cypress测试项目')
|
||||
const ings = JSON.parse(proj.ingredients)
|
||||
const cost = ings.reduce((s, i) => s + (oilMap[i.oil] || 0) * i.drops, 0)
|
||||
const profit = proj.pricing - cost
|
||||
expect(profit).to.be.gt(0) // pricing(200) > cost
|
||||
expect(cost).to.be.gt(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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 })
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user