aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-04-08 00:33:40 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-04-08 00:33:40 -0400
commitaf7fbe2837df4cac76383014191e805389da57a2 (patch)
treea47e75bf7906df56f69c207e4016c5cb1c94a259
parentef62e670a4af08026581db83410bbc8b98e45d7d (diff)
downloadJellySolutions-af7fbe2837df4cac76383014191e805389da57a2.tar.gz
JellySolutions-af7fbe2837df4cac76383014191e805389da57a2.tar.bz2
JellySolutions-af7fbe2837df4cac76383014191e805389da57a2.zip
Add more tests for AuthService
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java31
1 files changed, 30 insertions, 1 deletions
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));
+ }
}