Skip to content

Commit

Permalink
GMS-72 Another pack of boring tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-szrnka committed Apr 4, 2024
1 parent 84ffd99 commit 634db47
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,33 @@ void shouldLoginFail() {
verify(converter, never()).toUserInfoDto(any(IntrospectResponse.class));
}

@Test
void shouldLoginFailWhenResponseIsNot2xx() {
@ParameterizedTest
@MethodSource("not2xxInputData")
void shouldLoginFailWhenResponseIsNot2xx(String errorDescription, AuthResponsePhase authResponsePhaseExpected) {
// arrange
when(keycloakLoginService.login(DemoData.USERNAME1, DemoData.CREDENTIAL_TEST))
.thenReturn(ResponseEntity.status(400).body(LoginResponse.builder()
.error("error").errorDescription("Account disabled").build()));
.error("error").errorDescription(errorDescription).build()));

// act
AuthenticationResponse response = service.authenticate(DemoData.USERNAME1, DemoData.CREDENTIAL_TEST);

// assert
assertNotNull(response);
assertEquals(AuthResponsePhase.BLOCKED, response.getPhase());
assertEquals(authResponsePhaseExpected, response.getPhase());
verify(keycloakLoginService).login(DemoData.USERNAME1, DemoData.CREDENTIAL_TEST);
verify(converter, never()).toUserInfoDto(any(IntrospectResponse.class));
verify(keycloakIntrospectService, never()).getUserDetails(MOCK_ACCESS_TOKEN, MOCK_REFRESH_TOKEN);
assertLogContains(logAppender, "Login failed! Status code=400");
}

private static Object[][] not2xxInputData() {
return new Object[][] {
{ "Account disabled", AuthResponsePhase.BLOCKED },
{ "Other issue", AuthResponsePhase.FAILED }
};
}

@Test
void shouldLoginFailedWhenIntrospectFailed() {
// arrange
Expand Down

0 comments on commit 634db47

Please sign in to comment.