feat: complete login and user management flow

This commit is contained in:
hectorzhao
2026-07-02 16:28:48 +08:00
parent 9c639d54b9
commit e26d8324c3
22 changed files with 1320 additions and 300 deletions
+25 -3
View File
@@ -10,6 +10,8 @@ const prisma = new PrismaClient({
const apiBaseUrl = process.env.API_BASE_URL ?? 'http://127.0.0.1:3101/api';
const tenantCode = 'smoke-tenant';
const username = 'smoke_client';
const email = 'smoke-client@example.com';
const phone = '13800138099';
const password = 'SmokePass123!';
function hashPassword(value) {
@@ -27,19 +29,37 @@ async function ensureSmokeData() {
where: { username },
update: {
tenantId: tenant.id,
email,
phone,
displayName: 'Smoke Client Admin',
passwordHash: hashPassword(password),
status: 'active',
failedLoginCount: 0,
lockedUntil: null,
deletedAt: null,
},
create: {
tenantId: tenant.id,
username,
email,
phone,
displayName: 'Smoke Client Admin',
passwordHash: hashPassword(password),
status: 'active',
},
});
const enterpriseAdminRole = await prisma.role.upsert({
where: { code: 'enterprise_admin' },
update: { name: '企业管理员', scope: 'tenant' },
create: { code: 'enterprise_admin', name: '企业管理员', scope: 'tenant' },
});
await prisma.userRole.upsert({
where: { userId_roleId: { userId: user.id, roleId: enterpriseAdminRole.id } },
update: {},
create: { userId: user.id, roleId: enterpriseAdminRole.id },
});
await prisma.tenantAccount.upsert({
where: { tenantId: tenant.id },
update: { balanceCents: { increment: 0 }, smsUnits: { increment: 0 }, creditCents: 5000, status: 'active' },
@@ -51,7 +71,7 @@ async function ensureSmokeData() {
update: {
name: 'Smoke CMPP Channel',
gatewayHost: '127.0.0.1',
gatewayPort: 7890,
gatewayPort: 17890,
account: 'smoke-account',
passwordCipher: 'smoke-password',
srcId: '10690000',
@@ -65,7 +85,7 @@ async function ensureSmokeData() {
carrier: 'all',
protocol: 'CMPP',
gatewayHost: '127.0.0.1',
gatewayPort: 7890,
gatewayPort: 17890,
account: 'smoke-account',
passwordCipher: 'smoke-password',
srcId: '10690000',
@@ -180,9 +200,11 @@ async function run() {
const health = await request('/health');
assert(health.status === 'ok', 'health should return ok');
const captcha = await request('/client/auth/captcha');
const captchaText = String(captcha.challenge.split('=')[0].split('+').map((part) => Number(part.trim())).reduce((sum, value) => sum + value, 0));
const login = await request('/client/auth/login', {
method: 'POST',
body: JSON.stringify({ username, password }),
body: JSON.stringify({ login: email, password, captchaId: captcha.captchaId, captchaText }),
});
assert(login.accessToken && login.user?.tenantId === data.tenant.id, 'login should return smoke tenant user');