Skip to content

Commit

Permalink
handle locale registerRequest and resetPasswordRequest null
Browse files Browse the repository at this point in the history
Signed-off-by: mengleang-0090 <[email protected]>
  • Loading branch information
mengleang-0090 committed Mar 26, 2024
1 parent 084f7b9 commit 350a04a
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,5 +27,6 @@ public class RegisterRequest {
@NotNull(message = ErrorConstants.INVALID_USERINFO)
private @Valid UserInfoMap userInfo;

@Language(required = false)
private String locale;
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,5 +14,6 @@ public class ResetPasswordRequest {
@Password
private String password;

@Language(required = false)
private String locale;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IdentityResponse> mockRestResponseWrapperAddIdentityResponse = new RestResponseWrapper<IdentityResponse>();
mockRestResponseWrapperAddIdentityResponse.setResponse(identityResponse);
RestResponseWrapper<UINResponse> mockRestResponseWrapperUINResponse = new RestResponseWrapper<UINResponse>();
mockRestResponseWrapperUINResponse.setResponse(uinResponse);
RestResponseWrapper<Password.PasswordHash> mockRestResponseWrapperPasswordHash = new RestResponseWrapper<Password.PasswordHash>();
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";
Expand Down Expand Up @@ -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<Password.PasswordHash> mockPasswordHashRestResponseWrapper = new RestResponseWrapper<>();
mockPasswordHashRestResponseWrapper.setResponse(passwordHash);

RestResponseWrapper<IdentityResponse> 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() {

Expand Down

0 comments on commit 350a04a

Please sign in to comment.