短信验证调试成功

This commit is contained in:
2026-07-06 13:18:56 +08:00
parent 5ba69eb935
commit 1c978b8adc
62 changed files with 2491 additions and 354 deletions
+40 -27
View File
@@ -1,4 +1,5 @@
const API = 'http://localhost:3000/api/v1';
const MOCK_SMS_CODE = process.env.MOCK_SMS_CODE ?? '123456';
async function req(clientApp, path, options = {}) {
const headers = {
@@ -12,15 +13,27 @@ async function req(clientApp, path, options = {}) {
return json.data;
}
async function sendSms(clientApp, phone, scene, sendPath = '/auth/sms/send') {
await req(clientApp, sendPath, {
method: 'POST',
body: JSON.stringify({ phone, scene }),
});
}
async function loginSms(clientApp, phone, scene, loginPath = '/auth/login/sms', sendPath = '/auth/sms/send') {
await sendSms(clientApp, phone, scene, sendPath);
return req(clientApp, loginPath, {
method: 'POST',
body: JSON.stringify({ phone, code: MOCK_SMS_CODE }),
});
}
async function main() {
console.log('1. Health');
await req('USER_H5', '/health');
console.log('2. User login');
const userLogin = await req('USER_H5', '/auth/login/sms', {
method: 'POST',
body: JSON.stringify({ phone: '13800000001', code: '123456' }),
});
const userLogin = await loginSms('USER_H5', '13800000001', 'USER_LOGIN');
const userToken = userLogin.accessToken;
console.log('3. Catalog');
@@ -48,40 +61,40 @@ async function main() {
});
await req('USER_H5', `/trade/orders/${order.id}/pay`, { method: 'POST', token: userToken });
console.log('5. Benefit granted');
console.log('5. Shop login + redeem preview');
const shopLogin = await loginSms(
'SHOP_H5',
'13900000001',
'STORE_LOGIN',
'/shop/auth/login/sms',
'/shop/auth/sms/send',
);
const coupons = await req('USER_H5', '/benefit/coupons', { token: userToken });
if (!coupons.length) throw new Error('No coupon after pay');
console.log('6. Redeem token');
const tokenData = await req('USER_H5', '/redeem/tokens', {
if (!coupons.length) throw new Error('No coupons');
const tokenRes = await req('USER_H5', '/redeem/tokens', {
method: 'POST',
token: userToken,
body: JSON.stringify({ couponId: coupons[0].id, amount: 50 }),
body: JSON.stringify({ amount: 50 }),
});
console.log('7. Shop redeem');
const shopLogin = await req('SHOP_H5', '/shop/auth/login/sms', {
method: 'POST',
body: JSON.stringify({ phone: '13900000001', code: '123456' }),
});
await req('SHOP_H5', '/shop/redeem/confirm', {
await req('SHOP_H5', '/shop/redeem/preview', {
method: 'POST',
token: shopLogin.accessToken,
body: JSON.stringify({ token: tokenData.token }),
body: JSON.stringify({ token: tokenRes.token }),
});
console.log('8. Partner orders');
const partnerLogin = await req('PARTNER_H5', '/partner/auth/login/sms', {
method: 'POST',
body: JSON.stringify({ phone: '13700000001', code: '123456' }),
});
const orders = await req('PARTNER_H5', '/partner/orders', { token: partnerLogin.accessToken });
if (!orders.list.length) throw new Error('Partner should see orders');
console.log('6. Partner login');
await loginSms(
'PARTNER_H5',
'13700000001',
'PARTNER_LOGIN',
'/partner/auth/login/sms',
'/partner/auth/sms/send',
);
console.log('\n✅ preV1 smoke passed');
console.log('preV1 smoke OK');
}
main().catch((e) => {
console.error('❌ Smoke failed:', e.message);
console.error(e);
process.exit(1);
});