webadmin系统设置
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { loginWithSms, resolveSmsCode } from './sms-test-helper.mjs';
|
||||
|
||||
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 = {
|
||||
@@ -21,11 +22,7 @@ async function sendSms(clientApp, phone, scene, sendPath = '/auth/sms/send') {
|
||||
}
|
||||
|
||||
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 }),
|
||||
});
|
||||
return loginWithSms(clientApp, phone, scene, loginPath, sendPath);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { loginWithSms } from './sms-test-helper.mjs';
|
||||
|
||||
const API = process.env.SMOKE_API ?? 'http://localhost:3000/api/v1';
|
||||
|
||||
async function req(clientApp, path, options = {}) {
|
||||
@@ -24,7 +26,6 @@ async function expectFail(clientApp, path, options = {}) {
|
||||
return json.message;
|
||||
}
|
||||
|
||||
const MOCK_SMS_CODE = process.env.MOCK_SMS_CODE ?? '123456';
|
||||
|
||||
async function sendSms(clientApp, phone, scene, sendPath = '/auth/sms/send') {
|
||||
await req(clientApp, sendPath, {
|
||||
@@ -34,11 +35,7 @@ async function sendSms(clientApp, phone, scene, sendPath = '/auth/sms/send') {
|
||||
}
|
||||
|
||||
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 }),
|
||||
});
|
||||
return loginWithSms(clientApp, phone, scene, loginPath, sendPath);
|
||||
}
|
||||
|
||||
async function adminLogin() {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
const API = process.env.SMOKE_API ?? 'http://localhost:3000/api/v1';
|
||||
const DEFAULT_MOCK_CODE = process.env.MOCK_SMS_CODE ?? '123456';
|
||||
const REDIS_CONTAINER = process.env.REDIS_CONTAINER ?? 'dukang-v1-redis';
|
||||
|
||||
function sleep(ms) {
|
||||
@@ -33,14 +32,11 @@ export async function loadClientConfig() {
|
||||
}
|
||||
|
||||
export async function resolveSmsCode(phone, scene) {
|
||||
const cfg = await loadClientConfig();
|
||||
if (cfg.mockSms) return DEFAULT_MOCK_CODE;
|
||||
|
||||
const fromRedis = readSmsCodeFromRedis(phone, scene);
|
||||
if (fromRedis) return fromRedis;
|
||||
|
||||
throw new Error(
|
||||
`SMS code not found for ${phone} (${scene}); enable MOCK_SMS or ensure Redis is reachable`,
|
||||
`SMS code not found for ${phone} (${scene}); send SMS first and ensure Redis is reachable`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
* 门店登录 / 建店短信校验专项冒烟(需 API 已启动且 MOCK_SMS 开启)
|
||||
* 用法: node scripts/test-shop-auth.mjs
|
||||
*/
|
||||
import { resolveSmsCode, sendSmsWithCooldown } from './sms-test-helper.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 = {
|
||||
@@ -38,13 +39,11 @@ async function main() {
|
||||
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: '13910000001', scene: 'STORE_LOGIN' }),
|
||||
});
|
||||
await sendSmsWithCooldown('SHOP_H5', '/shop/auth/sms/send', '13910000001', 'STORE_LOGIN');
|
||||
const code = await resolveSmsCode('13910000001', 'STORE_LOGIN');
|
||||
const login = await req('SHOP_H5', '/shop/auth/login/sms', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ phone: '13910000001', code: MOCK_SMS_CODE }),
|
||||
body: JSON.stringify({ phone: '13910000001', code }),
|
||||
});
|
||||
if (!login.accessToken || !login.refreshToken) throw new Error('login missing tokens');
|
||||
|
||||
@@ -58,13 +57,11 @@ async function main() {
|
||||
if (!refreshed.accessToken) throw new Error('refresh failed');
|
||||
|
||||
console.log('4. Admin create store rejects occupied phone');
|
||||
await req('HQ_WEB', '/admin/auth/sms/send', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ phone: '13600000001', scene: 'HQ_LOGIN' }),
|
||||
});
|
||||
await sendSmsWithCooldown('HQ_WEB', '/admin/auth/sms/send', '13600000001', 'HQ_LOGIN');
|
||||
const adminCode = await resolveSmsCode('13600000001', 'HQ_LOGIN');
|
||||
const admin = await req('HQ_WEB', '/admin/auth/login/sms', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ phone: '13600000001', code: MOCK_SMS_CODE }),
|
||||
body: JSON.stringify({ phone: '13600000001', code: adminCode }),
|
||||
});
|
||||
const occupied = await expectFail('HQ_WEB', '/admin/stores', {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user