Skip to content

Commit

Permalink
fix state in user list
Browse files Browse the repository at this point in the history
  • Loading branch information
xuelianhan007 committed Dec 2, 2024
1 parent 69996a5 commit 075e4f5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.consoleconnect.kraken.operator.auth.repo;

import com.consoleconnect.kraken.operator.auth.entity.UserEntity;
import com.consoleconnect.kraken.operator.auth.enums.UserStateEnum;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -24,5 +25,5 @@ public interface UserRepository
+ " and ((:role) is null or e.role = :role)")
@Transactional(readOnly = true)
Page<UserEntity> search(
String q, Pageable pageable, List<String> filterRoles, String state, String role);
String q, Pageable pageable, List<String> filterRoles, UserStateEnum state, String role);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -134,12 +135,14 @@ public User create(CreateUserRequest request, String createdBy) {
public Paging<User> search(
String q, PageRequest pageRequest, boolean filterInternalUser, String state, String role) {
log.info("Searching users, q:{}, pageRequest:{}", q, pageRequest);
UserStateEnum userStateEnum =
(StringUtils.isBlank(state) ? null : UserStateEnum.valueOf(state));
Page<UserEntity> userEntityPage =
userRepository.search(
q,
pageRequest,
filterInternalUser ? List.of(UserRoleEnum.INTERNAL_USER.name()) : null,
state,
userStateEnum,
role);
log.info("Users found:{}", userEntityPage.getTotalElements());
return PagingHelper.toPaging(userEntityPage, UserMapper.INSTANCE::toUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import java.util.*;
import java.util.function.Consumer;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.SpyBean;
Expand All @@ -31,6 +32,7 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.web.reactive.server.WebTestClient;

@Slf4j
@ActiveProfiles("test-login-enabled")
@MockIntegrationTest
@ContextConfiguration(classes = {TestApplication.class})
Expand Down Expand Up @@ -429,6 +431,25 @@ void givenUserCreated_whenSearch_thenReturnOk() {
assertThat(bodyStr, hasJsonPath("$.data.data", hasSize(greaterThanOrEqualTo(1))));
assertThat(bodyStr, hasJsonPath("$.data.data[0].email", equalTo("[email protected]")));
});

// search by role and state
testClientHelper.requestAndVerify(
HttpMethod.GET,
(uriBuilder ->
uriBuilder
.path("/users")
.queryParam("role", "USER")
.queryParam("state", "ENABLED")
.build()),
headers,
null,
HttpStatus.OK.value(),
bodyStr -> {
log.info("bodyStr:{}", bodyStr);
Assertions.assertNotNull(bodyStr);
assertThat(bodyStr, hasJsonPath("$.data.data", notNullValue()));
assertThat(bodyStr, hasJsonPath("$.data.data", hasSize(greaterThanOrEqualTo(3))));
});
}

@Test
Expand Down

0 comments on commit 075e4f5

Please sign in to comment.