From cd742856c0bf251aaa70e3fb9943303f83a42e78 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 14 Dec 2025 00:59:01 -0800 Subject: [PATCH] =?UTF-8?q?fix(identity):=20=E4=BC=98=E5=8C=96=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=98=B5=E7=A7=B0=E7=94=9F=E6=88=90=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将新用户默认昵称从「用户D2512140001」改为「用户1」, 使用 accountSequence.dailySequence 提取当日序号并去除前导零。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../user-account/user-account.aggregate.ts | 4 +- .../user-account/user-account.spec.ts | 154 +++++++++--------- 2 files changed, 79 insertions(+), 79 deletions(-) diff --git a/backend/services/identity-service/src/domain/aggregates/user-account/user-account.aggregate.ts b/backend/services/identity-service/src/domain/aggregates/user-account/user-account.aggregate.ts index a3ecc05d..b42f3ba7 100644 --- a/backend/services/identity-service/src/domain/aggregates/user-account/user-account.aggregate.ts +++ b/backend/services/identity-service/src/domain/aggregates/user-account/user-account.aggregate.ts @@ -89,7 +89,7 @@ export class UserAccount { )); // UserID将由数据库自动生成(autoincrement),这里使用临时值0 - const nickname = params.nickname || `用户${params.accountSequence.value}`; + const nickname = params.nickname || `用户${params.accountSequence.dailySequence}`; const avatarUrl = params.avatarSvg || null; const account = new UserAccount( @@ -129,7 +129,7 @@ export class UserAccount { // UserID将由数据库自动生成(autoincrement),这里使用临时值0 const account = new UserAccount( UserId.create(0), params.accountSequence, devices, params.phoneNumber, - `用户${params.accountSequence.value}`, null, params.inviterSequence, + `用户${params.accountSequence.dailySequence}`, null, params.inviterSequence, ReferralCode.generate(), new Map(), null, KYCStatus.NOT_VERIFIED, AccountStatus.ACTIVE, new Date(), null, new Date(), diff --git a/backend/services/identity-service/src/domain/aggregates/user-account/user-account.spec.ts b/backend/services/identity-service/src/domain/aggregates/user-account/user-account.spec.ts index 2d5c1d84..dac0f592 100644 --- a/backend/services/identity-service/src/domain/aggregates/user-account/user-account.spec.ts +++ b/backend/services/identity-service/src/domain/aggregates/user-account/user-account.spec.ts @@ -1,77 +1,77 @@ -import { UserAccount } from './user-account.aggregate'; -import { AccountSequence } from '@/domain/value-objects'; -import { DomainError } from '@/shared/exceptions/domain.exception'; - -describe('UserAccount', () => { - const createTestAccount = () => { - return UserAccount.createAutomatic({ - accountSequence: AccountSequence.create(1), - initialDeviceId: 'device-001', - deviceName: 'Test Device', - inviterSequence: null, - }); - }; - - describe('createAutomatic', () => { - it('should create account with default values', () => { - const account = createTestAccount(); - expect(account.accountSequence.value).toBe(1); - expect(account.nickname).toBe('用户1'); - expect(account.isActive).toBe(true); - expect(account.phoneNumber).toBeNull(); - }); - - it('should add initial device', () => { - const account = createTestAccount(); - expect(account.isDeviceAuthorized('device-001')).toBe(true); - expect(account.getAllDevices()).toHaveLength(1); - }); - }); - - describe('addDevice', () => { - it('should add new device', () => { - const account = createTestAccount(); - account.addDevice('device-002', 'New Device'); - expect(account.getAllDevices()).toHaveLength(2); - }); - - it('should throw error when exceeding device limit', () => { - const account = createTestAccount(); - account.addDevice('device-002'); - account.addDevice('device-003'); - account.addDevice('device-004'); - account.addDevice('device-005'); - - expect(() => account.addDevice('device-006')).toThrow(DomainError); - }); - }); - - describe('removeDevice', () => { - it('should remove existing device', () => { - const account = createTestAccount(); - account.addDevice('device-002'); - account.removeDevice('device-002'); - expect(account.getAllDevices()).toHaveLength(1); - }); - - it('should not remove last device', () => { - const account = createTestAccount(); - expect(() => account.removeDevice('device-001')).toThrow(DomainError); - }); - }); - - describe('freeze/unfreeze', () => { - it('should freeze active account', () => { - const account = createTestAccount(); - account.freeze('Test reason'); - expect(account.isActive).toBe(false); - }); - - it('should unfreeze frozen account', () => { - const account = createTestAccount(); - account.freeze('Test reason'); - account.unfreeze(); - expect(account.isActive).toBe(true); - }); - }); -}); +import { UserAccount } from './user-account.aggregate'; +import { AccountSequence } from '@/domain/value-objects'; +import { DomainError } from '@/shared/exceptions/domain.exception'; + +describe('UserAccount', () => { + const createTestAccount = () => { + return UserAccount.createAutomatic({ + accountSequence: AccountSequence.create('D2512140001'), + initialDeviceId: 'device-001', + deviceName: 'Test Device', + inviterSequence: null, + }); + }; + + describe('createAutomatic', () => { + it('should create account with default values', () => { + const account = createTestAccount(); + expect(account.accountSequence.value).toBe('D2512140001'); + expect(account.nickname).toBe('用户1'); + expect(account.isActive).toBe(true); + expect(account.phoneNumber).toBeNull(); + }); + + it('should add initial device', () => { + const account = createTestAccount(); + expect(account.isDeviceAuthorized('device-001')).toBe(true); + expect(account.getAllDevices()).toHaveLength(1); + }); + }); + + describe('addDevice', () => { + it('should add new device', () => { + const account = createTestAccount(); + account.addDevice('device-002', 'New Device'); + expect(account.getAllDevices()).toHaveLength(2); + }); + + it('should throw error when exceeding device limit', () => { + const account = createTestAccount(); + account.addDevice('device-002'); + account.addDevice('device-003'); + account.addDevice('device-004'); + account.addDevice('device-005'); + + expect(() => account.addDevice('device-006')).toThrow(DomainError); + }); + }); + + describe('removeDevice', () => { + it('should remove existing device', () => { + const account = createTestAccount(); + account.addDevice('device-002'); + account.removeDevice('device-002'); + expect(account.getAllDevices()).toHaveLength(1); + }); + + it('should not remove last device', () => { + const account = createTestAccount(); + expect(() => account.removeDevice('device-001')).toThrow(DomainError); + }); + }); + + describe('freeze/unfreeze', () => { + it('should freeze active account', () => { + const account = createTestAccount(); + account.freeze('Test reason'); + expect(account.isActive).toBe(false); + }); + + it('should unfreeze frozen account', () => { + const account = createTestAccount(); + account.freeze('Test reason'); + account.unfreeze(); + expect(account.isActive).toBe(true); + }); + }); +});