Skip to content

Commit

Permalink
throw exception and add test case
Browse files Browse the repository at this point in the history
Signed-off-by: mengleang-ngoun <[email protected]>
  • Loading branch information
mengleang-0090 committed Feb 21, 2024
1 parent 693d17c commit b0418fe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public GenerateChallengeResponse generateChallenge(GenerateChallengeRequest gene
SEND_OTP_SMS_NOTIFICATION_TEMPLATE_KEY, hashMap);
log.debug(notificationLogging, notificationResponseRest);
}catch (RestClientException e){
log.debug(notificationLogging, "send notification failed");
throw new SignUpException(ErrorConstants.OTP_NOTIFICATION_FAILED);
}
return new GenerateChallengeResponse(ActionStatus.SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ public class ErrorConstants {
public static final String CHALLENGE_FORMAT_AND_TYPE_MISMATCH = "challenge_format_and_type_mismatch";
public static final String KNOWLEDGEBASE_MISMATCH = "knowledgebase_mismatch";
public static final String IDENTIFIER_BLOCKED = "identifier_blocked";
public static final String OTP_NOTIFICATION_FAILED = "otp_notification_failed";
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;
Expand Down Expand Up @@ -1632,6 +1633,27 @@ public void doGenerateChallenge_withoutTransactionId_thenPass() throws SignUpExc
Assert.assertEquals("SUCCESS", generateChallengeResponse.getStatus());
}

@Test
public void doGenerateChallenge_withFailedSendNotification_thenFail() throws SignUpException, IOException {
String identifier = "+85577410541";
GenerateChallengeRequest generateChallengeRequest = new GenerateChallengeRequest();
generateChallengeRequest.setIdentifier(identifier);
generateChallengeRequest.setCaptchaToken("mock-captcha");
generateChallengeRequest.setRegenerate(false);
when(challengeManagerService.generateChallenge(any())).thenReturn("1111");
when(googleRecaptchaValidatorService.validateCaptcha(
generateChallengeRequest.getCaptchaToken())).thenReturn(true);
when(notificationHelper.sendSMSNotification(any(), any(), any(), any()))
.thenThrow(new RestClientException("failed to send notification"));

try{
registrationService.generateChallenge(generateChallengeRequest, "");
Assert.fail();
} catch (SignUpException ex) {
Assert.assertEquals("otp_notification_failed", ex.getErrorCode());
}
}

@Test
public void doGenerateChallenge_withRetryAttemptsOver3time_thenFail() throws SignUpException{
String identifier = "+85577410541";
Expand Down

0 comments on commit b0418fe

Please sign in to comment.