fix(identity): 优化默认昵称生成格式

将新用户默认昵称从「用户D2512140001」改为「用户1」,
使用 accountSequence.dailySequence 提取当日序号并去除前导零。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-14 00:59:01 -08:00
parent 35f5d54a0c
commit cd742856c0
2 changed files with 79 additions and 79 deletions

View File

@ -89,7 +89,7 @@ export class UserAccount {
)); ));
// UserID将由数据库自动生成(autoincrement)这里使用临时值0 // UserID将由数据库自动生成(autoincrement)这里使用临时值0
const nickname = params.nickname || `用户${params.accountSequence.value}`; const nickname = params.nickname || `用户${params.accountSequence.dailySequence}`;
const avatarUrl = params.avatarSvg || null; const avatarUrl = params.avatarSvg || null;
const account = new UserAccount( const account = new UserAccount(
@ -129,7 +129,7 @@ export class UserAccount {
// UserID将由数据库自动生成(autoincrement)这里使用临时值0 // UserID将由数据库自动生成(autoincrement)这里使用临时值0
const account = new UserAccount( const account = new UserAccount(
UserId.create(0), params.accountSequence, devices, params.phoneNumber, UserId.create(0), params.accountSequence, devices, params.phoneNumber,
`用户${params.accountSequence.value}`, null, params.inviterSequence, `用户${params.accountSequence.dailySequence}`, null, params.inviterSequence,
ReferralCode.generate(), ReferralCode.generate(),
new Map(), null, KYCStatus.NOT_VERIFIED, AccountStatus.ACTIVE, new Map(), null, KYCStatus.NOT_VERIFIED, AccountStatus.ACTIVE,
new Date(), null, new Date(), new Date(), null, new Date(),

View File

@ -1,77 +1,77 @@
import { UserAccount } from './user-account.aggregate'; import { UserAccount } from './user-account.aggregate';
import { AccountSequence } from '@/domain/value-objects'; import { AccountSequence } from '@/domain/value-objects';
import { DomainError } from '@/shared/exceptions/domain.exception'; import { DomainError } from '@/shared/exceptions/domain.exception';
describe('UserAccount', () => { describe('UserAccount', () => {
const createTestAccount = () => { const createTestAccount = () => {
return UserAccount.createAutomatic({ return UserAccount.createAutomatic({
accountSequence: AccountSequence.create(1), accountSequence: AccountSequence.create('D2512140001'),
initialDeviceId: 'device-001', initialDeviceId: 'device-001',
deviceName: 'Test Device', deviceName: 'Test Device',
inviterSequence: null, inviterSequence: null,
}); });
}; };
describe('createAutomatic', () => { describe('createAutomatic', () => {
it('should create account with default values', () => { it('should create account with default values', () => {
const account = createTestAccount(); const account = createTestAccount();
expect(account.accountSequence.value).toBe(1); expect(account.accountSequence.value).toBe('D2512140001');
expect(account.nickname).toBe('用户1'); expect(account.nickname).toBe('用户1');
expect(account.isActive).toBe(true); expect(account.isActive).toBe(true);
expect(account.phoneNumber).toBeNull(); expect(account.phoneNumber).toBeNull();
}); });
it('should add initial device', () => { it('should add initial device', () => {
const account = createTestAccount(); const account = createTestAccount();
expect(account.isDeviceAuthorized('device-001')).toBe(true); expect(account.isDeviceAuthorized('device-001')).toBe(true);
expect(account.getAllDevices()).toHaveLength(1); expect(account.getAllDevices()).toHaveLength(1);
}); });
}); });
describe('addDevice', () => { describe('addDevice', () => {
it('should add new device', () => { it('should add new device', () => {
const account = createTestAccount(); const account = createTestAccount();
account.addDevice('device-002', 'New Device'); account.addDevice('device-002', 'New Device');
expect(account.getAllDevices()).toHaveLength(2); expect(account.getAllDevices()).toHaveLength(2);
}); });
it('should throw error when exceeding device limit', () => { it('should throw error when exceeding device limit', () => {
const account = createTestAccount(); const account = createTestAccount();
account.addDevice('device-002'); account.addDevice('device-002');
account.addDevice('device-003'); account.addDevice('device-003');
account.addDevice('device-004'); account.addDevice('device-004');
account.addDevice('device-005'); account.addDevice('device-005');
expect(() => account.addDevice('device-006')).toThrow(DomainError); expect(() => account.addDevice('device-006')).toThrow(DomainError);
}); });
}); });
describe('removeDevice', () => { describe('removeDevice', () => {
it('should remove existing device', () => { it('should remove existing device', () => {
const account = createTestAccount(); const account = createTestAccount();
account.addDevice('device-002'); account.addDevice('device-002');
account.removeDevice('device-002'); account.removeDevice('device-002');
expect(account.getAllDevices()).toHaveLength(1); expect(account.getAllDevices()).toHaveLength(1);
}); });
it('should not remove last device', () => { it('should not remove last device', () => {
const account = createTestAccount(); const account = createTestAccount();
expect(() => account.removeDevice('device-001')).toThrow(DomainError); expect(() => account.removeDevice('device-001')).toThrow(DomainError);
}); });
}); });
describe('freeze/unfreeze', () => { describe('freeze/unfreeze', () => {
it('should freeze active account', () => { it('should freeze active account', () => {
const account = createTestAccount(); const account = createTestAccount();
account.freeze('Test reason'); account.freeze('Test reason');
expect(account.isActive).toBe(false); expect(account.isActive).toBe(false);
}); });
it('should unfreeze frozen account', () => { it('should unfreeze frozen account', () => {
const account = createTestAccount(); const account = createTestAccount();
account.freeze('Test reason'); account.freeze('Test reason');
account.unfreeze(); account.unfreeze();
expect(account.isActive).toBe(true); expect(account.isActive).toBe(true);
}); });
}); });
}); });