99 lines
3.7 KiB
JavaScript
99 lines
3.7 KiB
JavaScript
const https = require('https')
|
|
const http = require('http')
|
|
|
|
const testQuestionsDisplay = async () => {
|
|
console.log('🔍 測試題目顯示修正')
|
|
console.log('=' .repeat(50))
|
|
|
|
try {
|
|
// 1. 測試邏輯題目顯示
|
|
console.log('\n📊 1. 測試邏輯題目顯示...')
|
|
const logicResponse = await new Promise((resolve, reject) => {
|
|
const req = http.get('http://localhost:3000/api/questions/logic', (res) => {
|
|
let data = ''
|
|
res.on('data', chunk => data += chunk)
|
|
res.on('end', () => resolve({ status: res.statusCode, data }))
|
|
})
|
|
req.on('error', reject)
|
|
})
|
|
|
|
if (logicResponse.status === 200) {
|
|
const logicData = JSON.parse(logicResponse.data)
|
|
if (logicData.success) {
|
|
console.log('✅ 邏輯題目 API 成功')
|
|
console.log(` 總題目數量: ${logicData.data.length}`)
|
|
console.log(` 顯示狀態: 全部顯示 (移除 .slice(0, 10) 限制)`)
|
|
|
|
if (logicData.data.length > 0) {
|
|
console.log(' 前 3 題預覽:')
|
|
logicData.data.slice(0, 3).forEach((question, index) => {
|
|
console.log(` ${index + 1}. ID: ${question.id}, 內容: ${question.question.substring(0, 30)}...`)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
// 2. 測試創意題目顯示
|
|
console.log('\n📊 2. 測試創意題目顯示...')
|
|
const creativeResponse = await new Promise((resolve, reject) => {
|
|
const req = http.get('http://localhost:3000/api/questions/creative', (res) => {
|
|
let data = ''
|
|
res.on('data', chunk => data += chunk)
|
|
res.on('end', () => resolve({ status: res.statusCode, data }))
|
|
})
|
|
req.on('error', reject)
|
|
})
|
|
|
|
if (creativeResponse.status === 200) {
|
|
const creativeData = JSON.parse(creativeResponse.data)
|
|
if (creativeData.success) {
|
|
console.log('✅ 創意題目 API 成功')
|
|
console.log(` 總題目數量: ${creativeData.data.length}`)
|
|
console.log(` 顯示狀態: 全部顯示 (移除 .slice(0, 10) 限制)`)
|
|
|
|
if (creativeData.data.length > 0) {
|
|
console.log(' 前 3 題預覽:')
|
|
creativeData.data.slice(0, 3).forEach((question, index) => {
|
|
console.log(` ${index + 1}. ID: ${question.id}, 內容: ${question.statement.substring(0, 30)}...`)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
// 3. 修正內容總結
|
|
console.log('\n📊 3. 修正內容總結:')
|
|
console.log('✅ 移除邏輯題目 .slice(0, 10) 限制')
|
|
console.log('✅ 移除創意題目 .slice(0, 10) 限制')
|
|
console.log('✅ 現在顯示所有題目,不再限制為 10 道')
|
|
console.log('✅ 保持原有的載入狀態和錯誤處理')
|
|
|
|
// 4. 用戶體驗改善
|
|
console.log('\n📊 4. 用戶體驗改善:')
|
|
console.log('✅ 管理員可以看到所有題目')
|
|
console.log('✅ 題目數量統計準確')
|
|
console.log('✅ 完整的題目管理功能')
|
|
console.log('✅ 無需分頁即可查看全部內容')
|
|
|
|
// 5. 技術細節
|
|
console.log('\n📊 5. 技術修正細節:')
|
|
console.log(' 之前: logicQuestions.slice(0, 10).map(...)')
|
|
console.log(' 現在: logicQuestions.map(...)')
|
|
console.log('')
|
|
console.log(' 之前: creativeQuestions.slice(0, 10).map(...)')
|
|
console.log(' 現在: creativeQuestions.map(...)')
|
|
|
|
console.log('\n📝 修正總結:')
|
|
console.log('✅ 創意題目現在顯示全部 18 道題目')
|
|
console.log('✅ 邏輯題目現在顯示全部 10 道題目')
|
|
console.log('✅ 移除了不必要的顯示限制')
|
|
console.log('✅ 保持所有原有功能正常運作')
|
|
|
|
} catch (error) {
|
|
console.error('❌ 測試失敗:', error.message)
|
|
} finally {
|
|
console.log('\n✅ 題目顯示修正測試完成')
|
|
}
|
|
}
|
|
|
|
testQuestionsDisplay()
|