Skip to content

Commit

Permalink
add Unit Test for modified (#15771)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuw529 committed Mar 27, 2024
1 parent b40460e commit 915843a
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ public void testGrantProject() {
logger.info(result.toString());
Assertions.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS));

// ERROR: NO_CURRENT_OPERATING_PERMISSION
loginUser.setUserType(UserType.GENERAL_USER);
result = this.usersService.grantProject(loginUser, userId, projectIds);
logger.info(result.toString());
Assertions.assertEquals(Status.NO_CURRENT_OPERATING_PERMISSION, result.get(Constants.STATUS));

// SUCCESS
when(userMapper.selectById(userId)).thenReturn(getUser());
result = usersService.grantProject(loginUser, userId, projectIds);
Expand All @@ -413,6 +419,12 @@ public void testGrantProjectWithReadPerm() {
logger.info(result.toString());
Assertions.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS));

// ERROR: NO_CURRENT_OPERATING_PERMISSION
loginUser.setUserType(UserType.GENERAL_USER);
result = this.usersService.grantProjectWithReadPerm(loginUser, userId, projectIds);
logger.info(result.toString());
Assertions.assertEquals(Status.NO_CURRENT_OPERATING_PERMISSION, result.get(Constants.STATUS));

// SUCCESS
when(userMapper.selectById(userId)).thenReturn(getUser());
result = usersService.grantProjectWithReadPerm(loginUser, userId, projectIds);
Expand All @@ -436,6 +448,12 @@ public void testGrantProjectByCode() {
logger.info(result.toString());
Assertions.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS));

// ERROR: NO_CURRENT_OPERATING_PERMISSION
loginUser.setUserType(UserType.GENERAL_USER);
result = this.usersService.grantProjectByCode(loginUser, 999, projectCode);
logger.info(result.toString());
Assertions.assertEquals(Status.NO_CURRENT_OPERATING_PERMISSION, result.get(Constants.STATUS));

// ERROR: PROJECT_NOT_FOUNT
result = this.usersService.grantProjectByCode(loginUser, authorizer, 999);
logger.info(result.toString());
Expand Down Expand Up @@ -566,6 +584,12 @@ public void testGrantDataSource() {
logger.info(result.toString());
Assertions.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS));

// ERROR: NO_CURRENT_OPERATING_PERMISSION
loginUser.setUserType(UserType.GENERAL_USER);
result = this.usersService.grantDataSource(loginUser, userId, datasourceIds);
logger.info(result.toString());
Assertions.assertEquals(Status.NO_CURRENT_OPERATING_PERMISSION, result.get(Constants.STATUS));

// test admin user
when(userMapper.selectById(userId)).thenReturn(getUser());
when(datasourceUserMapper.deleteByUserId(Mockito.anyInt())).thenReturn(1);
Expand Down

0 comments on commit 915843a

Please sign in to comment.