Files
2026-10-20 11:33:20 +08:00

18 lines
2.0 KiB
JavaScript

import fs from 'node:fs';
const base=process.env.ADMIN_TEST_GATEWAY;
if(!base||!['127.0.0.1','localhost'].includes(new URL(base).hostname))throw new Error('仅允许本机');
let token='';const checks=[];
async function call(path,body) {
const r=await fetch(base+path,{method:body?'POST':'GET',headers:{...(token?{Authorization:'Bearer '+token}:{}),...(body?{'Content-Type':'application/json'}:{})},body:body?JSON.stringify(body):undefined,signal:AbortSignal.timeout(45000)});
const value=await r.json().catch(()=>null);
checks.push({path,http:r.status,code:value?.code,message:String(value?.code)==='200'?undefined:value?.message,requestId:r.headers.get('x-request-id'),passed:r.status===200&&String(value?.code)==='200',total:value?.data?.total,counts:value?.data?.counts,records:value?.data?.records?.map(x=>({orderId:x.orderId,tenantId:x.tenantId,inboundId:x.inboundId,mainStatus:x.mainStatus}))});
fs.writeFileSync(new URL('tab-smoke.json',import.meta.url),JSON.stringify(checks,null,2));
return value;
}
const login=await call('/api/auth/login',{loginId:process.env.ADMIN_TEST_USERNAME,password:process.env.ADMIN_TEST_PASSWORD});
if(!login?.data?.accessToken)throw new Error('本地登录失败');token=login.data.accessToken;
for(const path of ['/api/platform/v1/orders/status-counts',...['PENDING_REVIEW','WAIT_MEASURE','WAIT_WEIGHT_CONFIRM','WEIGHT_CONFIRMED','WAIT_CUSTOMS_DOCS','WAIT_PALLETIZE','WAIT_SPLIT','LOADING','LOADED','EXPORT_CUSTOMS','SAILING_CLEARANCE','WAIT_UNLOAD','WAIT_DISPATCH','OUTBOUND_DOCUMENT','DELIVERING','SIGNED','DELIVERED','COMPLETED','MEASUREMENT_REVIEW'].map(s=>'/api/platform/v1/orders?page=1&size=5&mainStatus='+s)])await call(path);
for(const port of [9202,9303]){const r=await fetch(`http://127.0.0.1:${port}/actuator/health`);checks.push({path:`${port}/actuator/health`,http:r.status,body:await r.json(),passed:r.ok});}
fs.writeFileSync(new URL('tab-smoke.json',import.meta.url),JSON.stringify(checks,null,2));console.log(JSON.stringify(checks,null,2));