refactored to make use of the ServiceType enum throughout backend and frontend for typesafety
This commit is contained in:
@@ -12,6 +12,8 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import com.vaessl.app.connection.ConnectionRepository;
|
||||
import com.vaessl.app.exception.ConnectionNotFoundException;
|
||||
import static com.vaessl.app.connection.ServiceType.HOMEBOX;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class HomeboxSearchProviderTest {
|
||||
@@ -27,7 +29,7 @@ class HomeboxSearchProviderTest {
|
||||
|
||||
when(mockRepo.findByAppUrlAndUsername(MOCK_URL, MOCK_USER)).thenReturn(null);
|
||||
|
||||
SearchRequest request = new SearchRequest(MOCK_URL, MOCK_USER, "test query", "HOMEBOX");
|
||||
SearchRequest request = new SearchRequest(MOCK_URL, MOCK_USER, "test query", HOMEBOX);
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
assertThrows(ConnectionNotFoundException.class,
|
||||
() -> provider.getSearchResults(request, pageable));
|
||||
|
||||
@@ -110,25 +110,21 @@ class SearchControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnUnauthorizedWhenSessionHasNoConnectionForRequestedServiceType(
|
||||
WireMockRuntimeInfo wm) throws Exception {
|
||||
|
||||
WireMock.stubFor(WireMock.post(HOMEBOX_LOGIN.getValue())
|
||||
.willReturn(WireMock.okJson(VALID_HOMEBOX_LOGIN_RESPONSE)));
|
||||
|
||||
MvcResult loginResult =
|
||||
mockMvc.perform(post(LOGIN_PATH).contentType(MediaType.APPLICATION_JSON)
|
||||
.content(connectionRequestBody(wm))).andExpect(status().isOk()).andReturn();
|
||||
|
||||
Cookie sessionCookie = loginResult.getResponse().getCookie("SESSION");
|
||||
|
||||
mockMvc.perform(
|
||||
post(SEARCH_REQUEST).cookie(sessionCookie).contentType(MediaType.APPLICATION_JSON)
|
||||
.content(searchRequestBody(wm, "OTHER_SERVICETYPE")))
|
||||
.andExpect(status().isUnauthorized());
|
||||
void shouldReturnBadRequestWhenServiceTypeIsInvalid() throws Exception {
|
||||
mockMvc.perform(post(SEARCH_REQUEST).contentType(MediaType.APPLICATION_JSON)
|
||||
.content(searchRequestBody("INVALID_SERVICETYPE")))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
private String searchRequestBody(WireMockRuntimeInfo wm, String serviceType) {
|
||||
return searchRequestBody(wm.getHttpBaseUrl(), serviceType);
|
||||
}
|
||||
|
||||
private String searchRequestBody(String serviceType) {
|
||||
return searchRequestBody("http://irrelevant", serviceType);
|
||||
}
|
||||
|
||||
private String searchRequestBody(String appUrl, String serviceType) {
|
||||
return """
|
||||
{
|
||||
"appUrl": "%s",
|
||||
@@ -136,7 +132,7 @@ class SearchControllerTest {
|
||||
"serviceType": "%s",
|
||||
"username": "%s"
|
||||
}
|
||||
""".formatted(wm.getHttpBaseUrl(), serviceType, MOCK_USER);
|
||||
""".formatted(appUrl, serviceType, MOCK_USER);
|
||||
}
|
||||
|
||||
private String connectionRequestBody(WireMockRuntimeInfo wm) {
|
||||
|
||||
Reference in New Issue
Block a user