diff --git a/backend/src/main/java/ovh/herisson/Clyde/RegNoGenerator.java b/backend/src/main/java/ovh/herisson/Clyde/RegNoGenerator.java index 23dc8c8..e974a50 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/RegNoGenerator.java +++ b/backend/src/main/java/ovh/herisson/Clyde/RegNoGenerator.java @@ -28,7 +28,6 @@ public class RegNoGenerator implements IdentifierGenerator { Calendar c = new GregorianCalendar(); if(set.next()){ resp = set.getLong(1)+((c.get(Calendar.YEAR)%1000)*10000); - System.out.println(resp); } conn.close(); 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 0d1322c..7681953 100644 --- a/backend/src/test/java/ovh/herisson/Clyde/Endpoints/UserControllerTest.java +++ b/backend/src/test/java/ovh/herisson/Clyde/Endpoints/UserControllerTest.java @@ -23,6 +23,7 @@ import ovh.herisson.Clyde.Repositories.TokenRepository; import ovh.herisson.Clyde.Repositories.UserRepository; import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.TokenService; +import ovh.herisson.Clyde.Services.UserService; import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.Token; import ovh.herisson.Clyde.Tables.User; @@ -47,6 +48,8 @@ public class UserControllerTest { @Autowired private TokenService tokenService; + @Autowired + private UserService userService; @Autowired private UserRepository userRepository; @Autowired @@ -79,12 +82,13 @@ public class UserControllerTest { tokenRepository.deleteAll(); userRepository.deleteAll(); } + @Test //Verifie qu'un user qui n'a pas les permissions admin ou secretaire ne peut pas post public void userPostTest(){ User god = new User("god","god","admin@admin.com","everywhere","every",new Date(0), null, Role.Admin,"goddoesntneedpassword"); Token godToken = new Token(god, tokenService.generateNewToken(), new Date()); - userRepository.save(god); + userService.save(god); tokenService.saveToken(godToken); //Can god post herobrine himself ? @@ -97,7 +101,7 @@ public class UserControllerTest { //Can noob post herobrine without authorizations (no) User noob = new User("boon","noob","noob@student.com","everywhere","every",new Date(0), null, Role.Student,"noob"); Token noobToken = new Token(noob, tokenService.generateNewToken(), new Date()); - userRepository.save(noob); + userService.save(noob); tokenService.saveToken(noobToken); with().body(herobrine).contentType(ContentType.JSON).header("Authorization", noobToken.getToken()).when().request("POST", "/user").then().statusCode(401); diff --git a/backend/src/test/java/ovh/herisson/Clyde/Repositories/UserRepoTest.java b/backend/src/test/java/ovh/herisson/Clyde/Repositories/UserRepoTest.java index f99ff2f..9dd6a4f 100644 --- a/backend/src/test/java/ovh/herisson/Clyde/Repositories/UserRepoTest.java +++ b/backend/src/test/java/ovh/herisson/Clyde/Repositories/UserRepoTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.TestPropertySource; +import ovh.herisson.Clyde.Services.UserService; import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.User; @@ -24,6 +25,7 @@ public class UserRepoTest { @BeforeEach public void setup(){ + userRepo.deleteAll(); User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand", new GregorianCalendar(2005, 4, 3).getTime(), null, Role.Admin,"admin"); userRepo.save(herobrine); } @@ -34,8 +36,8 @@ public class UserRepoTest { } @Test public void usertest(){ - Assert.assertEquals("brine", userRepo.findById(1).getLastName()); - Assert.assertTrue(new GregorianCalendar(2005, 4, 3).getTime().equals(userRepo.findById(1).getBirthDate())); + Assert.assertEquals("brine", userRepo.findByEmail("admin@admin.com").getLastName()); + Assert.assertTrue(new GregorianCalendar(2005, 4, 3).getTime().equals(userRepo.findByEmail("admin@admin.com").getBirthDate())); } }