init
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
const API = 'http://localhost:3000/api/v1';
|
||||
|
||||
async function req(clientApp, path, options = {}) {
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Client-App': clientApp,
|
||||
...(options.token ? { Authorization: `Bearer ${options.token}` } : {}),
|
||||
};
|
||||
const res = await fetch(`${API}${path}`, { ...options, headers, body: options.body });
|
||||
const json = await res.json();
|
||||
if (json.code !== 0) throw new Error(`${path}: ${json.message}`);
|
||||
return json.data;
|
||||
}
|
||||
|
||||
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 userToken = userLogin.accessToken;
|
||||
|
||||
console.log('3. Catalog');
|
||||
const products = await req('USER_H5', '/catalog/products');
|
||||
if (products.length < 4) throw new Error('Expected 4 products');
|
||||
|
||||
console.log('4. Create address + order + mock pay');
|
||||
const addr = await req('USER_H5', '/user/addresses', {
|
||||
method: 'POST',
|
||||
token: userToken,
|
||||
body: JSON.stringify({
|
||||
receiverName: '测试',
|
||||
phone: '13800000001',
|
||||
province: '河南省',
|
||||
city: '郑州市',
|
||||
district: '金水区',
|
||||
detail: '冒烟测试地址1号',
|
||||
isDefault: true,
|
||||
}),
|
||||
});
|
||||
const order = await req('USER_H5', '/trade/orders', {
|
||||
method: 'POST',
|
||||
token: userToken,
|
||||
body: JSON.stringify({ productId: products[0].id, quantity: 2, addressId: addr.id }),
|
||||
});
|
||||
await req('USER_H5', `/trade/orders/${order.id}/pay`, { method: 'POST', token: userToken });
|
||||
|
||||
console.log('5. Benefit granted');
|
||||
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', {
|
||||
method: 'POST',
|
||||
token: userToken,
|
||||
body: JSON.stringify({ couponId: coupons[0].id, 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', {
|
||||
method: 'POST',
|
||||
token: shopLogin.accessToken,
|
||||
body: JSON.stringify({ token: tokenData.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('\n✅ preV1 smoke passed');
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error('❌ Smoke failed:', e.message);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user