26 lines
1.8 KiB
JavaScript
26 lines
1.8 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'});
|
|
fs.writeFileSync(new URL('http-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/last-leg/orders?page=1&size=5',
|
|
'/api/platform/v1/last-leg/dispatches?page=1&size=5',
|
|
'/api/platform/v1/last-leg/dispatches/drafts?page=1&size=5',
|
|
'/api/platform/v1/last-leg/appointment-work/summary',
|
|
'/api/platform/inbounds?page=1&size=5',
|
|
'/api/platform/v1/first-leg/tasks?tenantId=10001&page=1&size=5',
|
|
'/api/platform/v1/sailing-channels',
|
|
'/api/platform/v1/sailing-templates?page=1&size=5'
|
|
])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('http-smoke.json',import.meta.url),JSON.stringify(checks,null,2));console.log(JSON.stringify(checks,null,2));
|