diff --git a/backend/src/test/java/ovh/herisson/Clyde/Endpoints/UserControllerTest.java b/backend/src/test/java/ovh/herisson/Clyde/Endpoints/UserControllerTest.java index aebb474..96ddcc9 100644 --- a/backend/src/test/java/ovh/herisson/Clyde/Endpoints/UserControllerTest.java +++ b/backend/src/test/java/ovh/herisson/Clyde/Endpoints/UserControllerTest.java @@ -27,6 +27,8 @@ import ovh.herisson.Clyde.Tables.Token; import ovh.herisson.Clyde.Tables.User; import java.util.Date; +import java.util.HashMap; +import java.util.Map; import static io.restassured.RestAssured.with; import static org.hamcrest.Matchers.equalTo; @@ -111,4 +113,21 @@ public class UserControllerTest { with().header("Authorization", t.getToken()).when().request("GET", "/user").then().assertThat().statusCode(200).body("firstName",equalTo("hero")); } + @Test + public void userPatchTest(){ + User herobrine = new User("brine","hero","herobrine@admin.com","in your WalLs","ShadowsLand",new Date(0), null,Role.Student,"test"); + userRepository.save(herobrine); + + Token t = new Token(herobrine, tokenService.generateNewToken(), new Date()); + tokenRepository.save(t); + + Map data = new HashMap(); + data.put("firstName", "test"); + + //Teste que le patch s'execute bien + with().body(data).contentType(ContentType.JSON).header("Authorization", t.getToken()).when().request("PATCH", "/user").then().statusCode(200); + + //Teste que la donnée a bien été altérée + with().header("Authorization", t.getToken()).when().request("GET", "/user").then().body("firstName",equalTo("test")); + } }