From 772fa09e28e7b13ca7660e1281d14c92b13f5c38 Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Mon, 22 Apr 2024 20:35:30 +0200 Subject: [PATCH] Fixing tests and tokenService --- .../java/ovh/herisson/Clyde/Services/TokenService.java | 4 ++-- .../ovh/herisson/Clyde/Endpoints/UserControllerTest.java | 7 +++++-- .../java/ovh/herisson/Clyde/Services/TokenServiceTest.java | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java index c20977d..1cb3c2a 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java @@ -51,8 +51,8 @@ public class TokenService { ArrayList tokenList = tokenRepo.getByUserOrderByExpirationDate(token.getUser()); while(tokenList.size() >= 5){ - tokenRepo.delete(tokenList.getFirst()); - tokenList.remove(tokenList.getFirst()); + tokenRepo.delete(tokenList.get(0)); + tokenList.remove(tokenList.get(0)); } tokenRepo.save(token); } 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..32682be 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; @@ -46,7 +47,8 @@ public class UserControllerTest { @Autowired private TokenService tokenService; - + @Autowired + private UserService userService; @Autowired private UserRepository userRepository; @Autowired @@ -72,6 +74,7 @@ public class UserControllerTest { @BeforeEach void setup(){ RestAssured.baseURI = "http://localhost:" + port; + userRepository.deleteAll(); } @AfterEach @@ -84,7 +87,7 @@ public class UserControllerTest { 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 ? diff --git a/backend/src/test/java/ovh/herisson/Clyde/Services/TokenServiceTest.java b/backend/src/test/java/ovh/herisson/Clyde/Services/TokenServiceTest.java index 0e9a81a..8607ceb 100644 --- a/backend/src/test/java/ovh/herisson/Clyde/Services/TokenServiceTest.java +++ b/backend/src/test/java/ovh/herisson/Clyde/Services/TokenServiceTest.java @@ -70,7 +70,7 @@ class TokenServiceTest { ArrayList tokenList = new ArrayList<>(); GregorianCalendar gc = new GregorianCalendar(); - User malveillant = new User("Cargo", "John", "CargoJ@mail.com", "secret", "secret", null, null, null, "secret"); + User malveillant = new User("Cargo", "John", "CargoJ@mail.com", "secret", "secret", new Date(), null, "secret", null); userRepository.save(malveillant); for (int i = 0; i < 20; i++){