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