Some checks failed
Test / unit-test (push) Successful in 6s
Test / build-check (push) Successful in 4s
PR Preview / teardown-preview (pull_request) Has been skipped
Test / e2e-test (push) Failing after 25s
PR Preview / test (pull_request) Successful in 6s
PR Preview / deploy-preview (pull_request) Successful in 15s
1. 编辑配方的滴数输入框从 42px 加宽到 58px,确保 50.5 不被 spinner 遮挡 2. 配方卡片在零售价==会员价时也显示零售价(之前因 retail>cost 过滤掉) 3. 精油价目英文名保存后被静态 OIL_CARDS 覆盖,把 getEnglishName 的优先级改 为先用 DB meta.enName,解决温柔呵护/仕女呵护等显示不更新的问题 4. 再次审核 tag 的配方被非管理员修改时,给管理员发通知,内容含前后 diff 5. 对应 vitest + cypress 测试各一组 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
93 lines
3.3 KiB
JavaScript
93 lines
3.3 KiB
JavaScript
// Verifies that when a non-admin edits a recipe tagged 再次审核,
|
|
// an admin-targeted notification is created containing a before/after diff.
|
|
describe('Re-review notification on non-admin edit', () => {
|
|
let adminToken
|
|
let viewerToken
|
|
let recipeId
|
|
|
|
before(() => {
|
|
cy.getAdminToken().then(t => {
|
|
adminToken = t
|
|
const uname = 'editor_' + Date.now()
|
|
cy.request({
|
|
method: 'POST', url: '/api/register',
|
|
body: { username: uname, password: 'pw12345678' }
|
|
}).then(res => {
|
|
viewerToken = res.body.token
|
|
// Look up user id via admin /api/users, then promote to editor
|
|
cy.request({ url: '/api/users', headers: { Authorization: `Bearer ${adminToken}` } })
|
|
.then(r => {
|
|
const u = r.body.find(x => x.username === uname)
|
|
cy.request({
|
|
method: 'PUT', url: `/api/users/${u.id}`,
|
|
headers: { Authorization: `Bearer ${adminToken}` },
|
|
body: { role: 'editor' },
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
it('creates admin notification with diff lines', () => {
|
|
// Editor creates their own recipe tagged 再次审核
|
|
cy.request({
|
|
method: 'POST', url: '/api/recipes',
|
|
headers: { Authorization: `Bearer ${viewerToken}` },
|
|
body: {
|
|
name: 're-review-fixture-' + Date.now(),
|
|
ingredients: [{ oil_name: '薰衣草', drops: 3 }],
|
|
tags: ['再次审核'],
|
|
},
|
|
}).then(res => {
|
|
recipeId = res.body.id
|
|
expect(recipeId).to.be.a('number')
|
|
})
|
|
|
|
// Mark notifications read so we can detect the new one
|
|
cy.request({
|
|
method: 'POST', url: '/api/notifications/read-all',
|
|
headers: { Authorization: `Bearer ${adminToken}` }, body: {},
|
|
})
|
|
|
|
// Non-admin edits the recipe
|
|
cy.then(() => {
|
|
cy.request({
|
|
method: 'PUT', url: `/api/recipes/${recipeId}`,
|
|
headers: { Authorization: `Bearer ${viewerToken}` },
|
|
body: {
|
|
ingredients: [{ oil_name: '薰衣草', drops: 5 }, { oil_name: '柠檬', drops: 2 }],
|
|
note: '新备注',
|
|
},
|
|
}).then(r => expect(r.status).to.eq(200))
|
|
})
|
|
|
|
// Admin sees a new unread notification mentioning the recipe and diff
|
|
cy.then(() => {
|
|
cy.request({ url: '/api/notifications', headers: { Authorization: `Bearer ${adminToken}` } })
|
|
.then(res => {
|
|
const unread = res.body.filter(n => !n.is_read && n.title && n.title.includes('再次审核配方被修改'))
|
|
expect(unread.length).to.be.greaterThan(0)
|
|
expect(unread[0].body).to.match(/成分|备注/)
|
|
expect(unread[0].body).to.contain('→')
|
|
})
|
|
})
|
|
})
|
|
|
|
it('admin edits do NOT create re-review notification', () => {
|
|
cy.request({
|
|
method: 'POST', url: '/api/notifications/read-all',
|
|
headers: { Authorization: `Bearer ${adminToken}` }, body: {},
|
|
})
|
|
cy.request({
|
|
method: 'PUT', url: `/api/recipes/${recipeId}`,
|
|
headers: { Authorization: `Bearer ${adminToken}` },
|
|
body: { note: '管理员备注' },
|
|
})
|
|
cy.request({ url: '/api/notifications', headers: { Authorization: `Bearer ${adminToken}` } })
|
|
.then(res => {
|
|
const unread = res.body.filter(n => !n.is_read && n.title && n.title.includes('再次审核配方被修改'))
|
|
expect(unread.length).to.eq(0)
|
|
})
|
|
})
|
|
})
|