Skip to content

Commit

Permalink
AYS-487 | Change Add Role API e2e tests for Forbidden Error
Browse files Browse the repository at this point in the history
  • Loading branch information
suhakopan committed Sep 24, 2024
1 parent b3b4557 commit 8084736
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.ays.auth.util.exception;

import org.ays.common.util.exception.AysAuthException;
import org.springframework.security.access.AccessDeniedException;

import java.io.Serial;

/**
* Exception to be thrown when a user is not a super admin but tries to perform an action that requires super admin privileges.
*/
public final class AysUserNotSuperAdminException extends AysAuthException {
public final class AysUserNotSuperAdminException extends AccessDeniedException {

/**
* Unique identifier for serialization.
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/ays/auth/controller/AysRoleEndToEndTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void givenValidRoleCreateRequest_whenRoleCreated_thenReturnSuccess() throws Exce
}

@Test
void givenRoleCreateRequest_whenRequestHasSuperPermissionsAndUserIsNotSuperAdmin_thenReturnBadRequestError() throws Exception {
void givenRoleCreateRequest_whenRequestHasSuperPermissionsAndUserIsNotSuperAdmin_thenReturnForbiddenError() throws Exception {

// Initialize
List<AysPermission> permissions = permissionReadPort.findAll();
Expand All @@ -392,11 +392,11 @@ void givenRoleCreateRequest_whenRequestHasSuperPermissionsAndUserIsNotSuperAdmin
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders
.post(endpoint, adminToken.getAccessToken(), createRequest);

AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.BAD_REQUEST;
AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.FORBIDDEN;

aysMockMvc.perform(mockHttpServletRequestBuilder, mockErrorResponse)
.andExpect(AysMockResultMatchersBuilders.status()
.isBadRequest())
.isForbidden())
.andExpect(AysMockResultMatchersBuilders.subErrors()
.doesNotHaveJsonPath());

Expand Down Expand Up @@ -514,7 +514,7 @@ void givenValidRoleUpdateRequest_whenRoleUpdated_thenReturnSuccess() throws Exce
}

@Test
void givenValidIdAndRoleUpdateRequest_whenRequestHasSuperPermissionsAndUserIsNotSuperAdmin_thenReturnBadRequestError() throws Exception {
void givenValidIdAndRoleUpdateRequest_whenRequestHasSuperPermissionsAndUserIsNotSuperAdmin_thenReturnForbiddenError() throws Exception {

// Initialize
List<AysPermission> permissions = permissionReadPort.findAll();
Expand Down Expand Up @@ -543,11 +543,11 @@ void givenValidIdAndRoleUpdateRequest_whenRequestHasSuperPermissionsAndUserIsNot
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders
.put(endpoint, adminToken.getAccessToken(), updateRequest);

AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.BAD_REQUEST;
AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.FORBIDDEN;

aysMockMvc.perform(mockHttpServletRequestBuilder, mockErrorResponse)
.andExpect(AysMockResultMatchersBuilders.status()
.isBadRequest())
.isForbidden())
.andExpect(AysMockResultMatchersBuilders.subErrors()
.doesNotHaveJsonPath());

Expand Down

0 comments on commit 8084736

Please sign in to comment.