mirror of
https://github.com/vran-dev/databasir.git
synced 2025-08-22 00:00:07 +08:00
feat: add integration test (#65)
* feat: add integration test * feat: update action config * fix: action run failed * feat: add test report step in action
This commit is contained in:
@@ -20,6 +20,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.databasir.core.infrastructure.constant.RoleConstants.GROUP_OWNER;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GroupService {
|
||||
@@ -39,7 +41,7 @@ public class GroupService {
|
||||
private final GroupResponseConverter groupResponseConverter;
|
||||
|
||||
@Transactional
|
||||
public void create(GroupCreateRequest request) {
|
||||
public Integer create(GroupCreateRequest request) {
|
||||
GroupPojo groupPojo = groupPojoConverter.of(request);
|
||||
Integer groupId = groupDao.insertAndReturnId(groupPojo);
|
||||
List<UserRolePojo> roles = request.getGroupOwnerUserIds()
|
||||
@@ -47,25 +49,26 @@ public class GroupService {
|
||||
.map(userId -> {
|
||||
UserRolePojo role = new UserRolePojo();
|
||||
role.setUserId(userId);
|
||||
role.setRole("GROUP_OWNER");
|
||||
role.setRole(GROUP_OWNER);
|
||||
role.setGroupId(groupId);
|
||||
return role;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
userRoleDao.batchInsert(roles);
|
||||
return groupId;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void update(GroupUpdateRequest request) {
|
||||
GroupPojo groupPojo = groupPojoConverter.of(request);
|
||||
groupDao.updateById(groupPojo);
|
||||
userRoleDao.deleteByRoleAndGroupId("GROUP_OWNER", groupPojo.getId());
|
||||
userRoleDao.deleteByRoleAndGroupId(GROUP_OWNER, groupPojo.getId());
|
||||
List<UserRolePojo> roles = request.getGroupOwnerUserIds()
|
||||
.stream()
|
||||
.map(userId -> {
|
||||
UserRolePojo role = new UserRolePojo();
|
||||
role.setUserId(userId);
|
||||
role.setRole("GROUP_OWNER");
|
||||
role.setRole(GROUP_OWNER);
|
||||
role.setGroupId(groupPojo.getId());
|
||||
return role;
|
||||
})
|
||||
@@ -114,7 +117,7 @@ public class GroupService {
|
||||
|
||||
public GroupResponse get(Integer groupId) {
|
||||
GroupPojo groupPojo = groupDao.selectById(groupId);
|
||||
List<UserPojo> users = userDao.selectLimitUsersByRoleAndGroup(groupId, "GROUP_OWNER", 50);
|
||||
List<UserPojo> users = userDao.selectLimitUsersByRoleAndGroup(groupId, GROUP_OWNER, 50);
|
||||
return groupResponseConverter.toResponse(groupPojo, users);
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,14 @@
|
||||
package com.databasir.core.domain.project.data;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DataSourcePropertyValue {
|
||||
|
||||
@NotBlank
|
||||
|
@@ -59,7 +59,7 @@ public class ProjectService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void create(ProjectCreateRequest request) {
|
||||
public Integer create(ProjectCreateRequest request) {
|
||||
ProjectPojo project = projectPojoConverter.of(request);
|
||||
Integer projectId = null;
|
||||
try {
|
||||
@@ -78,6 +78,7 @@ public class ProjectService {
|
||||
|
||||
ProjectSyncRulePojo syncRule = projectPojoConverter.of(request.getProjectSyncRule(), projectId);
|
||||
projectSyncRuleDao.insertAndReturnId(syncRule);
|
||||
return projectId;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
@@ -26,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
import static com.databasir.core.infrastructure.constant.RoleConstants.SYS_OWNER;
|
||||
import static java.util.stream.Collectors.*;
|
||||
|
||||
@Service
|
||||
@@ -63,7 +64,7 @@ public class UserService {
|
||||
.filter(ur -> ur.getGroupId() != null)
|
||||
.collect(groupingBy(UserRolePojo::getUserId, mapping(UserRolePojo::getGroupId, toList())));
|
||||
Map<Integer, List<UserRolePojo>> sysOwnerGroupByUserId = userRoles.stream()
|
||||
.filter(ur -> ur.getRole().equals("SYS_OWNER"))
|
||||
.filter(ur -> ur.getRole().equals(SYS_OWNER))
|
||||
.collect(groupingBy(UserRolePojo::getUserId));
|
||||
return users.map(user ->
|
||||
userResponseConverter.pageResponse(user, sysOwnerGroupByUserId.containsKey(user.getId()),
|
||||
@@ -143,16 +144,16 @@ public class UserService {
|
||||
}
|
||||
|
||||
public void removeSysOwnerFrom(Integer userId) {
|
||||
if (userRoleDao.hasRole(userId, "SYS_OWNER")) {
|
||||
userRoleDao.deleteRole(userId, "SYS_OWNER");
|
||||
if (userRoleDao.hasRole(userId, SYS_OWNER)) {
|
||||
userRoleDao.deleteRole(userId, SYS_OWNER);
|
||||
}
|
||||
}
|
||||
|
||||
public void addSysOwnerTo(Integer userId) {
|
||||
if (!userRoleDao.hasRole(userId, "SYS_OWNER")) {
|
||||
if (!userRoleDao.hasRole(userId, SYS_OWNER)) {
|
||||
UserRolePojo role = new UserRolePojo();
|
||||
role.setUserId(userId);
|
||||
role.setRole("SYS_OWNER");
|
||||
role.setRole(SYS_OWNER);
|
||||
userRoleDao.insertAndReturnId(role);
|
||||
}
|
||||
}
|
||||
@@ -167,6 +168,7 @@ public class UserService {
|
||||
}
|
||||
String newHashedPassword = bCryptPasswordEncoder.encode(request.getNewPassword());
|
||||
userDao.updatePassword(userId, newHashedPassword);
|
||||
loginDao.deleteByUserId(userId);
|
||||
}
|
||||
|
||||
public void updateNickname(Integer userId, UserNicknameUpdateRequest request) {
|
||||
|
@@ -0,0 +1,10 @@
|
||||
package com.databasir.core.infrastructure.constant;
|
||||
|
||||
public interface RoleConstants {
|
||||
|
||||
String SYS_OWNER = "SYS_OWNER";
|
||||
|
||||
String GROUP_OWNER = "GROUP_OWNER";
|
||||
|
||||
String GROUP_MEMBER = "GROUP_MEMBER";
|
||||
}
|
@@ -27,6 +27,8 @@ import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.databasir.core.infrastructure.constant.RoleConstants.SYS_OWNER;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@@ -129,7 +131,7 @@ public class SystemStartedEventSubscriber {
|
||||
Integer userId = userDao.insertAndReturnId(admin);
|
||||
UserRolePojo role = new UserRolePojo();
|
||||
role.setUserId(userId);
|
||||
role.setRole("SYS_OWNER");
|
||||
role.setRole(SYS_OWNER);
|
||||
userRoleDao.insertAndReturnId(role);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user