diff --git a/src/test/java/uk/gov/justice/hmpps/prison/api/resource/UserResourceIntTest.java b/src/test/java/uk/gov/justice/hmpps/prison/api/resource/UserResourceIntTest.java index 4155b1be70..0c87d9ee6c 100644 --- a/src/test/java/uk/gov/justice/hmpps/prison/api/resource/UserResourceIntTest.java +++ b/src/test/java/uk/gov/justice/hmpps/prison/api/resource/UserResourceIntTest.java @@ -6,13 +6,21 @@ import org.springframework.http.HttpStatus; import uk.gov.justice.hmpps.prison.api.model.AccessRole; import uk.gov.justice.hmpps.prison.api.resource.impl.ResourceTest; +import uk.gov.justice.hmpps.prison.api.support.Order; +import uk.gov.justice.hmpps.prison.api.support.Page; +import uk.gov.justice.hmpps.prison.api.support.PageRequest; +import uk.gov.justice.hmpps.prison.api.support.Status; import uk.gov.justice.hmpps.prison.repository.UserRepository; +import uk.gov.justice.hmpps.prison.service.filters.NameFilter; import java.util.List; +import java.util.Map; import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; @@ -22,6 +30,7 @@ public class UserResourceIntTest extends ResourceTest { @MockBean private UserRepository userRepository; + @Test public void addAccessRole() { final var requestEntity = createHttpEntityWithBearerAuthorisation("BOB", List.of("ROLE_MAINTAIN_ACCESS_ROLES"), null); @@ -82,4 +91,33 @@ public void addAccessRoles_noprivileges() { verifyNoInteractions(userRepository); } + + @Test + public void getUser_statusUsesDefaultValueAllWhenNonSupplied() { + final var requestEntity = createHttpEntityWithBearerAuthorisation( + "BOB", + List.of("ROLE_MAINTAIN_ACCESS_ROLES_ADMIN"), + Map.of()); + final var pageRequest = new PageRequest(null, Order.ASC, 0L, 20L); + final var userDetails = new Page(List.of(), 0, pageRequest); + when(userRepository.findUsers(any(), any(), any(), any())).thenReturn(userDetails); + final var responseEntity = testRestTemplate.exchange("/api/users", HttpMethod.GET, requestEntity, String.class); + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); + verify(userRepository).findUsers(eq(null), any(NameFilter.class), eq(Status.ALL), any(PageRequest.class)); + } + + @Test + public void getStaffUsersForLocalAdministrator_statusUsesDefaultValueAllWhenNonSupplied() { + final var requestEntity = createHttpEntityWithBearerAuthorisation( + "BOB", + List.of("ROLE_MAINTAIN_ACCESS_ROLES_ADMIN"), + Map.of()); + final var pageRequest = new PageRequest(null, Order.ASC, 0L, 20L); + final var userDetails = new Page(List.of(), 0, pageRequest); + when(userRepository.getUsersAsLocalAdministrator(any(),any(), any(), any(), any())).thenReturn(userDetails); + final var responseEntity = testRestTemplate.exchange("/api/users/local-administrator/available", HttpMethod.GET, requestEntity, String.class); + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); + verify(userRepository).getUsersAsLocalAdministrator(eq("BOB"),eq(null), any(NameFilter.class), eq(Status.ALL), any(PageRequest.class)); + } + }