Skip to content

Commit

Permalink
Adding github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mlambert125 committed Nov 15, 2024
1 parent 9190067 commit c337721
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions java-springboot-final/src/test/java/UserEndpointTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.example.SpringBootApplication;
import org.example.models.User;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
Expand All @@ -20,13 +21,15 @@ public class UserEndpointTests extends WebStoreTest {
* Tests that getting users fails if not authorized.
*/
@Test
@DisplayName("GET /api/users should return a 401 if not authorized")
public void getUsersShouldFailIfNotAuthorized() {
var result = this.restTemplate.getForEntity(getBaseUrl() + "/api/users", String.class);
var responseCode = result.getStatusCode();
assertEquals(HttpStatus.UNAUTHORIZED, responseCode);
}

@Test
@DisplayName("GET /api/users should return a 403 if not an admin")
public void getUsersShouldFailIfUserNotAdmin() throws SQLException {
jdbcTemplate.update(
"insert into users (username, password) values ('user', ?);",
Expand All @@ -42,6 +45,7 @@ public void getUsersShouldFailIfUserNotAdmin() throws SQLException {
* Tests that getting users succeeds if authorized.
*/
@Test
@DisplayName("GET /api/users should return a 200 and a list of one user if authorized")
public void getUserShouldSucceedIfAuthorized() {
var requestEntity = GetAuthEntity("test-admin", "admin");
var result = this.restTemplate.exchange(getBaseUrl() + "/api/users", HttpMethod.GET, requestEntity, User[].class);
Expand Down

0 comments on commit c337721

Please sign in to comment.