| | |
| | | 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.mapper.GuideApplicationMapper; |
| | | import com.tourguide.modules.user.mapper.GuideTeamMapper; |
| | |
| | | private StringRedisTemplate redisTemplate; |
| | | private ValueOperations<String, String> valueOperations; |
| | | private GuideApplicationMapper applicationMapper; |
| | | private GuideVerificationCodeService verificationCodeService; |
| | | private GuideRegistrationService service; |
| | | |
| | | @SuppressWarnings("unchecked") |
| | |
| | | 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 shouldCreatePendingApplicationAndConsumeToken() { |
| | | GuideRegistrationSubmitRequest request = new GuideRegistrationSubmitRequest(); |
| | | request.setRealName("张导游"); |