| | |
| | | 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; |
| | |
| | | |
| | | service.createPendingFromApplication(application); |
| | | |
| | | ArgumentCaptor<GuideUser> updateCaptor = ArgumentCaptor.forClass(GuideUser.class); |
| | | verify(userMapper).updateById(updateCaptor.capture()); |
| | | GuideUser anonymizedGuide = updateCaptor.getValue(); |
| | | assertThat(anonymizedGuide.getStatus()).isEqualTo(GuideUserService.STATUS_CANCELLED); |
| | | assertThat(anonymizedGuide.getUsername()).startsWith("deleted_").hasSize(32); |
| | | assertThat(anonymizedGuide.getMobile()).isNull(); |
| | | assertThat(anonymizedGuide.getCertificateNo()).isNull(); |
| | | assertThat(anonymizedGuide.getIdCardNo()).isNull(); |
| | | 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()); |
| | |
| | | } |
| | | |
| | | @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 |
| | | void shouldReleaseIdentityFromStalePendingGuideBeforeNewRegistration() { |
| | | 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).clearPendingIdentityByIdCard("11010519491231002X"); |
| | | verify(userMapper).insert(any(GuideUser.class)); |
| | | } |
| | | |
| | | @Test |
| | | void shouldReleasePendingIdentityWhenRejectingApplication() { |
| | | GuideUser pendingGuide = new GuideUser(); |
| | | pendingGuide.setId(12L); |
| | | pendingGuide.setStatus(GuideUserService.STATUS_PENDING); |
| | | pendingGuide.setMobile("13800138000"); |
| | | when(userMapper.selectOne(any())).thenReturn(pendingGuide); |
| | | |
| | | service.releaseIdentityForRejectedApplication("13800138000"); |
| | | |
| | | verify(userMapper).releasePendingIdentity(12L); |
| | | } |
| | | |
| | | @Test |
| | | void shouldTreatOneYearOrLessAsZeroWorkYears() { |
| | | GuideApplication application = new GuideApplication(); |
| | | application.setMobile("13800138000"); |