From af7fbe2837df4cac76383014191e805389da57a2 Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 8 Apr 2025 00:33:40 -0400 Subject: Add more tests for AuthService --- .../api/ufundapi/service/AuthServiceTest.java | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'ufund-api') diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java index 4f58b12..db849f2 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java @@ -6,6 +6,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.IOException; +import java.time.LocalDateTime; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -105,5 +107,32 @@ public class AuthServiceTest { assertDoesNotThrow(() -> authService.logout(key)); } - + + @Test + void keyIsValid() throws IOException { + String key = "sowgro"; + when(mockAuthDAO.getUserAuth(key)).thenReturn(null); + + assertThrows(IllegalAccessException.class, () -> authService.keyIsValid(key)); + } + + @Test + void keyHasAccessToCupboard1() throws IOException { + String key = "sowgro"; + when(mockAuthDAO.getUserAuth(key)).thenReturn(null); + + assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToCupboard(key)); + } + + @Test + void keyHasAccessToCupboard2() throws IOException { + String key = "sowgro"; + UserAuth userAuth = new UserAuth("sowgro", "sowgro", LocalDateTime.MAX); + User user = new User("sowgro", 8675309, List.of(), User.UserType.HELPER); + + when(mockAuthDAO.getUserAuth(key)).thenReturn(userAuth); + when(mockUserService.getUser(key)).thenReturn(user); + + assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToCupboard(key)); + } } -- cgit v1.2.3