优化构架
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import {
|
||||
getPasswordStrength,
|
||||
validateEditableAccountProfile,
|
||||
validatePasswordChange,
|
||||
} from './accountProfile.ts'
|
||||
|
||||
test('accepts a complete editable account profile', () => {
|
||||
assert.deepEqual(validateEditableAccountProfile({
|
||||
realName: '企业管理员',
|
||||
phone: '13800006601',
|
||||
email: 'admin@example.com',
|
||||
}), [])
|
||||
})
|
||||
|
||||
test('reports invalid profile fields together', () => {
|
||||
const errors = validateEditableAccountProfile({ realName: '', phone: '1'.repeat(33), email: 'bad' })
|
||||
assert.equal(errors.length, 3)
|
||||
})
|
||||
|
||||
test('validates password length, equality and confirmation', () => {
|
||||
assert.deepEqual(validatePasswordChange({
|
||||
currentPassword: 'OldPass123',
|
||||
newPassword: 'NewPass456',
|
||||
confirmPassword: 'NewPass456',
|
||||
}), [])
|
||||
assert.equal(validatePasswordChange({ currentPassword: '', newPassword: '123', confirmPassword: '456' }).length, 3)
|
||||
assert.match(validatePasswordChange({ currentPassword: 'SamePass1', newPassword: 'SamePass1', confirmPassword: 'SamePass1' }).join('|'), /不能与当前密码相同/)
|
||||
assert.match(validatePasswordChange({ currentPassword: 'OldPass1', newPassword: 'abcdefgh', confirmPassword: 'abcdefgh' }).join('|'), /同时包含字母和数字/)
|
||||
})
|
||||
|
||||
test('grades password strength without making extra complexity mandatory', () => {
|
||||
assert.equal(getPasswordStrength('short'), 'weak')
|
||||
assert.equal(getPasswordStrength('Password1'), 'medium')
|
||||
assert.equal(getPasswordStrength('Stronger@2026'), 'strong')
|
||||
})
|
||||
Reference in New Issue
Block a user