新增評分項目設定、資料庫整合
This commit is contained in:
79
scripts/test-single-template.js
Normal file
79
scripts/test-single-template.js
Normal file
@@ -0,0 +1,79 @@
|
||||
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||
|
||||
const API_BASE = 'http://localhost:3000/api';
|
||||
|
||||
async function testSingleTemplateMode() {
|
||||
try {
|
||||
console.log('🔄 測試單一模板模式...');
|
||||
|
||||
// 1. 測試獲取現有模板
|
||||
console.log('\n1. 測試獲取現有模板...');
|
||||
const getResponse = await fetch(`${API_BASE}/criteria-templates`);
|
||||
const getData = await getResponse.json();
|
||||
|
||||
if (getData.success) {
|
||||
console.log(`✅ 找到 ${getData.data.length} 個模板`);
|
||||
if (getData.data.length > 0) {
|
||||
const template = getData.data[0];
|
||||
console.log(` 模板名稱: ${template.name}`);
|
||||
console.log(` 評分項目數量: ${template.items.length}`);
|
||||
}
|
||||
} else {
|
||||
console.log('❌ 獲取模板失敗:', getData.error);
|
||||
}
|
||||
|
||||
// 2. 測試覆蓋模板
|
||||
console.log('\n2. 測試覆蓋模板...');
|
||||
const templateData = {
|
||||
name: '我的評分標準',
|
||||
description: '這是我的自定義評分標準',
|
||||
items: [
|
||||
{ name: '內容品質', description: '內容的準確性和完整性', weight: 30, maxScore: 10 },
|
||||
{ name: '視覺設計', description: '版面設計和視覺效果', weight: 25, maxScore: 10 },
|
||||
{ name: '邏輯結構', description: '內容組織的邏輯性', weight: 25, maxScore: 10 },
|
||||
{ name: '創新性', description: '創意思維的展現', weight: 20, maxScore: 10 }
|
||||
]
|
||||
};
|
||||
|
||||
const saveResponse = await fetch(`${API_BASE}/criteria-templates`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(templateData)
|
||||
});
|
||||
const saveData = await saveResponse.json();
|
||||
|
||||
if (saveData.success) {
|
||||
console.log('✅ 模板覆蓋成功');
|
||||
console.log(` 模板 ID: ${saveData.data.id}`);
|
||||
} else {
|
||||
console.log('❌ 模板覆蓋失敗:', saveData.error);
|
||||
}
|
||||
|
||||
// 3. 驗證覆蓋結果
|
||||
console.log('\n3. 驗證覆蓋結果...');
|
||||
const verifyResponse = await fetch(`${API_BASE}/criteria-templates`);
|
||||
const verifyData = await verifyResponse.json();
|
||||
|
||||
if (verifyData.success) {
|
||||
console.log(`✅ 驗證成功,現在有 ${verifyData.data.length} 個模板`);
|
||||
if (verifyData.data.length > 0) {
|
||||
const template = verifyData.data[0];
|
||||
console.log(` 模板名稱: ${template.name}`);
|
||||
console.log(` 模板描述: ${template.description}`);
|
||||
console.log(` 評分項目數量: ${template.items.length}`);
|
||||
template.items.forEach((item, index) => {
|
||||
console.log(` ${index + 1}. ${item.name} (權重: ${item.weight}%)`);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log('❌ 驗證失敗:', verifyData.error);
|
||||
}
|
||||
|
||||
console.log('\n🎉 單一模板模式測試完成!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 測試失敗:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
testSingleTemplateMode();
|
Reference in New Issue
Block a user