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>
78 lines
2.4 KiB
JavaScript
78 lines
2.4 KiB
JavaScript
// Verify that Vue frontend pages call the correct backend API endpoints.
|
|
|
|
describe('API Endpoint Parity', () => {
|
|
let adminToken
|
|
|
|
before(() => {
|
|
cy.getAdminToken().then(token => { adminToken = token })
|
|
})
|
|
|
|
function visitAsAdmin(path) {
|
|
cy.visit(path, {
|
|
onBeforeLoad(win) {
|
|
win.localStorage.setItem('oil_auth_token', adminToken)
|
|
}
|
|
})
|
|
}
|
|
|
|
it('search page loads recipes from /api/recipes', () => {
|
|
cy.intercept('GET', '/api/recipes').as('recipes')
|
|
visitAsAdmin('/')
|
|
cy.wait('@recipes').its('response.statusCode').should('eq', 200)
|
|
})
|
|
|
|
it('search page loads oils from /api/oils', () => {
|
|
cy.intercept('GET', '/api/oils').as('oils')
|
|
visitAsAdmin('/')
|
|
cy.wait('@oils').its('response.statusCode').should('eq', 200)
|
|
})
|
|
|
|
it('oil reference page loads oils', () => {
|
|
cy.intercept('GET', '/api/oils').as('oils')
|
|
visitAsAdmin('/oils')
|
|
cy.wait('@oils').its('response.statusCode').should('eq', 200)
|
|
})
|
|
|
|
it('audit log page loads from /api/audit-log', () => {
|
|
cy.intercept('GET', '/api/audit-log*').as('audit')
|
|
visitAsAdmin('/audit')
|
|
cy.wait('@audit').its('response.statusCode').should('eq', 200)
|
|
})
|
|
|
|
it('audit log page does NOT call /api/audit-logs (wrong endpoint)', () => {
|
|
cy.intercept('GET', '/api/audit-logs*').as('wrongAudit')
|
|
visitAsAdmin('/audit')
|
|
cy.wait(2000)
|
|
cy.get('@wrongAudit.all').should('have.length', 0)
|
|
})
|
|
|
|
it('bug tracker page loads from /api/bug-reports', () => {
|
|
cy.intercept('GET', '/api/bug-reports').as('bugs')
|
|
visitAsAdmin('/bugs')
|
|
cy.wait('@bugs').its('response.statusCode').should('eq', 200)
|
|
})
|
|
|
|
it('bug tracker page does NOT call /api/bugs (wrong endpoint)', () => {
|
|
cy.intercept('GET', '/api/bugs').as('wrongBugs')
|
|
visitAsAdmin('/bugs')
|
|
cy.wait(2000)
|
|
cy.get('@wrongBugs.all').should('have.length', 0)
|
|
})
|
|
|
|
it('user management page loads from /api/users', () => {
|
|
cy.intercept('GET', '/api/users').as('users')
|
|
visitAsAdmin('/users')
|
|
cy.wait('@users').its('response.statusCode').should('eq', 200)
|
|
})
|
|
|
|
it('categories load from /api/categories', () => {
|
|
cy.intercept('GET', '/api/categories').as('cats')
|
|
visitAsAdmin('/')
|
|
cy.wait(3000)
|
|
// Categories may or may not be fetched depending on page logic
|
|
// Just verify no /api/category-modules calls
|
|
cy.intercept('GET', '/api/category-modules').as('wrongCats')
|
|
cy.get('@wrongCats.all').should('have.length', 0)
|
|
})
|
|
})
|