31 lines
834 B
JavaScript
31 lines
834 B
JavaScript
|
|
const axios = require('axios');
|
|||
|
|
|
|||
|
|
async function testOrderQuery() {
|
|||
|
|
try {
|
|||
|
|
// 首先登录获取token
|
|||
|
|
const loginResponse = await axios.post('http://localhost:4330/api/auth/login', {
|
|||
|
|
username: 'testuser',
|
|||
|
|
password: 'testpassword'
|
|||
|
|
}, {
|
|||
|
|
headers: { 'Content-Type': 'application/json' }
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
const token = loginResponse.data.data.token;
|
|||
|
|
console.log('登录成功,Token:', token);
|
|||
|
|
|
|||
|
|
// 测试订单查询
|
|||
|
|
const ordersResponse = await axios.get('http://localhost:4330/api/orders', {
|
|||
|
|
headers: {
|
|||
|
|
'Authorization': `Bearer ${token}`,
|
|||
|
|
'Content-Type': 'application/json'
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
console.log('订单查询成功:', ordersResponse.data);
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('测试失败:', error.response?.data || error.message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
testOrderQuery();
|