| | |
| | | member.setPhone("13355555555"); |
| | | member.setAvatar("https://cdn.example.com/a.png"); |
| | | member.setSystemLevel(MemberLevelEnum.L3.getCode()); |
| | | member.setAuthStatus("2"); |
| | | EarningSummaryVo summary = new EarningSummaryVo(1000L, 40000L, 12800000L); |
| | | when(accountUserMapper.selectAccountUserById(66L)).thenReturn(member); |
| | | when(accountEarningRecordMapper.selectEarningSummary(66L)).thenReturn(summary); |
| | |
| | | assertEquals("133****5555", vo.getPhone()); |
| | | assertEquals("https://cdn.example.com/a.png", vo.getAvatar()); |
| | | assertEquals(MemberLevelEnum.L3.getCode(), vo.getMemberLevel()); |
| | | // 认证状态原样下发,供个人中心「实名认证」行徽标回显 |
| | | assertEquals("2", vo.getAuthStatus()); |
| | | assertEquals(1000L, vo.getEarnings().getToday()); |
| | | assertEquals(40000L, vo.getEarnings().getMonth()); |
| | | assertEquals(12800000L, vo.getEarnings().getTotal()); |
| | |
| | | assertFallbackLevel("L9", MemberLevelEnum.C.getCode()); |
| | | } |
| | | |
| | | @Test |
| | | @DisplayName("认证状态为空时应兜底为未认证(0)") |
| | | void getAccountUserInfo_shouldFallbackNoneAuthStatus_whenBlank() |
| | | { |
| | | AccountUser member = new AccountUser(); |
| | | member.setUserId(66L); |
| | | member.setSystemLevel(MemberLevelEnum.C.getCode()); |
| | | when(accountUserMapper.selectAccountUserById(66L)).thenReturn(member); |
| | | when(accountEarningRecordMapper.selectEarningSummary(66L)).thenReturn(EarningSummaryVo.zero()); |
| | | |
| | | AccountUserInfoVo vo = accountUserService.getAccountUserInfo(66L); |
| | | |
| | | assertEquals("0", vo.getAuthStatus()); |
| | | } |
| | | |
| | | /** |
| | | * 校验不同等级取值下的等级兜底结果 |
| | | * |
| | |
| | | |
| | | assertEquals(expectedLevel, vo.getMemberLevel()); |
| | | } |
| | | |
| | | @Test |
| | | @DisplayName("更新头像时应只写入 avatar 列") |
| | | void updateAvatar_shouldUpdateAvatar_whenValid() |
| | | { |
| | | when(accountUserMapper.updateUserAvatar(any(AccountUser.class))).thenReturn(1); |
| | | |
| | | accountUserService.updateAvatar(66L, "https://cdn.example.com/new.png"); |
| | | |
| | | ArgumentCaptor<AccountUser> captor = ArgumentCaptor.forClass(AccountUser.class); |
| | | verify(accountUserMapper).updateUserAvatar(captor.capture()); |
| | | assertEquals(66L, captor.getValue().getUserId()); |
| | | assertEquals("https://cdn.example.com/new.png", captor.getValue().getAvatar()); |
| | | } |
| | | |
| | | @Test |
| | | @DisplayName("头像地址为空时应抛出提示且不落库") |
| | | void updateAvatar_shouldThrow_whenAvatarBlank() |
| | | { |
| | | ServiceException ex = assertThrows(ServiceException.class, |
| | | () -> accountUserService.updateAvatar(66L, "")); |
| | | |
| | | assertEquals("头像地址不能为空", ex.getMessage()); |
| | | verify(accountUserMapper, never()).updateUserAvatar(any(AccountUser.class)); |
| | | } |
| | | |
| | | @Test |
| | | @DisplayName("头像地址超长时应抛出提示且不落库") |
| | | void updateAvatar_shouldThrow_whenAvatarTooLong() |
| | | { |
| | | String longUrl = "a".repeat(256); |
| | | |
| | | ServiceException ex = assertThrows(ServiceException.class, |
| | | () -> accountUserService.updateAvatar(66L, longUrl)); |
| | | |
| | | assertEquals("头像地址过长", ex.getMessage()); |
| | | verify(accountUserMapper, never()).updateUserAvatar(any(AccountUser.class)); |
| | | } |
| | | |
| | | @Test |
| | | @DisplayName("会员不存在(影响行数为 0)时应抛出更新失败") |
| | | void updateAvatar_shouldThrow_whenMemberNotFound() |
| | | { |
| | | when(accountUserMapper.updateUserAvatar(any(AccountUser.class))).thenReturn(0); |
| | | |
| | | ServiceException ex = assertThrows(ServiceException.class, |
| | | () -> accountUserService.updateAvatar(66L, "https://cdn.example.com/new.png")); |
| | | |
| | | assertEquals("更新头像失败", ex.getMessage()); |
| | | } |
| | | |
| | | @Test |
| | | @DisplayName("会员ID为空时应抛出更新失败") |
| | | void updateAvatar_shouldThrow_whenUserIdNull() |
| | | { |
| | | ServiceException ex = assertThrows(ServiceException.class, |
| | | () -> accountUserService.updateAvatar(null, "https://cdn.example.com/new.png")); |
| | | |
| | | assertEquals("更新头像失败", ex.getMessage()); |
| | | } |
| | | } |