All checks were successful
PR Preview / test (pull_request) Has been skipped
Deploy Production / test (push) Successful in 6s
PR Preview / teardown-preview (pull_request) Successful in 14s
PR Preview / deploy-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 6s
Test / build-check (push) Successful in 4s
Deploy Production / deploy (push) Successful in 6s
Test / e2e-test (push) Successful in 53s
单元测试256个全部通过(新增14个): - recipeNameEn: 11个翻译测试 - 重复精油检查: 3个 后端: 补充"缓解"翻译词条 E2E: 改名重翻译、删除用户去重跳过 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
270 lines
9.0 KiB
JavaScript
270 lines
9.0 KiB
JavaScript
describe('PR27 Feature Tests', () => {
|
|
const ADMIN_TOKEN = 'c86ae7afbe10fabe3c1d5e1a7fee74feaadfd5dc7be2ab62'
|
|
const authHeaders = { Authorization: `Bearer ${ADMIN_TOKEN}` }
|
|
const TEST_USERNAME = 'cypress_pr27_user'
|
|
|
|
// -------------------------------------------------------------------------
|
|
// API: en_name auto title case on recipe create
|
|
// -------------------------------------------------------------------------
|
|
describe('API: en_name auto title case', () => {
|
|
let recipeId
|
|
|
|
after(() => {
|
|
// Cleanup
|
|
if (recipeId) {
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `/api/recipes/${recipeId}`,
|
|
headers: authHeaders,
|
|
failOnStatusCode: false
|
|
})
|
|
}
|
|
})
|
|
|
|
it('auto title-cases en_name when provided', () => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/api/recipes',
|
|
headers: authHeaders,
|
|
body: {
|
|
name: 'PR27标题测试',
|
|
en_name: 'pain relief blend',
|
|
ingredients: [{ oil_name: '薰衣草', drops: 3 }],
|
|
tags: []
|
|
}
|
|
}).then(res => {
|
|
expect(res.status).to.be.oneOf([200, 201])
|
|
recipeId = res.body.id
|
|
})
|
|
})
|
|
|
|
it('verifies en_name is title-cased', () => {
|
|
cy.request('/api/recipes').then(res => {
|
|
const found = res.body.find(r => r.name === 'PR27标题测试')
|
|
expect(found).to.exist
|
|
expect(found.en_name).to.eq('Pain Relief Blend')
|
|
recipeId = found.id
|
|
})
|
|
})
|
|
|
|
it('auto translates en_name from Chinese when not provided', () => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/api/recipes',
|
|
headers: authHeaders,
|
|
body: {
|
|
name: '助眠配方',
|
|
ingredients: [{ oil_name: '薰衣草', drops: 5 }],
|
|
tags: []
|
|
}
|
|
}).then(res => {
|
|
expect(res.status).to.be.oneOf([200, 201])
|
|
const autoId = res.body.id
|
|
|
|
cy.request('/api/recipes').then(listRes => {
|
|
const found = listRes.body.find(r => r.id === autoId)
|
|
expect(found).to.exist
|
|
// auto_translate('助眠配方') should produce English with "Sleep" and "Blend"
|
|
expect(found.en_name).to.be.a('string')
|
|
expect(found.en_name.length).to.be.greaterThan(0)
|
|
expect(found.en_name).to.include('Sleep')
|
|
|
|
// Cleanup
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `/api/recipes/${autoId}`,
|
|
headers: authHeaders,
|
|
failOnStatusCode: false
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
// -------------------------------------------------------------------------
|
|
// API: delete user transfers diary recipes to admin
|
|
// -------------------------------------------------------------------------
|
|
describe('API: delete user transfers diary', () => {
|
|
let testUserId
|
|
let testUserToken
|
|
|
|
// Cleanup leftover test user
|
|
before(() => {
|
|
cy.request({
|
|
url: '/api/users',
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
const leftover = res.body.find(u => u.username === TEST_USERNAME)
|
|
if (leftover) {
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `/api/users/${leftover.id || leftover._id}`,
|
|
headers: authHeaders,
|
|
failOnStatusCode: false
|
|
})
|
|
}
|
|
})
|
|
})
|
|
|
|
it('creates a test user', () => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/api/users',
|
|
headers: authHeaders,
|
|
body: {
|
|
username: TEST_USERNAME,
|
|
display_name: 'PR27 Test User',
|
|
role: 'editor'
|
|
}
|
|
}).then(res => {
|
|
expect(res.status).to.be.oneOf([200, 201])
|
|
testUserId = res.body.id || res.body._id
|
|
testUserToken = res.body.token
|
|
expect(testUserId).to.be.a('number')
|
|
})
|
|
})
|
|
|
|
it('adds a diary entry for the test user', () => {
|
|
const userAuth = { Authorization: `Bearer ${testUserToken}` }
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/api/diary',
|
|
headers: userAuth,
|
|
body: {
|
|
name: 'PR27用户日记',
|
|
ingredients: [{ oil: '乳香', drops: 4 }, { oil: '薰衣草', drops: 2 }],
|
|
note: '转移测试'
|
|
}
|
|
}).then(res => {
|
|
expect(res.status).to.be.oneOf([200, 201])
|
|
})
|
|
})
|
|
|
|
it('deletes the user and transfers diary to admin', () => {
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `/api/users/${testUserId}`,
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
expect(res.status).to.eq(200)
|
|
expect(res.body.ok).to.eq(true)
|
|
})
|
|
})
|
|
|
|
it('verifies diary was transferred to admin', () => {
|
|
cy.request({
|
|
url: '/api/diary',
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
expect(res.body).to.be.an('array')
|
|
// Transferred diary should have user's name appended
|
|
const transferred = res.body.find(d => d.name && d.name.includes('PR27用户日记') && d.name.includes('PR27 Test User'))
|
|
expect(transferred).to.exist
|
|
expect(transferred.note).to.eq('转移测试')
|
|
|
|
// Cleanup: delete the transferred diary
|
|
if (transferred) {
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `/api/diary/${transferred.id}`,
|
|
headers: authHeaders,
|
|
failOnStatusCode: false
|
|
})
|
|
}
|
|
})
|
|
})
|
|
})
|
|
|
|
// -------------------------------------------------------------------------
|
|
// API: rename recipe auto-retranslates en_name
|
|
// -------------------------------------------------------------------------
|
|
describe('API: rename recipe retranslates en_name', () => {
|
|
let recipeId
|
|
|
|
after(() => {
|
|
if (recipeId) {
|
|
cy.request({ method: 'DELETE', url: `/api/recipes/${recipeId}`, headers: authHeaders, failOnStatusCode: false })
|
|
}
|
|
})
|
|
|
|
it('creates recipe then renames it, en_name auto-updates', () => {
|
|
cy.request({
|
|
method: 'POST', url: '/api/recipes', headers: authHeaders,
|
|
body: { name: '头痛', ingredients: [{ oil_name: '薰衣草', drops: 3 }], tags: [] }
|
|
}).then(res => {
|
|
recipeId = res.body.id
|
|
// Verify initial en_name
|
|
cy.request('/api/recipes').then(list => {
|
|
const r = list.body.find(x => x.id === recipeId)
|
|
expect(r.en_name).to.include('Headache')
|
|
})
|
|
// Rename to 肩颈按摩
|
|
cy.request({
|
|
method: 'PUT', url: `/api/recipes/${recipeId}`, headers: authHeaders,
|
|
body: { name: '肩颈按摩' }
|
|
}).then(() => {
|
|
cy.request('/api/recipes').then(list => {
|
|
const r = list.body.find(x => x.id === recipeId)
|
|
expect(r.en_name).to.include('Neck')
|
|
expect(r.en_name).to.include('Massage')
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
// -------------------------------------------------------------------------
|
|
// API: delete user skips duplicate diary by ingredient content
|
|
// -------------------------------------------------------------------------
|
|
describe('API: delete user skips duplicate diary', () => {
|
|
const DUP_USER = 'cypress_pr27_dup'
|
|
|
|
it('creates user with duplicate diary, deletes, verifies skip', () => {
|
|
// Create user
|
|
cy.request({
|
|
method: 'POST', url: '/api/users', headers: authHeaders,
|
|
body: { username: DUP_USER, display_name: 'Dup Test', role: 'viewer' }
|
|
}).then(res => {
|
|
const userId = res.body.id
|
|
const userToken = res.body.token
|
|
const userAuth = { Authorization: `Bearer ${userToken}` }
|
|
|
|
// Get a public recipe's ingredients to create a duplicate
|
|
cy.request({ url: '/api/recipes', headers: authHeaders }).then(listRes => {
|
|
const pub = listRes.body[0]
|
|
const dupIngs = pub.ingredients.map(i => ({ oil: i.oil_name, drops: i.drops }))
|
|
|
|
// Add diary with same ingredients as public recipe (different name)
|
|
cy.request({
|
|
method: 'POST', url: '/api/diary', headers: userAuth,
|
|
body: { name: '我的重复方', ingredients: dupIngs, note: '' }
|
|
}).then(() => {
|
|
// Delete user
|
|
cy.request({ method: 'DELETE', url: `/api/users/${userId}`, headers: authHeaders }).then(delRes => {
|
|
expect(delRes.body.ok).to.eq(true)
|
|
// Verify duplicate was NOT transferred
|
|
cy.request({ url: '/api/diary', headers: authHeaders }).then(diaryRes => {
|
|
const transferred = diaryRes.body.find(d => d.name && d.name.includes('我的重复方'))
|
|
expect(transferred).to.not.exist
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
// -------------------------------------------------------------------------
|
|
// UI: 管理配方 login prompt when not logged in
|
|
// -------------------------------------------------------------------------
|
|
describe('UI: RecipeManager login prompt', () => {
|
|
it('shows login prompt when not logged in', () => {
|
|
// Clear any stored auth
|
|
cy.clearLocalStorage()
|
|
cy.visit('/#/manage')
|
|
cy.contains('登录后可管理配方').should('be.visible')
|
|
cy.contains('登录 / 注册').should('be.visible')
|
|
})
|
|
})
|
|
})
|