const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const test = require('node:test'); const AuthPages = require('../public/js/auth-pages.js'); test('registration body carries the SMS code but never sends confirmation or captcha fields', () => { assert.deepEqual( AuthPages.buildRegisterBody({ phone: '13800000000', smsCode: '123456', nickName: '小李', password: 'plain-password', confirmPassword: 'plain-password', validToken: 'captcha-ticket' }, (value) => 'md5-' + value), { phone: '13800000000', smsCode: '123456', nickName: '小李', password: 'md5-plain-password' } ); }); test('password reset body carries only the reset DTO fields', () => { assert.deepEqual( AuthPages.buildPasswordResetBody({ phone: '13800000000', smsCode: '123456', newPassword: 'plain-password', validToken: 'captcha-ticket' }, (value) => 'md5-' + value), { phone: '13800000000', smsCode: '123456', newPassword: 'md5-plain-password' } ); }); test('authentication forms use the PC SMS scenes defined by the PC endpoint', () => { assert.equal(AuthPages.getCaptchaScene('login'), 'PC_SMS_LOGIN'); assert.equal(AuthPages.getCaptchaScene('sms-login'), 'PC_SMS_LOGIN'); assert.equal(AuthPages.getCaptchaScene('register'), 'PC_REGISTER'); assert.equal(AuthPages.getCaptchaScene('password-reset'), 'PC_FORGOT_PASSWORD'); }); test('registration validates SMS code and password confirmation before submission', () => { const base = { phone: '13800000000', smsCode: '123456', password: 'password', confirmPassword: 'password' }; assert.equal(AuthPages.validateAuthValues('register', base), ''); assert.equal(AuthPages.validateAuthValues('register', { ...base, smsCode: '' }), '请填写短信验证码'); assert.equal(AuthPages.validateAuthValues('register', { ...base, confirmPassword: 'different' }), '两次输入的密码不一致'); }); test('registration page exposes the documented SMS and confirmation inputs', () => { const source = fs.readFileSync(path.join(__dirname, '..', 'register.html'), 'utf8'); assert.match(source, /name="smsCode"/); assert.match(source, /data-api-send-code/); assert.match(source, /name="confirmPassword"/); });