diff --git a/signup-service/src/main/java/io/mosip/signup/dto/RegisterRequest.java b/signup-service/src/main/java/io/mosip/signup/dto/RegisterRequest.java index 45a395a4..40ad7a9f 100644 --- a/signup-service/src/main/java/io/mosip/signup/dto/RegisterRequest.java +++ b/signup-service/src/main/java/io/mosip/signup/dto/RegisterRequest.java @@ -1,6 +1,7 @@ package io.mosip.signup.dto; import io.mosip.signup.util.ErrorConstants; +import io.mosip.signup.validator.Language; import io.mosip.signup.validator.Password; import io.mosip.signup.validator.Username; import lombok.Data; @@ -26,5 +27,6 @@ public class RegisterRequest { @NotNull(message = ErrorConstants.INVALID_USERINFO) private @Valid UserInfoMap userInfo; + @Language(required = false) private String locale; } diff --git a/signup-service/src/main/java/io/mosip/signup/dto/ResetPasswordRequest.java b/signup-service/src/main/java/io/mosip/signup/dto/ResetPasswordRequest.java index c0976dfe..e5c19980 100644 --- a/signup-service/src/main/java/io/mosip/signup/dto/ResetPasswordRequest.java +++ b/signup-service/src/main/java/io/mosip/signup/dto/ResetPasswordRequest.java @@ -1,6 +1,7 @@ package io.mosip.signup.dto; import io.mosip.signup.validator.Identifier; +import io.mosip.signup.validator.Language; import io.mosip.signup.validator.Password; import lombok.Data; @@ -13,5 +14,6 @@ public class ResetPasswordRequest { @Password private String password; + @Language(required = false) private String locale; } diff --git a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java index 03812591..520cdc10 100644 --- a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java +++ b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java @@ -251,7 +251,9 @@ public RegisterResponse register(RegisterRequest registerRequest, String transac transaction.setRegistrationStatus(RegistrationStatus.PENDING); cacheUtilService.setStatusCheckTransaction(transactionId, transaction); - notificationHelper.sendSMSNotificationAsync(registerRequest.getUserInfo().getPhone(), registerRequest.getLocale(), + String locale = registerRequest.getLocale() == null ? transaction.getLocale() : registerRequest.getLocale(); + + notificationHelper.sendSMSNotificationAsync(registerRequest.getUserInfo().getPhone(), locale, REGISTRATION_SMS_NOTIFICATION_TEMPLATE_KEY, null) .thenAccept(notificationResponseRestResponseWrapper -> log.debug(notificationLogging, notificationResponseRestResponseWrapper) @@ -324,7 +326,9 @@ public RegistrationStatusResponse updatePassword(ResetPasswordRequest resetPassw transaction.setRegistrationStatus(RegistrationStatus.PENDING); cacheUtilService.setStatusCheckTransaction(transactionId, transaction); - notificationHelper.sendSMSNotificationAsync(resetPasswordRequest.getIdentifier(), resetPasswordRequest.getLocale(), + String locale = resetPasswordRequest.getLocale() == null ? transaction.getLocale() : resetPasswordRequest.getLocale(); + + notificationHelper.sendSMSNotificationAsync(resetPasswordRequest.getIdentifier(), locale, FORGOT_PASSWORD_SMS_NOTIFICATION_TEMPLATE_KEY, null) .thenAccept(notificationResponseRestResponseWrapper -> log.debug(notificationLogging, notificationResponseRestResponseWrapper) diff --git a/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java b/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java index b324dbdf..ea282abd 100644 --- a/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java +++ b/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java @@ -838,6 +838,69 @@ public void register_thenPass() throws SignUpException { Assert.assertEquals("PENDING", registerResponse.getStatus()); } + @Test + public void register_withNullLocale_thenPass() throws SignUpException { + + UserInfoMap userInfo = new UserInfoMap(); + userInfo.setPreferredLang("khm"); + userInfo.setFullName(List.of(new LanguageTaggedValue("eng", "Panharith AN"))); + userInfo.setPhone("+855219718732"); + + RegisterRequest registerRequest = new RegisterRequest(); + registerRequest.setUserInfo(userInfo); + registerRequest.setUsername("+855219718732"); + registerRequest.setPassword("123123"); + registerRequest.setConsent("AGREE"); + registerRequest.setLocale(null); + + String mockTransactionID = "123456789"; + + RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(userInfo.getPhone(), Purpose.REGISTRATION); + mockRegistrationTransaction.setChallengeHash("123456"); + mockRegistrationTransaction.setIdentifier(userInfo.getPhone()); + + when(cacheUtilService.getChallengeVerifiedTransaction(mockTransactionID)) + .thenReturn(mockRegistrationTransaction); + + IdentityResponse identityResponse = new IdentityResponse(); + identityResponse.setStatus("ACTIVATED"); + UINResponse uinResponse = new UINResponse(); + uinResponse.setUIN("mockUIN"); + Password.PasswordHash passwordHash = new Password.PasswordHash(); + passwordHash.setSalt("mockSalt"); + passwordHash.setHashValue("mockHashValue"); + + RestResponseWrapper mockRestResponseWrapperAddIdentityResponse = new RestResponseWrapper(); + mockRestResponseWrapperAddIdentityResponse.setResponse(identityResponse); + RestResponseWrapper mockRestResponseWrapperUINResponse = new RestResponseWrapper(); + mockRestResponseWrapperUINResponse.setResponse(uinResponse); + RestResponseWrapper mockRestResponseWrapperPasswordHash = new RestResponseWrapper(); + mockRestResponseWrapperPasswordHash.setResponse(passwordHash); + + when(selfTokenRestTemplate.exchange( + eq(getUinEndpoint), + eq(HttpMethod.GET), + eq(null), + any(ParameterizedTypeReference.class))).thenReturn(new ResponseEntity<>(mockRestResponseWrapperUINResponse, HttpStatus.OK)); + when(selfTokenRestTemplate.exchange( + eq(generateHashEndpoint), + eq(HttpMethod.POST), + any(HttpEntity.class), + any(ParameterizedTypeReference.class))).thenReturn(new ResponseEntity<>(mockRestResponseWrapperPasswordHash, HttpStatus.OK)); + when(selfTokenRestTemplate.exchange( + eq(identityEndpoint), + eq(HttpMethod.POST), + any(HttpEntity.class), + any(ParameterizedTypeReference.class))).thenReturn(new ResponseEntity<>(mockRestResponseWrapperAddIdentityResponse, HttpStatus.OK)); + + when(notificationHelper.sendSMSNotificationAsync(any(), any(), any(), any())) + .thenReturn(new CompletableFuture<>()); + + RegisterResponse registerResponse = registrationService.register(registerRequest, mockTransactionID); + Assert.assertNotNull(registerResponse); + Assert.assertEquals("PENDING", registerResponse.getStatus()); + } + @Test public void register_whenUinEndpointResponseNullBody_throwGetUINFailed() throws SignUpException { String locale = "eng"; @@ -2020,6 +2083,53 @@ public void doUpdatePassword_thenSuccess() { Assert.assertEquals(RegistrationStatus.PENDING, registrationStatusResponse.getStatus()); } + @Test + public void doUpdatePassword_withNullLocale_thenSuccess() { + + String verifiedTransactionId = "VERIFIED_TRANSACTION_ID"; + ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest(); + resetPasswordRequest.setPassword("Password@2002"); + resetPasswordRequest.setIdentifier("+85512345678"); + resetPasswordRequest.setLocale(null); + + RegistrationTransaction transaction = new RegistrationTransaction(resetPasswordRequest.getIdentifier(), + Purpose.RESET_PASSWORD); + transaction.setUin("mockUin"); + + Password.PasswordHash passwordHash = new Password.PasswordHash(); + passwordHash.setSalt("mockSalt"); + passwordHash.setHashValue("mockHashValue"); + RestResponseWrapper mockPasswordHashRestResponseWrapper = new RestResponseWrapper<>(); + mockPasswordHashRestResponseWrapper.setResponse(passwordHash); + + RestResponseWrapper mockIdentityResponseRestResponseWrapper = new RestResponseWrapper<>(); + IdentityResponse mockIdentityResponse = new IdentityResponse(); + mockIdentityResponseRestResponseWrapper.setResponse(mockIdentityResponse); + mockIdentityResponse.setStatus(SignUpConstants.ACTIVATED); + mockIdentityResponseRestResponseWrapper.setErrors(new ArrayList<>()); + + when(cacheUtilService.getChallengeVerifiedTransaction(verifiedTransactionId)).thenReturn(transaction); + when(selfTokenRestTemplate.exchange( + eq(generateHashEndpoint), + eq(HttpMethod.POST), + any(HttpEntity.class), + any(ParameterizedTypeReference.class))) + .thenReturn(new ResponseEntity<>(mockPasswordHashRestResponseWrapper, HttpStatus.OK)); + when(selfTokenRestTemplate.exchange( + eq(identityEndpoint), + eq(HttpMethod.PATCH), + any(HttpEntity.class), + any(ParameterizedTypeReference.class))) + .thenReturn(new ResponseEntity<>(mockIdentityResponseRestResponseWrapper, HttpStatus.OK)); + + when(notificationHelper.sendSMSNotificationAsync(any(), any(), any(), any())) + .thenReturn(new CompletableFuture<>()); + + RegistrationStatusResponse registrationStatusResponse = registrationService.updatePassword(resetPasswordRequest, + verifiedTransactionId); + Assert.assertEquals(RegistrationStatus.PENDING, registrationStatusResponse.getStatus()); + } + @Test public void doUpdatePassword_withInvalidTransaction_thenSuccess() {