门店账号管理修改
This commit is contained in:
@@ -121,6 +121,15 @@ async function main() {
|
||||
body: JSON.stringify({ couponId: coupons[0].id, amount: Number(coupons[0].balance) + 1 }),
|
||||
});
|
||||
|
||||
console.log('7b. Shop sms guard + session');
|
||||
const unboundMsg = await expectFail('SHOP_H5', '/shop/auth/sms/send', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ phone: '13899999999', scene: 'STORE_LOGIN' }),
|
||||
});
|
||||
if (!unboundMsg.includes('未绑定门店')) {
|
||||
throw new Error(`Expected unbound store message, got: ${unboundMsg}`);
|
||||
}
|
||||
|
||||
console.log('8. Shop confirm redeem');
|
||||
const shopLogin = await loginSms(
|
||||
'SHOP_H5',
|
||||
@@ -129,6 +138,13 @@ async function main() {
|
||||
'/shop/auth/login/sms',
|
||||
'/shop/auth/sms/send',
|
||||
);
|
||||
const shopMe = await req('SHOP_H5', '/shop/auth/me', { token: shopLogin.accessToken });
|
||||
if (!shopMe?.phone) throw new Error('Shop /shop/auth/me failed');
|
||||
const refreshed = await req('SHOP_H5', '/shop/auth/token/refresh', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ refreshToken: shopLogin.refreshToken }),
|
||||
});
|
||||
if (!refreshed?.accessToken) throw new Error('Shop token refresh failed');
|
||||
const preview = await req('SHOP_H5', '/shop/redeem/preview', {
|
||||
method: 'POST',
|
||||
token: shopLogin.accessToken,
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 门店登录 / 建店短信校验专项冒烟(需 API 已启动且 MOCK_SMS 开启)
|
||||
* 用法: node scripts/test-shop-auth.mjs
|
||||
*/
|
||||
const API = process.env.SMOKE_API ?? 'http://localhost:3000/api/v1';
|
||||
const MOCK_SMS_CODE = process.env.MOCK_SMS_CODE ?? '123456';
|
||||
|
||||
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 expectFail(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}: expected failure`);
|
||||
return json.message;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('1. STORE_LOGIN unbound phone');
|
||||
const unbound = await expectFail('SHOP_H5', '/shop/auth/sms/send', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ phone: '13899999999', scene: 'STORE_LOGIN' }),
|
||||
});
|
||||
if (!unbound.includes('未绑定门店')) throw new Error(`unexpected: ${unbound}`);
|
||||
|
||||
console.log('2. STORE_LOGIN bound phone');
|
||||
await req('SHOP_H5', '/shop/auth/sms/send', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ phone: '13900000001', scene: 'STORE_LOGIN' }),
|
||||
});
|
||||
const login = await req('SHOP_H5', '/shop/auth/login/sms', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ phone: '13900000001', code: MOCK_SMS_CODE }),
|
||||
});
|
||||
if (!login.accessToken || !login.refreshToken) throw new Error('login missing tokens');
|
||||
|
||||
console.log('3. Shop session me + refresh');
|
||||
const me = await req('SHOP_H5', '/shop/auth/me', { token: login.accessToken });
|
||||
if (me.phone !== '13900000001') throw new Error('me phone mismatch');
|
||||
const refreshed = await req('SHOP_H5', '/shop/auth/token/refresh', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ refreshToken: login.refreshToken }),
|
||||
});
|
||||
if (!refreshed.accessToken) throw new Error('refresh failed');
|
||||
|
||||
console.log('4. STORE_ACCOUNT_OPEN occupied phone');
|
||||
await req('HQ_WEB', '/admin/auth/sms/send', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ phone: '13600000001', scene: 'HQ_LOGIN' }),
|
||||
});
|
||||
const admin = await req('HQ_WEB', '/admin/auth/login/sms', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ phone: '13600000001', code: MOCK_SMS_CODE }),
|
||||
});
|
||||
const occupied = await expectFail('HQ_WEB', '/admin/stores/phone/sms/send', {
|
||||
method: 'POST',
|
||||
token: admin.accessToken,
|
||||
body: JSON.stringify({ phone: '13900000001' }),
|
||||
});
|
||||
if (!occupied.includes('已绑定')) throw new Error(`unexpected: ${occupied}`);
|
||||
|
||||
console.log('\n✅ shop-auth tests passed');
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user