88 lines
2.6 KiB
JavaScript
88 lines
2.6 KiB
JavaScript
/**
|
|
* 截单时间逻辑集成测试脚本
|
|
* 通过 HTTP 请求真实 API 接口
|
|
*/
|
|
const http = require('http');
|
|
|
|
const BASE_URL = 'http://localhost:6060';
|
|
const TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJsaXVmdW1pbmdyZW4iLCJpYXQiOjE3ODE5NTM3ODIsImV4cCI6MTc4MTk2ODE4Mn0.p-H2Wz6BaJppPV4X-wGjzdvUz_pbuBfmo1lt5cDimhM';
|
|
|
|
function apiRequest(method, body) {
|
|
return new Promise((resolve, reject) => {
|
|
const bodyStr = typeof body === 'string' ? body : JSON.stringify(body);
|
|
const options = {
|
|
hostname: 'localhost',
|
|
port: 6060,
|
|
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now() / 1000)}`,
|
|
method: 'POST',
|
|
headers: {
|
|
platform: 'web',
|
|
project: 'wms',
|
|
Authorization: `Bearer ${TOKEN}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
};
|
|
const req = http.request(options, res => {
|
|
let data = '';
|
|
res.on('data', chunk => data += chunk);
|
|
res.on('end', () => {
|
|
let body;
|
|
try {
|
|
body = JSON.parse(data);
|
|
} catch (e) {
|
|
body = { _raw: data.substring(0, 500), _contentType: res.headers['content-type'] };
|
|
}
|
|
resolve({ status: res.statusCode, headers: res.headers, body, _rawLength: data.length });
|
|
});
|
|
});
|
|
req.on('error', e => reject(e));
|
|
req.write(bodyStr);
|
|
req.end();
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
// 测试 1: 验证 token 和基本信息
|
|
console.log('=== 测试 1: 验证 API 连接 ===');
|
|
try {
|
|
const r = await apiRequest('order.deliveryOrder.list', { page: 1, pageSize: 1, warehouse_id: 1000028 });
|
|
console.log(`Status: ${r.status}`);
|
|
console.log('Response:', JSON.stringify(r.body).substring(0, 300));
|
|
} catch (e) {
|
|
console.error('Error:', e.message);
|
|
}
|
|
|
|
// 测试 2: 创建订单
|
|
console.log('\n=== 测试 2: 创建订单 ===');
|
|
const orderBody = {
|
|
store_id: 1000241,
|
|
name: '测试收件人AAA',
|
|
mobile: '13800138000',
|
|
province: '广东省',
|
|
city: '广州市',
|
|
area: '天河区',
|
|
detail_address: '测试地址1号',
|
|
items: [
|
|
{
|
|
item_id: 1000693,
|
|
item_code: '6942349700385',
|
|
item_name: '泊泉雅黄瓜积雪草补水面膜25g',
|
|
plan_qty: 1,
|
|
},
|
|
],
|
|
};
|
|
try {
|
|
const r = await apiRequest('order.pendingOrder.createOrder', orderBody);
|
|
console.log(`Status: ${r.status}`);
|
|
if (r.body._raw) {
|
|
console.log('RAW:', r.body._raw);
|
|
} else {
|
|
console.log('Response:', JSON.stringify(r.body, null, 2));
|
|
}
|
|
} catch (e) {
|
|
console.error('Error:', e.message);
|
|
}
|
|
}
|
|
|
|
main().catch(console.error);
|