diff --git a/fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java b/fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java index 954ff09..8ff3fbb 100644 --- a/fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java +++ b/fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java @@ -44,6 +44,8 @@ public class ServerApp post("/accounts/registrate", accessController::registrate); post("/accounts/login", accessController::login); post("/accounts/logout", accessController::logout); + delete("/accounts/:player_id", accessController::deletePlayer); + get("/hello", (req, res) -> "Hello World"); diff --git a/fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java b/fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java index ce9c09e..ab3706a 100644 --- a/fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java +++ b/fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java @@ -8,12 +8,11 @@ import de.fd.fh.server.user.UserId; import de.fd.fh.shared.Utils; import de.fd.fh.shared.network.messages.LoginRequest; import de.fd.fh.shared.network.messages.RegistrateRequest; +import lombok.RequiredArgsConstructor; import spark.Request; import spark.Response; -import spark.Spark; - -import static spark.Spark.*; +@RequiredArgsConstructor public class AccessController { private final ObjectMapper objectMapper = new ObjectMapper(); @@ -97,11 +96,4 @@ public class AccessController req.session().attribute("userId", accessToken); } - - public AccessController(final AccessService service) - { - this.service = service; - - delete("/accounts/:player_id", this::deletePlayer); - } } diff --git a/fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java b/fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java index 8f5dc24..a848d18 100644 --- a/fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java +++ b/fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java @@ -8,6 +8,7 @@ import de.fd.fh.shared.Utils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import spark.Response; import java.io.IOException; import java.util.HashMap; @@ -100,4 +101,21 @@ class ServerAppTest assertEquals(200, res.getStatus()); then(accessController).should().logout(any(), any()); } + + @Test + void testDeletePlayer() + { + final Response response = mock(Response.class); + + when(accessController.deletePlayer(any(), any())).thenReturn(response); + + String url = "/accounts/12345"; + + ApiTestUtils.TestResponse res = new ApiTestUtils() + .request("DELETE", url, null, null, String.class); + + assertNotNull(res); + assertEquals(200, res.getStatus()); + then(accessController).should().deletePlayer(any(), any()); + } } \ No newline at end of file