| | |
| | | |
| | | import com.tourguide.modules.operation.mapper.OperationCityMapper; |
| | | import com.tourguide.modules.operation.mapper.OperationScenicSpotMapper; |
| | | import com.tourguide.modules.user.dto.GuideUserDetailUpdateRequest; |
| | | import com.tourguide.modules.user.dto.GuideUserDetailResponse; |
| | | import com.tourguide.modules.user.entity.GuideApplication; |
| | | import com.tourguide.modules.user.entity.GuideUser; |
| | |
| | | import static org.assertj.core.api.Assertions.assertThat; |
| | | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| | | import static org.mockito.ArgumentMatchers.any; |
| | | import static org.mockito.ArgumentMatchers.eq; |
| | | import static org.mockito.Mockito.mock; |
| | | import static org.mockito.Mockito.verify; |
| | | import static org.mockito.Mockito.when; |
| | |
| | | } |
| | | |
| | | @Test |
| | | void shouldReuseCancelledGuideForNewRegistration() { |
| | | void shouldCreateNewGuideForCancelledRegistration() { |
| | | GuideUser cancelledGuide = new GuideUser(); |
| | | cancelledGuide.setId(12L); |
| | | cancelledGuide.setStatus(GuideUserService.STATUS_CANCELLED); |
| | | cancelledGuide.setMobile("13800138000"); |
| | | cancelledGuide.setUsername("13800138000"); |
| | | cancelledGuide.setCertificateNo("CERT-12"); |
| | | cancelledGuide.setIdCardNo("11010519491231002X"); |
| | | cancelledGuide.setAutoDisableWhitelisted(1); |
| | | cancelledGuide.setAutoDisabled(1); |
| | | when(userMapper.selectOne(any())).thenReturn(cancelledGuide); |
| | |
| | | |
| | | service.createPendingFromApplication(application); |
| | | |
| | | ArgumentCaptor<GuideUser> captor = ArgumentCaptor.forClass(GuideUser.class); |
| | | verify(userMapper).updateById(captor.capture()); |
| | | GuideUser reusedGuide = captor.getValue(); |
| | | assertThat(reusedGuide.getStatus()).isEqualTo(GuideUserService.STATUS_PENDING); |
| | | assertThat(reusedGuide.getAutoDisableWhitelisted()).isZero(); |
| | | assertThat(reusedGuide.getAutoDisabled()).isZero(); |
| | | verify(userMapper).anonymizeCancelledGuide(eq(12L), org.mockito.ArgumentMatchers.argThat( |
| | | username -> username.startsWith("deleted_") && username.length() == 32)); |
| | | verify(userMapper).clearCancelledIdentityByIdCard("11010519491231002X"); |
| | | |
| | | ArgumentCaptor<GuideUser> insertCaptor = ArgumentCaptor.forClass(GuideUser.class); |
| | | verify(userMapper).insert(insertCaptor.capture()); |
| | | GuideUser newGuide = insertCaptor.getValue(); |
| | | assertThat(newGuide.getStatus()).isEqualTo(GuideUserService.STATUS_PENDING); |
| | | assertThat(newGuide.getUsername()).isEqualTo("13800138000"); |
| | | assertThat(newGuide.getMobile()).isEqualTo("13800138000"); |
| | | assertThat(newGuide.getAutoDisableWhitelisted()).isNull(); |
| | | assertThat(newGuide.getAutoDisabled()).isNull(); |
| | | } |
| | | |
| | | @Test |
| | | void shouldReleaseIdentityFromStaleCancelledGuideBeforeNewRegistration() { |
| | | GuideApplication application = new GuideApplication(); |
| | | application.setMobile("13900139000"); |
| | | application.setRealName("新导游"); |
| | | application.setIdCardNo("11010519491231002X"); |
| | | when(userMapper.selectOne(any())).thenReturn(null); |
| | | |
| | | service.createPendingFromApplication(application); |
| | | |
| | | verify(userMapper).clearCancelledIdentityByIdCard("11010519491231002X"); |
| | | verify(userMapper).insert(any(GuideUser.class)); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | GuideApplication application = new GuideApplication(); |
| | | application.setIdCardNo(guide.getIdCardNo()); |
| | | application.setAgeRange("26-35岁"); |
| | | application.setWorkYearRange("1-3年"); |
| | | when(applicationMapper.selectOne(any())).thenReturn(application); |
| | | |
| | |
| | | assertThat(response.getBirthDate()).isEqualTo(LocalDate.of(1949, 12, 31)); |
| | | assertThat(response.getAge()).isEqualTo(Period.between(LocalDate.of(1949, 12, 31), LocalDate.now()).getYears()); |
| | | assertThat(response.getWorkYears()).isEqualTo(1); |
| | | assertThat(response.getAgeRange()).isEqualTo("26-35岁"); |
| | | assertThat(response.getWorkYearRange()).isEqualTo("1-3年"); |
| | | } |
| | | |
| | | @Test |
| | | void adminPhoneChangeShouldUpdatePhoneLoginIdentity() { |
| | | GuideUser guide = new GuideUser(); |
| | | guide.setId(12L); |
| | | guide.setStatus(GuideUserService.STATUS_ENABLED); |
| | | guide.setUsername("13800138000"); |
| | | guide.setMobile("13800138000"); |
| | | when(userMapper.selectForUpdate(12L)).thenReturn(guide); |
| | | when(userMapper.selectById(12L)).thenReturn(guide); |
| | | |
| | | GuideUserDetailUpdateRequest request = new GuideUserDetailUpdateRequest(); |
| | | request.setRealName("导游"); |
| | | request.setMobile("13900139000"); |
| | | |
| | | service.updateDetail(12L, request); |
| | | |
| | | assertThat(guide.getMobile()).isEqualTo("13900139000"); |
| | | assertThat(guide.getUsername()).isEqualTo("13900139000"); |
| | | verify(userMapper).updateById(guide); |
| | | } |
| | | |
| | | @Test |