Fix 5 wrong API endpoints + stop swallowing JS errors in E2E
All checks were successful
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 10s
Test / e2e-test (push) Successful in 4m24s
All checks were successful
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 10s
Test / e2e-test (push) Successful in 4m24s
Endpoint fixes: - AuditLog: /api/audit-logs → /api/audit-log - BugTracker: /api/bugs → /api/bug-reports, create → /api/bug-report - BugTracker: fix create body (content+priority, not title/description) - MyDiary: /api/brand-settings → /api/brand - MyDiary: /api/me/display-name → PUT /api/me - RecipeSearch: /api/category-modules → /api/categories Test improvements: - Remove blanket uncaught:exception swallow (only ignore ResizeObserver) - Add endpoint-parity.cy.js: intercept-based test that verifies correct API endpoints are called and wrong ones are NOT called Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
74
frontend/cypress/e2e/endpoint-parity.cy.js
Normal file
74
frontend/cypress/e2e/endpoint-parity.cy.js
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
// Verify that Vue frontend pages call the correct backend API endpoints.
|
||||||
|
// This test catches mismatched endpoint names (e.g. /api/bugs vs /api/bug-reports).
|
||||||
|
|
||||||
|
const ADMIN_TOKEN = 'c86ae7afbe10fabe3c1d5e1a7fee74feaadfd5dc7be2ab62'
|
||||||
|
|
||||||
|
describe('API Endpoint Parity', () => {
|
||||||
|
function visitAsAdmin(path) {
|
||||||
|
cy.visit(path, {
|
||||||
|
onBeforeLoad(win) {
|
||||||
|
win.localStorage.setItem('oil_auth_token', ADMIN_TOKEN)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
// Ignore uncaught exceptions from the app (API errors during loading, etc.)
|
// Log uncaught exceptions but don't swallow them blindly.
|
||||||
Cypress.on('uncaught:exception', () => false)
|
// Only ignore known non-critical errors (e.g. ResizeObserver).
|
||||||
|
Cypress.on('uncaught:exception', (err) => {
|
||||||
|
// ResizeObserver loop errors are harmless
|
||||||
|
if (err.message.includes('ResizeObserver')) return false
|
||||||
|
// Let all other errors fail the test
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
// Custom commands for the oil calculator app
|
// Custom commands for the oil calculator app
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ function formatDetail(log) {
|
|||||||
async function fetchLogs() {
|
async function fetchLogs() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await api(`/api/audit-logs?offset=${page.value * pageSize}&limit=${pageSize}`)
|
const res = await api(`/api/audit-log?offset=${page.value * pageSize}&limit=${pageSize}`)
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
const items = Array.isArray(data) ? data : data.logs || data.items || []
|
const items = Array.isArray(data) ? data : data.logs || data.items || []
|
||||||
@@ -179,7 +179,7 @@ async function undoLog(log) {
|
|||||||
if (!ok) return
|
if (!ok) return
|
||||||
try {
|
try {
|
||||||
const id = log._id || log.id
|
const id = log._id || log.id
|
||||||
const res = await api(`/api/audit-logs/${id}/undo`, { method: 'POST' })
|
const res = await api(`/api/audit-log/${id}/undo`, { method: 'POST' })
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
ui.showToast('已撤销')
|
ui.showToast('已撤销')
|
||||||
// Refresh
|
// Refresh
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ function toggleComments(bug) {
|
|||||||
|
|
||||||
async function loadBugs() {
|
async function loadBugs() {
|
||||||
try {
|
try {
|
||||||
const res = await api('/api/bugs')
|
const res = await api('/api/bug-reports')
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
bugs.value = await res.json()
|
bugs.value = await res.json()
|
||||||
}
|
}
|
||||||
@@ -200,14 +200,11 @@ async function loadBugs() {
|
|||||||
async function createBug() {
|
async function createBug() {
|
||||||
if (!bugForm.title.trim()) return
|
if (!bugForm.title.trim()) return
|
||||||
try {
|
try {
|
||||||
const res = await api('/api/bugs', {
|
const res = await api('/api/bug-report', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
title: bugForm.title.trim(),
|
content: bugForm.title.trim() + (bugForm.description.trim() ? '\n' + bugForm.description.trim() : ''),
|
||||||
description: bugForm.description.trim(),
|
priority: bugForm.priority === 'urgent' ? 0 : bugForm.priority === 'high' ? 1 : 2,
|
||||||
priority: bugForm.priority,
|
|
||||||
status: 'open',
|
|
||||||
reporter: auth.user.display_name || auth.user.username,
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@@ -226,7 +223,7 @@ async function createBug() {
|
|||||||
async function updateStatus(bug, newStatus) {
|
async function updateStatus(bug, newStatus) {
|
||||||
const id = bug._id || bug.id
|
const id = bug._id || bug.id
|
||||||
try {
|
try {
|
||||||
const res = await api(`/api/bugs/${id}`, {
|
const res = await api(`/api/bug-reports/${id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: JSON.stringify({ status: newStatus }),
|
body: JSON.stringify({ status: newStatus }),
|
||||||
})
|
})
|
||||||
@@ -244,7 +241,7 @@ async function removeBug(bug) {
|
|||||||
if (!ok) return
|
if (!ok) return
|
||||||
const id = bug._id || bug.id
|
const id = bug._id || bug.id
|
||||||
try {
|
try {
|
||||||
const res = await api(`/api/bugs/${id}`, { method: 'DELETE' })
|
const res = await api(`/api/bug-reports/${id}`, { method: 'DELETE' })
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
bugs.value = bugs.value.filter(b => (b._id || b.id) !== id)
|
bugs.value = bugs.value.filter(b => (b._id || b.id) !== id)
|
||||||
ui.showToast('已删除')
|
ui.showToast('已删除')
|
||||||
@@ -258,7 +255,7 @@ async function addComment(bug) {
|
|||||||
if (!newComment.value.trim()) return
|
if (!newComment.value.trim()) return
|
||||||
const id = bug._id || bug.id
|
const id = bug._id || bug.id
|
||||||
try {
|
try {
|
||||||
const res = await api(`/api/bugs/${id}/comments`, {
|
const res = await api(`/api/bug-reports/${id}/comments`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
text: newComment.value.trim(),
|
text: newComment.value.trim(),
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ function formatDate(d) {
|
|||||||
// Brand settings
|
// Brand settings
|
||||||
async function loadBrandSettings() {
|
async function loadBrandSettings() {
|
||||||
try {
|
try {
|
||||||
const res = await api('/api/brand-settings')
|
const res = await api('/api/brand')
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
brandName.value = data.brand_name || ''
|
brandName.value = data.brand_name || ''
|
||||||
@@ -356,7 +356,7 @@ async function loadBrandSettings() {
|
|||||||
|
|
||||||
async function saveBrandSettings() {
|
async function saveBrandSettings() {
|
||||||
try {
|
try {
|
||||||
await api('/api/brand-settings', {
|
await api('/api/brand', {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
brand_name: brandName.value,
|
brand_name: brandName.value,
|
||||||
@@ -400,7 +400,7 @@ async function handleUpload(type, event) {
|
|||||||
// Account
|
// Account
|
||||||
async function updateDisplayName() {
|
async function updateDisplayName() {
|
||||||
try {
|
try {
|
||||||
await api('/api/me/display-name', {
|
await api('/api/me', {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: JSON.stringify({ display_name: displayName.value }),
|
body: JSON.stringify({ display_name: displayName.value }),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ const catTrack = ref(null)
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await api('/api/category-modules')
|
const res = await api('/api/categories')
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
categories.value = await res.json()
|
categories.value = await res.json()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user