| | |
| | | import com.tourguide.modules.operation.mapper.OperationCityMapper; |
| | | import com.tourguide.modules.user.dto.GuideRegistrationResponse; |
| | | import com.tourguide.modules.user.dto.GuideRegistrationSubmitRequest; |
| | | import com.tourguide.modules.user.dto.GuideRegistrationTokenResponse; |
| | | import com.tourguide.modules.user.dto.SmsCodeResponse; |
| | | import com.tourguide.modules.user.entity.GuideApplication; |
| | | import com.tourguide.modules.user.entity.GuideUser; |
| | | import com.tourguide.modules.user.mapper.GuideApplicationMapper; |
| | | import com.tourguide.modules.user.mapper.GuideTeamMapper; |
| | | import org.junit.jupiter.api.BeforeEach; |
| | |
| | | private StringRedisTemplate redisTemplate; |
| | | private ValueOperations<String, String> valueOperations; |
| | | private GuideApplicationMapper applicationMapper; |
| | | private GuideVerificationCodeService verificationCodeService; |
| | | private GuideUserService guideUserService; |
| | | private GuideRegistrationService service; |
| | | |
| | | @SuppressWarnings("unchecked") |
| | |
| | | .thenReturn("13800138000"); |
| | | when(applicationMapper.selectCount(any())).thenReturn(0L); |
| | | |
| | | GuideUserService guideUserService = mock(GuideUserService.class); |
| | | guideUserService = mock(GuideUserService.class); |
| | | when(guideUserService.findByPhone("13800138000")).thenReturn(null); |
| | | OperationCityMapper cityMapper = mock(OperationCityMapper.class); |
| | | OperationCity city = new OperationCity(); |
| | |
| | | return 1; |
| | | }).when(applicationMapper).insert(any(GuideApplication.class)); |
| | | |
| | | verificationCodeService = mock(GuideVerificationCodeService.class); |
| | | service = new GuideRegistrationService( |
| | | mock(GuideVerificationCodeService.class), redisTemplate, applicationMapper, |
| | | verificationCodeService, redisTemplate, applicationMapper, |
| | | guideUserService, cityMapper, mock(GuideTeamMapper.class)); |
| | | } |
| | | |
| | | @Test |
| | | void shouldUseRegistrationSceneForSmsCode() { |
| | | when(verificationCodeService.send("13800138000", "registration")) |
| | | .thenReturn(new SmsCodeResponse(300, 30)); |
| | | |
| | | SmsCodeResponse response = service.sendCode("13800138000"); |
| | | |
| | | assertThat(response.getExpireSeconds()).isEqualTo(300); |
| | | verify(verificationCodeService).send("13800138000", "registration"); |
| | | } |
| | | |
| | | @Test |
| | | void shouldVerifyRegistrationSceneAndCreateToken() { |
| | | GuideRegistrationTokenResponse response = service.verifyPhone("13800138000", "794535"); |
| | | |
| | | assertThat(response.getRegistrationToken()).isNotBlank(); |
| | | verify(verificationCodeService).verifyAndConsume("13800138000", "794535", "registration"); |
| | | } |
| | | |
| | | @Test |
| | | void shouldAllowCancelledGuideToRegisterAgain() { |
| | | GuideUser guide = new GuideUser(); |
| | | guide.setStatus(GuideUserService.STATUS_CANCELLED); |
| | | when(guideUserService.findByPhone("13800138000")).thenReturn(guide); |
| | | |
| | | GuideRegistrationTokenResponse response = service.verifyPhone("13800138000", "794535"); |
| | | |
| | | assertThat(response.getRegistrationToken()).isNotBlank(); |
| | | verify(verificationCodeService).verifyAndConsume("13800138000", "794535", "registration"); |
| | | } |
| | | |
| | | @Test |
| | | void shouldCreatePendingApplicationAndConsumeToken() { |
| | | GuideRegistrationSubmitRequest request = new GuideRegistrationSubmitRequest(); |
| | | request.setRealName("张导游"); |