feature/implement-external-login-api #30
@@ -17,8 +17,6 @@ import com.vaessl.app.dto.ConnectionRequest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||
import static com.vaessl.app.connection.Endpoint.*;
|
||||
import static com.vaessl.app.exception.ErrorMessage.*;
|
||||
@@ -97,6 +95,7 @@ class HomeboxIntegrationTest {
|
||||
* Tests a server error from the external api.
|
||||
*
|
||||
* @param wm
|
||||
* the WiremockRuntimeInfo object
|
||||
*/
|
||||
@Test
|
||||
void shouldFailToConnectWhenHomeboxReturnsServiceUnavailable(WireMockRuntimeInfo wm) {
|
||||
@@ -119,7 +118,7 @@ class HomeboxIntegrationTest {
|
||||
ConnectionRequest badRequest = new ConnectionRequest(
|
||||
MOCK_URL,
|
||||
HOMEBOX.getValue(),
|
||||
Map.of("username", TEST_USER, "password", TEST_PASS),
|
||||
TEST_USER, TEST_PASS, null,
|
||||
false);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(LOGIN.getValue(), badRequest, String.class);
|
||||
@@ -134,7 +133,7 @@ class HomeboxIntegrationTest {
|
||||
@Test
|
||||
void shouldReturnBadRequestWhenHomeboxFieldsAreEmpty() {
|
||||
|
||||
ConnectionRequest emtpyRequest = new ConnectionRequest("", "", Map.of(), false);
|
||||
ConnectionRequest emtpyRequest = new ConnectionRequest("", "", "", "", false);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(LOGIN.getValue(), emtpyRequest, String.class);
|
||||
|
||||
@@ -150,7 +149,7 @@ class HomeboxIntegrationTest {
|
||||
ConnectionRequest wrongServiceTypeReq = new ConnectionRequest(
|
||||
MOCK_URL,
|
||||
"wrong-service-type",
|
||||
Map.of("username", TEST_USER, "password", TEST_PASS),
|
||||
TEST_USER, TEST_PASS,
|
||||
false);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(LOGIN.getValue(), wrongServiceTypeReq,
|
||||
@@ -179,12 +178,12 @@ class HomeboxIntegrationTest {
|
||||
|
||||
DocumentContext responseContext = JsonPath.parse(response.getBody());
|
||||
|
||||
ConnectionEntity dbEntry = cRepository.findByAppUrlAndUsername(request.appUrl(), request.credentials().get("username"));
|
||||
ConnectionEntity dbEntry = cRepository.findByAppUrlAndUsername(request.appUrl(), request.username());
|
||||
|
||||
assertThat(dbEntry).isNotNull();
|
||||
|
||||
assertThat(dbEntry.getAppUrl()).isEqualTo(request.appUrl());
|
||||
assertThat(dbEntry.getUsername()).isEqualTo(request.credentials().get("username"));
|
||||
assertThat(dbEntry.getUsername()).isEqualTo(request.username());
|
||||
|
||||
if (dbEntry instanceof HomeboxEntity hbE) {
|
||||
assertThat(hbE.getToken()).isEqualTo(responseContext.read("$.token"));
|
||||
@@ -202,8 +201,7 @@ class HomeboxIntegrationTest {
|
||||
* @return a mock api connection request.
|
||||
*/
|
||||
private ConnectionRequest connectionRequest(WireMockRuntimeInfo wm) {
|
||||
return new ConnectionRequest(wm.getHttpBaseUrl(), HOMEBOX.getValue(),
|
||||
Map.of("username", TEST_USER, "password", TEST_PASS),
|
||||
return new ConnectionRequest(wm.getHttpBaseUrl(), HOMEBOX.getValue(), TEST_USER, TEST_PASS,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user