Files
hr-assessment-system/scripts/test-creative-results-page.js

69 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const https = require('https')
const http = require('http')
const testCreativeResultsPage = async () => {
console.log('🔍 測試創意測驗結果頁面數據')
console.log('=' .repeat(50))
const userId = 'user-1759073326705-m06y3wacd'
try {
// 檢查創意測試結果 API模擬創意測驗結果頁面的請求
console.log('\n📊 檢查創意測試結果 API...')
const response = await new Promise((resolve, reject) => {
const req = http.get(`http://localhost:3000/api/test-results/creative?userId=${userId}`, (res) => {
let data = ''
res.on('data', chunk => data += chunk)
res.on('end', () => resolve({ status: res.statusCode, data }))
})
req.on('error', reject)
})
if (response.status === 200) {
const data = JSON.parse(response.data)
if (data.success && data.data.length > 0) {
console.log(`找到 ${data.data.length} 筆創意測試結果:`)
// 按創建時間排序,取最新的(模擬前端邏輯)
const sortedResults = data.data.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))
const latestResult = sortedResults[0]
console.log('\n📋 創意測驗結果頁面會使用的數據:')
console.log(`ID: ${latestResult.id}`)
console.log(`completed_at: ${latestResult.completed_at}`)
console.log(`created_at: ${latestResult.created_at}`)
// 測試時間解析(模擬前端顯示邏輯)
const parsedDate = new Date(latestResult.completed_at)
const isValid = !isNaN(parsedDate.getTime())
console.log(`\n📊 前端時間解析測試:`)
console.log(`解析是否有效: ${isValid ? '✅' : '❌'}`)
if (isValid) {
const taiwanTime = parsedDate.toLocaleString("zh-TW", { timeZone: "Asia/Taipei" })
console.log(`台灣時間: ${taiwanTime}`)
console.log(`顯示效果: 完成時間:${taiwanTime}`)
} else {
console.log(`❌ 會顯示: 完成時間Invalid Date`)
}
// 檢查是否為今天
const now = new Date()
const isToday = now.toDateString() === parsedDate.toDateString()
console.log(`是否為今天: ${isToday ? '✅' : '❌'}`)
if (!isToday) {
console.log(`⚠️ 這是舊數據,可能需要重新進行測試`)
}
}
}
} catch (error) {
console.error('❌ 測試失敗:', error.message)
} finally {
console.log('\n✅ 創意測驗結果頁面數據測試完成')
}
}
testCreativeResultsPage()