fix(test): 修复测试文件 TypeScript 类型错误
authorization-service: - UserId.create 第二个参数 accountSequence 由 BigInt 改为 string - mockAuthorizationRoleRepository 添加缺失的方法 - TeamStatistics mock 对象添加 selfPlantingCount 和 subordinateTeamPlantingCount reward-service: - accountSequence 由 BigInt 改为 string 类型 - 方法调用参数名由 userId 改为 accountSequence 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f20643599e
commit
701deb1e27
|
|
@ -30,6 +30,20 @@ describe('Domain Services Integration Tests', () => {
|
||||||
findByAccountSequenceAndRoleType: jest.fn(),
|
findByAccountSequenceAndRoleType: jest.fn(),
|
||||||
findByAccountSequence: jest.fn(),
|
findByAccountSequence: jest.fn(),
|
||||||
findActiveCommunityByAccountSequences: jest.fn(),
|
findActiveCommunityByAccountSequences: jest.fn(),
|
||||||
|
findActiveProvinceByAccountSequencesAndRegion: jest.fn(),
|
||||||
|
findActiveCityByAccountSequencesAndRegion: jest.fn(),
|
||||||
|
findCommunityByAccountSequences: jest.fn(),
|
||||||
|
findAuthProvinceByAccountSequencesAndRegion: jest.fn(),
|
||||||
|
findAuthCityByAccountSequencesAndRegion: jest.fn(),
|
||||||
|
findAuthProvinceByAccountSequences: jest.fn(),
|
||||||
|
findAuthCityByAccountSequences: jest.fn(),
|
||||||
|
findProvinceCompanyByRegion: jest.fn(),
|
||||||
|
findCityCompanyByRegion: jest.fn(),
|
||||||
|
findExpiredActiveByRoleType: jest.fn(),
|
||||||
|
findCommunityByName: jest.fn(),
|
||||||
|
findAllByUserIdIncludeDeleted: jest.fn(),
|
||||||
|
findAllByAccountSequenceIncludeDeleted: jest.fn(),
|
||||||
|
findByIdIncludeDeleted: jest.fn(),
|
||||||
}
|
}
|
||||||
|
|
||||||
const mockMonthlyAssessmentRepository: jest.Mocked<IMonthlyAssessmentRepository> = {
|
const mockMonthlyAssessmentRepository: jest.Mocked<IMonthlyAssessmentRepository> = {
|
||||||
|
|
@ -97,7 +111,7 @@ describe('Domain Services Integration Tests', () => {
|
||||||
describe('AuthorizationValidatorService', () => {
|
describe('AuthorizationValidatorService', () => {
|
||||||
describe('validateAuthorizationRequest', () => {
|
describe('validateAuthorizationRequest', () => {
|
||||||
it('should return success when no conflicts in referral chain', async () => {
|
it('should return success when no conflicts in referral chain', async () => {
|
||||||
const userId = UserId.create('user-123', BigInt(123))
|
const userId = UserId.create('user-123', 'D2412190123')
|
||||||
const roleType = RoleType.AUTH_PROVINCE_COMPANY
|
const roleType = RoleType.AUTH_PROVINCE_COMPANY
|
||||||
const regionCode = RegionCode.create('430000')
|
const regionCode = RegionCode.create('430000')
|
||||||
|
|
||||||
|
|
@ -116,7 +130,7 @@ describe('Domain Services Integration Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return failure when user already has province authorization', async () => {
|
it('should return failure when user already has province authorization', async () => {
|
||||||
const userId = UserId.create('user-123', BigInt(123))
|
const userId = UserId.create('user-123', 'D2412190123')
|
||||||
const roleType = RoleType.AUTH_PROVINCE_COMPANY
|
const roleType = RoleType.AUTH_PROVINCE_COMPANY
|
||||||
const regionCode = RegionCode.create('430000')
|
const regionCode = RegionCode.create('430000')
|
||||||
|
|
||||||
|
|
@ -140,11 +154,11 @@ describe('Domain Services Integration Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return failure when ancestor has same region authorization', async () => {
|
it('should return failure when ancestor has same region authorization', async () => {
|
||||||
const userId = UserId.create('user-123', BigInt(123))
|
const userId = UserId.create('user-123', 'D2412190123')
|
||||||
const roleType = RoleType.AUTH_PROVINCE_COMPANY
|
const roleType = RoleType.AUTH_PROVINCE_COMPANY
|
||||||
const regionCode = RegionCode.create('430000')
|
const regionCode = RegionCode.create('430000')
|
||||||
|
|
||||||
const ancestorUserId = UserId.create('ancestor-user', BigInt(999))
|
const ancestorUserId = UserId.create('ancestor-user', 'D2412190999')
|
||||||
|
|
||||||
mockAuthorizationRoleRepository.findByUserIdAndRoleType.mockResolvedValue(null)
|
mockAuthorizationRoleRepository.findByUserIdAndRoleType.mockResolvedValue(null)
|
||||||
mockReferralRepository.findByUserId.mockResolvedValue({ parentId: 'ancestor-user' })
|
mockReferralRepository.findByUserId.mockResolvedValue({ parentId: 'ancestor-user' })
|
||||||
|
|
@ -181,18 +195,18 @@ describe('Domain Services Integration Tests', () => {
|
||||||
|
|
||||||
// Mock two authorizations
|
// Mock two authorizations
|
||||||
const auth1 = AuthorizationRole.createAuthProvinceCompany({
|
const auth1 = AuthorizationRole.createAuthProvinceCompany({
|
||||||
userId: UserId.create('user-1', BigInt(1)),
|
userId: UserId.create('user-1', 'D2412190001'),
|
||||||
provinceCode: '430000',
|
provinceCode: '430000',
|
||||||
provinceName: '湖南省',
|
provinceName: '湖南省',
|
||||||
})
|
})
|
||||||
auth1.authorize(UserId.create('admin', BigInt(100)))
|
auth1.authorize(UserId.create('admin', 'D2412190100'))
|
||||||
|
|
||||||
const auth2 = AuthorizationRole.createAuthProvinceCompany({
|
const auth2 = AuthorizationRole.createAuthProvinceCompany({
|
||||||
userId: UserId.create('user-2', BigInt(2)),
|
userId: UserId.create('user-2', 'D2412190002'),
|
||||||
provinceCode: '430000',
|
provinceCode: '430000',
|
||||||
provinceName: '湖南省',
|
provinceName: '湖南省',
|
||||||
})
|
})
|
||||||
auth2.authorize(UserId.create('admin', BigInt(100)))
|
auth2.authorize(UserId.create('admin', 'D2412190100'))
|
||||||
|
|
||||||
mockAuthorizationRoleRepository.findActiveByRoleTypeAndRegion.mockResolvedValue([auth1, auth2])
|
mockAuthorizationRoleRepository.findActiveByRoleTypeAndRegion.mockResolvedValue([auth1, auth2])
|
||||||
mockMonthlyAssessmentRepository.findByAuthorizationAndMonth.mockResolvedValue(null)
|
mockMonthlyAssessmentRepository.findByAuthorizationAndMonth.mockResolvedValue(null)
|
||||||
|
|
@ -201,15 +215,19 @@ describe('Domain Services Integration Tests', () => {
|
||||||
mockTeamStatisticsRepository.findByUserId
|
mockTeamStatisticsRepository.findByUserId
|
||||||
.mockResolvedValueOnce({
|
.mockResolvedValueOnce({
|
||||||
userId: 'user-1',
|
userId: 'user-1',
|
||||||
accountSequence: BigInt(1),
|
accountSequence: 'D2412190001',
|
||||||
totalTeamPlantingCount: 200,
|
totalTeamPlantingCount: 200,
|
||||||
|
selfPlantingCount: 10,
|
||||||
|
get subordinateTeamPlantingCount() { return this.totalTeamPlantingCount - this.selfPlantingCount },
|
||||||
getProvinceTeamCount: () => 70,
|
getProvinceTeamCount: () => 70,
|
||||||
getCityTeamCount: () => 0,
|
getCityTeamCount: () => 0,
|
||||||
})
|
})
|
||||||
.mockResolvedValueOnce({
|
.mockResolvedValueOnce({
|
||||||
userId: 'user-2',
|
userId: 'user-2',
|
||||||
accountSequence: BigInt(2),
|
accountSequence: 'D2412190002',
|
||||||
totalTeamPlantingCount: 100,
|
totalTeamPlantingCount: 100,
|
||||||
|
selfPlantingCount: 5,
|
||||||
|
get subordinateTeamPlantingCount() { return this.totalTeamPlantingCount - this.selfPlantingCount },
|
||||||
getProvinceTeamCount: () => 35,
|
getProvinceTeamCount: () => 35,
|
||||||
getCityTeamCount: () => 0,
|
getCityTeamCount: () => 0,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -96,14 +96,14 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
|
|
||||||
const mockReward = RewardLedgerEntry.createPending({
|
const mockReward = RewardLedgerEntry.createPending({
|
||||||
userId: BigInt(200),
|
userId: BigInt(200),
|
||||||
accountSequence: BigInt(100),
|
accountSequence: 'D2412190100',
|
||||||
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(100)),
|
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(100)),
|
||||||
usdtAmount: Money.USDT(500),
|
usdtAmount: Money.USDT(500),
|
||||||
hashpowerAmount: Hashpower.zero(),
|
hashpowerAmount: Hashpower.zero(),
|
||||||
memo: 'Test',
|
memo: 'Test',
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockSummary = RewardSummary.create(BigInt(200), BigInt(100));
|
const mockSummary = RewardSummary.create(BigInt(200), 'D2412190100');
|
||||||
|
|
||||||
mockCalculationService.calculateRewards.mockResolvedValue([mockReward]);
|
mockCalculationService.calculateRewards.mockResolvedValue([mockReward]);
|
||||||
mockSummaryRepository.getOrCreate.mockResolvedValue(mockSummary);
|
mockSummaryRepository.getOrCreate.mockResolvedValue(mockSummary);
|
||||||
|
|
@ -123,14 +123,14 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
|
|
||||||
const pendingReward = RewardLedgerEntry.createPending({
|
const pendingReward = RewardLedgerEntry.createPending({
|
||||||
userId,
|
userId,
|
||||||
accountSequence: BigInt(100),
|
accountSequence: 'D2412190100',
|
||||||
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
||||||
usdtAmount: Money.USDT(500),
|
usdtAmount: Money.USDT(500),
|
||||||
hashpowerAmount: Hashpower.zero(),
|
hashpowerAmount: Hashpower.zero(),
|
||||||
memo: 'Test reward',
|
memo: 'Test reward',
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockSummary = RewardSummary.create(userId, BigInt(100));
|
const mockSummary = RewardSummary.create(userId, 'D2412190100');
|
||||||
mockSummary.addPending(
|
mockSummary.addPending(
|
||||||
Money.USDT(500),
|
Money.USDT(500),
|
||||||
Hashpower.zero(),
|
Hashpower.zero(),
|
||||||
|
|
@ -154,7 +154,7 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
const expiredReward = RewardLedgerEntry.reconstitute({
|
const expiredReward = RewardLedgerEntry.reconstitute({
|
||||||
id: BigInt(1),
|
id: BigInt(1),
|
||||||
userId,
|
userId,
|
||||||
accountSequence: BigInt(100),
|
accountSequence: 'D2412190100',
|
||||||
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
||||||
usdtAmount: 500,
|
usdtAmount: 500,
|
||||||
hashpowerAmount: 0,
|
hashpowerAmount: 0,
|
||||||
|
|
@ -167,7 +167,7 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
memo: 'Expired reward',
|
memo: 'Expired reward',
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockSummary = RewardSummary.create(userId, BigInt(100));
|
const mockSummary = RewardSummary.create(userId, 'D2412190100');
|
||||||
|
|
||||||
mockLedgerRepository.findPendingByUserId.mockResolvedValue([expiredReward]);
|
mockLedgerRepository.findPendingByUserId.mockResolvedValue([expiredReward]);
|
||||||
mockSummaryRepository.getOrCreate.mockResolvedValue(mockSummary);
|
mockSummaryRepository.getOrCreate.mockResolvedValue(mockSummary);
|
||||||
|
|
@ -181,12 +181,12 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
|
|
||||||
describe('settleRewards', () => {
|
describe('settleRewards', () => {
|
||||||
it('should settle rewards and call wallet service', async () => {
|
it('should settle rewards and call wallet service', async () => {
|
||||||
const accountSequence = BigInt(100);
|
const accountSequence = 'D2412190100';
|
||||||
|
|
||||||
const settleableReward = RewardLedgerEntry.reconstitute({
|
const settleableReward = RewardLedgerEntry.reconstitute({
|
||||||
id: BigInt(1),
|
id: BigInt(1),
|
||||||
userId: BigInt(100),
|
userId: BigInt(100),
|
||||||
accountSequence: BigInt(100),
|
accountSequence: 'D2412190100',
|
||||||
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
||||||
usdtAmount: 500,
|
usdtAmount: 500,
|
||||||
hashpowerAmount: 0,
|
hashpowerAmount: 0,
|
||||||
|
|
@ -199,7 +199,7 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
memo: 'Test',
|
memo: 'Test',
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockSummary = RewardSummary.create(BigInt(100), BigInt(100));
|
const mockSummary = RewardSummary.create(BigInt(100), 'D2412190100');
|
||||||
mockSummary.addSettleable(Money.USDT(500), Hashpower.zero());
|
mockSummary.addSettleable(Money.USDT(500), Hashpower.zero());
|
||||||
|
|
||||||
mockLedgerRepository.findSettleableByUserId.mockResolvedValue([settleableReward]);
|
mockLedgerRepository.findSettleableByUserId.mockResolvedValue([settleableReward]);
|
||||||
|
|
@ -227,7 +227,7 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return error when no settleable rewards', async () => {
|
it('should return error when no settleable rewards', async () => {
|
||||||
const accountSequence = BigInt(100);
|
const accountSequence = 'D2412190100';
|
||||||
|
|
||||||
mockLedgerRepository.findSettleableByUserId.mockResolvedValue([]);
|
mockLedgerRepository.findSettleableByUserId.mockResolvedValue([]);
|
||||||
|
|
||||||
|
|
@ -241,12 +241,12 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle wallet service failure', async () => {
|
it('should handle wallet service failure', async () => {
|
||||||
const accountSequence = BigInt(100);
|
const accountSequence = 'D2412190100';
|
||||||
|
|
||||||
const settleableReward = RewardLedgerEntry.reconstitute({
|
const settleableReward = RewardLedgerEntry.reconstitute({
|
||||||
id: BigInt(1),
|
id: BigInt(1),
|
||||||
userId: BigInt(100),
|
userId: BigInt(100),
|
||||||
accountSequence: BigInt(100),
|
accountSequence: 'D2412190100',
|
||||||
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
||||||
usdtAmount: 500,
|
usdtAmount: 500,
|
||||||
hashpowerAmount: 0,
|
hashpowerAmount: 0,
|
||||||
|
|
@ -259,7 +259,7 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
memo: 'Test',
|
memo: 'Test',
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockSummary = RewardSummary.create(BigInt(100), BigInt(100));
|
const mockSummary = RewardSummary.create(BigInt(100), 'D2412190100');
|
||||||
mockSummary.addSettleable(Money.USDT(500), Hashpower.zero());
|
mockSummary.addSettleable(Money.USDT(500), Hashpower.zero());
|
||||||
|
|
||||||
mockLedgerRepository.findSettleableByUserId.mockResolvedValue([settleableReward]);
|
mockLedgerRepository.findSettleableByUserId.mockResolvedValue([settleableReward]);
|
||||||
|
|
@ -281,12 +281,12 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
|
|
||||||
describe('getRewardSummary', () => {
|
describe('getRewardSummary', () => {
|
||||||
it('should return reward summary for user', async () => {
|
it('should return reward summary for user', async () => {
|
||||||
const userId = BigInt(100);
|
const accountSequence = 'D2412190100';
|
||||||
const mockSummary = RewardSummary.create(userId, BigInt(100));
|
const mockSummary = RewardSummary.create(BigInt(100), accountSequence);
|
||||||
|
|
||||||
mockSummaryRepository.findByUserId.mockResolvedValue(mockSummary);
|
mockSummaryRepository.findByAccountSequence.mockResolvedValue(mockSummary);
|
||||||
|
|
||||||
const result = await service.getRewardSummary(userId);
|
const result = await service.getRewardSummary(accountSequence);
|
||||||
|
|
||||||
expect(result.pendingUsdt).toBe(0);
|
expect(result.pendingUsdt).toBe(0);
|
||||||
expect(result.settleableUsdt).toBe(0);
|
expect(result.settleableUsdt).toBe(0);
|
||||||
|
|
@ -295,11 +295,11 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return zero values when no summary exists', async () => {
|
it('should return zero values when no summary exists', async () => {
|
||||||
const userId = BigInt(100);
|
const accountSequence = 'D2412190100';
|
||||||
|
|
||||||
mockSummaryRepository.findByUserId.mockResolvedValue(null);
|
mockSummaryRepository.findByAccountSequence.mockResolvedValue(null);
|
||||||
|
|
||||||
const result = await service.getRewardSummary(userId);
|
const result = await service.getRewardSummary(accountSequence);
|
||||||
|
|
||||||
expect(result.pendingUsdt).toBe(0);
|
expect(result.pendingUsdt).toBe(0);
|
||||||
expect(result.settleableUsdt).toBe(0);
|
expect(result.settleableUsdt).toBe(0);
|
||||||
|
|
@ -308,11 +308,11 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
|
|
||||||
describe('getRewardDetails', () => {
|
describe('getRewardDetails', () => {
|
||||||
it('should return paginated reward details', async () => {
|
it('should return paginated reward details', async () => {
|
||||||
const userId = BigInt(100);
|
const accountSequence = 'D2412190100';
|
||||||
const mockReward = RewardLedgerEntry.reconstitute({
|
const mockReward = RewardLedgerEntry.reconstitute({
|
||||||
id: BigInt(1),
|
id: BigInt(1),
|
||||||
userId,
|
userId: BigInt(100),
|
||||||
accountSequence: BigInt(100),
|
accountSequence,
|
||||||
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
||||||
usdtAmount: 500,
|
usdtAmount: 500,
|
||||||
hashpowerAmount: 0,
|
hashpowerAmount: 0,
|
||||||
|
|
@ -325,10 +325,10 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
memo: 'Test',
|
memo: 'Test',
|
||||||
});
|
});
|
||||||
|
|
||||||
mockLedgerRepository.findByUserId.mockResolvedValue([mockReward]);
|
mockLedgerRepository.findByAccountSequence.mockResolvedValue([mockReward]);
|
||||||
mockLedgerRepository.countByUserId.mockResolvedValue(1);
|
mockLedgerRepository.countByAccountSequence.mockResolvedValue(1);
|
||||||
|
|
||||||
const result = await service.getRewardDetails(userId, {}, { page: 1, pageSize: 20 });
|
const result = await service.getRewardDetails(accountSequence, {}, { page: 1, pageSize: 20 });
|
||||||
|
|
||||||
expect(result.data).toHaveLength(1);
|
expect(result.data).toHaveLength(1);
|
||||||
expect(result.data[0].usdtAmount).toBe(500);
|
expect(result.data[0].usdtAmount).toBe(500);
|
||||||
|
|
@ -338,20 +338,20 @@ describe('RewardApplicationService (Integration)', () => {
|
||||||
|
|
||||||
describe('getPendingRewards', () => {
|
describe('getPendingRewards', () => {
|
||||||
it('should return pending rewards with countdown', async () => {
|
it('should return pending rewards with countdown', async () => {
|
||||||
const userId = BigInt(100);
|
const accountSequence = 'D2412190100';
|
||||||
|
|
||||||
const pendingReward = RewardLedgerEntry.createPending({
|
const pendingReward = RewardLedgerEntry.createPending({
|
||||||
userId,
|
userId: BigInt(100),
|
||||||
accountSequence: BigInt(100),
|
accountSequence,
|
||||||
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
rewardSource: RewardSource.create(RightType.SHARE_RIGHT, 'ORDER001', BigInt(50)),
|
||||||
usdtAmount: Money.USDT(500),
|
usdtAmount: Money.USDT(500),
|
||||||
hashpowerAmount: Hashpower.zero(),
|
hashpowerAmount: Hashpower.zero(),
|
||||||
memo: 'Test',
|
memo: 'Test',
|
||||||
});
|
});
|
||||||
|
|
||||||
mockLedgerRepository.findPendingByUserId.mockResolvedValue([pendingReward]);
|
mockLedgerRepository.findPendingByAccountSequence.mockResolvedValue([pendingReward]);
|
||||||
|
|
||||||
const result = await service.getPendingRewards(userId);
|
const result = await service.getPendingRewards(accountSequence);
|
||||||
|
|
||||||
expect(result).toHaveLength(1);
|
expect(result).toHaveLength(1);
|
||||||
expect(result[0].usdtAmount).toBe(500);
|
expect(result[0].usdtAmount).toBe(500);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue