Skip to content

Commit

Permalink
move locale into registration request
Browse files Browse the repository at this point in the history
  • Loading branch information
mengleang-ngoun committed Mar 15, 2024
1 parent c94c09f commit 315162b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ public ResponseWrapper<VerifyChallengeResponse> verifyChallenge(@Valid @RequestB
@PostMapping("/register")
public ResponseWrapper<RegisterResponse> register(@Valid @RequestBody RequestWrapper<RegisterRequest> requestWrapper,
@Valid @NotBlank(message = ErrorConstants.INVALID_TRANSACTION)
@RequestHeader(name = "Locale") String locale,
@CookieValue(value = SignUpConstants.VERIFIED_TRANSACTION_ID, defaultValue = EMTPY) String transactionId)
throws SignUpException {
ResponseWrapper<RegisterResponse> responseWrapper = new ResponseWrapper<>();
responseWrapper.setResponseTime(IdentityProviderUtil.getUTCDateTime());
try {
responseWrapper.setResponse(registrationService.register(requestWrapper.getRequest(), transactionId, locale));
responseWrapper.setResponse(registrationService.register(requestWrapper.getRequest(), transactionId));
}catch (SignUpException signUpException){
auditHelper.sendAuditTransaction(AuditEvent.REGISTER, AuditEventType.ERROR, transactionId, signUpException);
throw signUpException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public class RegisterRequest {

@NotNull(message = ErrorConstants.INVALID_USERINFO)
private @Valid UserInfoMap userInfo;

private String locale;
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public VerifyChallengeResponse verifyChallenge(VerifyChallengeRequest verifyChal
return new VerifyChallengeResponse(ActionStatus.SUCCESS);
}

public RegisterResponse register(RegisterRequest registerRequest, String transactionId, String locale) throws SignUpException {
public RegisterResponse register(RegisterRequest registerRequest, String transactionId) throws SignUpException {

log.debug("Transaction {} : start do registration", transactionId);
RegistrationTransaction transaction = cacheUtilService.getChallengeVerifiedTransaction(transactionId);
Expand All @@ -247,7 +247,7 @@ public RegisterResponse register(RegisterRequest registerRequest, String transac
transaction.setRegistrationStatus(RegistrationStatus.PENDING);
cacheUtilService.setStatusCheckTransaction(transactionId, transaction);

notificationHelper.sendSMSNotificationAsync(registerRequest.getUserInfo().getPhone(), locale,
notificationHelper.sendSMSNotificationAsync(registerRequest.getUserInfo().getPhone(), registerRequest.getLocale(),
REGISTRATION_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 @@ -650,7 +650,7 @@ public void register_thenPass() throws Exception{

RegisterResponse registerResponse = new RegisterResponse();
registerResponse.setStatus(ActionStatus.PENDING);
when(registrationService.register(eq(registerRequest), eq(mockTransactionID), any())).thenReturn(registerResponse);
when(registrationService.register(eq(registerRequest), eq(mockTransactionID))).thenReturn(registerResponse);

mockMvc.perform(post("/registration/register")
.header("locale", "khm")
Expand Down Expand Up @@ -1017,6 +1017,7 @@ public void register_withInValidFullNameInKhm_returnErrorResponse() throws Excep
registerRequest.setUsername("+85512345678");
registerRequest.setPassword("Password@2023");
registerRequest.setConsent("AGREE");
registerRequest.setLocale(locale);

RequestWrapper<RegisterRequest> wrapper = new RequestWrapper<RegisterRequest>();
wrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime());
Expand All @@ -1026,7 +1027,7 @@ public void register_withInValidFullNameInKhm_returnErrorResponse() throws Excep

RegisterResponse registerResponse = new RegisterResponse();
registerResponse.setStatus(ActionStatus.PENDING);
when(registrationService.register(registerRequest, mockTransactionID, locale)).thenReturn(registerResponse);
when(registrationService.register(registerRequest, mockTransactionID)).thenReturn(registerResponse);

mockMvc.perform(post("/registration/register")
.content(objectMapper.writeValueAsString(wrapper))
Expand Down Expand Up @@ -1062,7 +1063,7 @@ public void register_withValidFullName_returnSuccessResponse() throws Exception{

RegisterResponse registerResponse = new RegisterResponse();
registerResponse.setStatus(ActionStatus.PENDING);
when(registrationService.register(eq(registerRequest), eq(mockTransactionID), any(String.class))).thenReturn(registerResponse);
when(registrationService.register(eq(registerRequest), eq(mockTransactionID))).thenReturn(registerResponse);

mockMvc.perform(post("/registration/register")
.header("locale", "khm")
Expand All @@ -1088,6 +1089,7 @@ public void register_withInvalidPassword_returnErrorResponse() throws Exception{
registerRequest.setUsername("+85512345678");
registerRequest.setPassword("12345678");
registerRequest.setConsent("AGREE");
registerRequest.setLocale(locale);

RequestWrapper<RegisterRequest> wrapper = new RequestWrapper<RegisterRequest>();
wrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime());
Expand All @@ -1097,7 +1099,7 @@ public void register_withInvalidPassword_returnErrorResponse() throws Exception{

RegisterResponse registerResponse = new RegisterResponse();
registerResponse.setStatus(ActionStatus.PENDING);
when(registrationService.register(registerRequest, mockTransactionID, locale)).thenReturn(registerResponse);
when(registrationService.register(registerRequest, mockTransactionID)).thenReturn(registerResponse);

mockMvc.perform(post("/registration/register")
.content(objectMapper.writeValueAsString(wrapper))
Expand Down Expand Up @@ -1125,6 +1127,7 @@ public void register_withBlankPassword_returnErrorResponse() throws Exception{
registerRequest.setUsername("+85512345678");
registerRequest.setConsent("AGREE");
registerRequest.setPassword("");
registerRequest.setLocale(locale);


RequestWrapper<RegisterRequest> wrapper = new RequestWrapper<RegisterRequest>();
Expand All @@ -1135,7 +1138,7 @@ public void register_withBlankPassword_returnErrorResponse() throws Exception{

RegisterResponse registerResponse = new RegisterResponse();
registerResponse.setStatus(ActionStatus.PENDING);
when(registrationService.register(registerRequest, mockTransactionID, locale)).thenReturn(registerResponse);
when(registrationService.register(registerRequest, mockTransactionID)).thenReturn(registerResponse);

mockMvc.perform(post("/registration/register")
.content(objectMapper.writeValueAsString(wrapper))
Expand All @@ -1162,6 +1165,7 @@ public void register_withNullPassword_returnErrorResponse() throws Exception{
registerRequest.setUserInfo(userInfo);
registerRequest.setUsername("+85512345678");
registerRequest.setConsent("AGREE");
registerRequest.setLocale(locale);


RequestWrapper<RegisterRequest> wrapper = new RequestWrapper<RegisterRequest>();
Expand All @@ -1172,7 +1176,7 @@ public void register_withNullPassword_returnErrorResponse() throws Exception{

RegisterResponse registerResponse = new RegisterResponse();
registerResponse.setStatus(ActionStatus.PENDING);
when(registrationService.register(registerRequest, mockTransactionID, locale)).thenReturn(registerResponse);
when(registrationService.register(registerRequest, mockTransactionID)).thenReturn(registerResponse);

mockMvc.perform(post("/registration/register")
.content(objectMapper.writeValueAsString(wrapper))
Expand Down Expand Up @@ -1200,6 +1204,7 @@ public void register_withBlankUsername_returnErrorResponse() throws Exception{
registerRequest.setConsent("AGREE");
registerRequest.setPassword("Password@2023");
registerRequest.setUsername("");
registerRequest.setLocale(locale);

RequestWrapper<RegisterRequest> wrapper = new RequestWrapper<RegisterRequest>();
wrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime());
Expand All @@ -1209,7 +1214,7 @@ public void register_withBlankUsername_returnErrorResponse() throws Exception{

RegisterResponse registerResponse = new RegisterResponse();
registerResponse.setStatus(ActionStatus.PENDING);
when(registrationService.register(registerRequest, mockTransactionID, locale)).thenReturn(registerResponse);
when(registrationService.register(registerRequest, mockTransactionID)).thenReturn(registerResponse);

mockMvc.perform(post("/registration/register")
.content(objectMapper.writeValueAsString(wrapper))
Expand All @@ -1235,6 +1240,7 @@ public void register_withNullUsername_returnErrorResponse() throws Exception{
registerRequest.setUserInfo(userInfo);
registerRequest.setConsent("AGREE");
registerRequest.setPassword("Password@2023");
registerRequest.setLocale(locale);

RequestWrapper<RegisterRequest> wrapper = new RequestWrapper<RegisterRequest>();
wrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime());
Expand All @@ -1244,7 +1250,7 @@ public void register_withNullUsername_returnErrorResponse() throws Exception{

RegisterResponse registerResponse = new RegisterResponse();
registerResponse.setStatus(ActionStatus.PENDING);
when(registrationService.register(registerRequest, mockTransactionID, locale)).thenReturn(registerResponse);
when(registrationService.register(registerRequest, mockTransactionID)).thenReturn(registerResponse);

mockMvc.perform(post("/registration/register")
.content(objectMapper.writeValueAsString(wrapper))
Expand Down Expand Up @@ -1272,6 +1278,7 @@ public void register_withNotMatchUsernameRegex_returnErrorResponse() throws Exce
registerRequest.setConsent("AGREE");
registerRequest.setUsername("+85512345678");
registerRequest.setPassword("Password@2023");
registerRequest.setLocale(locale);

RequestWrapper<RegisterRequest> wrapper = new RequestWrapper<RegisterRequest>();
wrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime());
Expand All @@ -1281,7 +1288,7 @@ public void register_withNotMatchUsernameRegex_returnErrorResponse() throws Exce

RegisterResponse registerResponse = new RegisterResponse();
registerResponse.setStatus(ActionStatus.PENDING);
when(registrationService.register(registerRequest, mockTransactionID, locale)).thenReturn(registerResponse);
when(registrationService.register(registerRequest, mockTransactionID)).thenReturn(registerResponse);

mockMvc.perform(post("/registration/register")
.content(objectMapper.writeValueAsString(wrapper))
Expand Down
Loading

0 comments on commit 315162b

Please sign in to comment.