Skip to content

Commit

Permalink
corrected testcases
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Rana <[email protected]>
  • Loading branch information
sacrana0 committed Dec 24, 2024
1 parent 5345d9b commit f3b6e61
Showing 1 changed file with 10 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1131,20 +1131,18 @@ public void doGenerateChallenge_withRetryAttemptsOver3time_thenFail() throws Sig
generateChallengeRequest.setRegenerateChallenge(true);
generateChallengeRequest.setPurpose(Purpose.REGISTRATION);
String transactionId = "TRAN-1234";
RegistrationTransaction transaction = new RegistrationTransaction(identifier, Purpose.REGISTRATION);
transaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC).minusSeconds(40));
transaction.setChallengeRetryAttempts(3);

when(cacheUtilService.getChallengeGeneratedTransaction(transactionId)).thenReturn(transaction);
when(challengeManagerService.generateChallenge(transaction)).thenReturn("1111");
when(captchaHelper.validateCaptcha(
generateChallengeRequest.getCaptchaToken())).thenReturn(true);

GenerateChallengeResponse generateChallengeResponse =
registrationService.generateChallenge(
generateChallengeRequest, transactionId);
Assert.assertNotNull(generateChallengeResponse);
Assert.assertEquals("SUCCESS", generateChallengeResponse.getStatus());
when(cacheUtilService.isIdentifierBlocked(generateChallengeRequest.getIdentifier())).thenReturn(true);
try {
registrationService.generateChallenge(
generateChallengeRequest, transactionId);
Assert.fail("Signup exception not thrown");
} catch (SignUpException ex) {
Assert.assertEquals(ex.getErrorCode(), ErrorConstants.IDENTIFIER_BLOCKED);
} catch (Exception ex) {
Assert.fail("Unexpected exception thrown");
}
}

@Test
Expand Down Expand Up @@ -1257,29 +1255,6 @@ public void doGenerateChallenge_withIdentifierNotMatchTransactionId_throwIdentif
}
}

@Test
public void doGenerateChallenge_withTooManyAttemptTransactionId_throwTooManyAttempts() throws SignUpException {
String identifier = "+85577410541";
GenerateChallengeRequest generateChallengeRequest = new GenerateChallengeRequest();
generateChallengeRequest.setIdentifier(identifier);
generateChallengeRequest.setCaptchaToken("mock-captcha");
generateChallengeRequest.setRegenerateChallenge(true);
String transactionId = "TRAN-1234";
RegistrationTransaction transaction = new RegistrationTransaction(identifier, Purpose.REGISTRATION);
transaction.setChallengeRetryAttempts(4);

when(cacheUtilService.getChallengeGeneratedTransaction(transactionId)).thenReturn(transaction);
when(captchaHelper.validateCaptcha(
generateChallengeRequest.getCaptchaToken())).thenReturn(true);

try {
registrationService.generateChallenge(generateChallengeRequest, transactionId);
Assert.fail();
} catch (GenerateChallengeException ex) {
Assert.assertEquals("too_many_attempts", ex.getErrorCode());
}
}

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

0 comments on commit f3b6e61

Please sign in to comment.