Skip to content

Commit

Permalink
test(#75): 유저의 그룹 조회 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
ghdcksgml1 committed Oct 30, 2023
1 parent 9ea2512 commit 2c92e8c
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static User generateUser() {
.build();
}

public static User generateUser(String email, String phoneNumber) {
public static User generateCustomUser(String email, String phoneNumber) {

return User.builder()
.platformId("123456")
Expand Down Expand Up @@ -103,18 +103,47 @@ public static HouseworkCategory generateHouseworkCategory() {
.build();
}

public static HouseworkInfo generateHouseworkInfo(GroupInfo groupInfo, HouseworkCategory category) {
public static HouseworkCategory generateCustomHouseworkCategory(String name) {

return HouseworkCategory.builder()
.name(name)
.build();
}

public static HouseworkInfo generateHouseworkInfo(HouseworkCategory category) {

return HouseworkInfo.builder()
.houseworkCategory(category)
.title("빨래")
.detail("빨래 돌리기")
.type(HouseworkPeriodType.HOUSEWORK_PERIOD_EVERYDAY)
.endTime(LocalTime.of(18,0))
.build();
}

public static HouseworkInfo generateHouseworkInfo(GroupInfo groupInfo, HouseworkCategory category) {

return HouseworkInfo.builder()
.groupInfo(groupInfo)
.houseworkCategory(category)
.title("빨래")
.detail("빨래 돌리기")
.type(HouseworkPeriodType.HOUSEWORK_PERIOD_EVERYDAY)
.endTime(LocalTime.of(18,0))
.build();
}

public static HouseworkInfo generateCustomHouseworkInfo(HouseworkCategory category, String title, HouseworkPeriodType type) {

return HouseworkInfo.builder()
.houseworkCategory(category)
.title(title)
.detail("빨래 돌리기")
.type(type)
.endTime(LocalTime.of(18,0))
.build();
}

public static HouseworkMember generateHouseworkMember(GroupMember groupMember, HouseworkInfo houseworkInfo) {

return HouseworkMember.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.heachi.housework.api.service.group.info;

import com.heachi.housework.TestConfig;
import com.heachi.housework.api.service.group.info.response.GroupInfoUserGroupServiceResponse;
import com.heachi.mysql.define.group.info.GroupInfo;
import com.heachi.mysql.define.group.info.repository.GroupInfoRepository;
import com.heachi.mysql.define.group.member.GroupMember;
import com.heachi.mysql.define.group.member.repository.GroupMemberRepository;
import com.heachi.mysql.define.housework.category.HouseworkCategory;
import com.heachi.mysql.define.housework.category.repository.HouseworkCategoryRepository;
import com.heachi.mysql.define.housework.info.HouseworkInfo;
import com.heachi.mysql.define.housework.info.repository.HouseworkInfoRepository;
import com.heachi.mysql.define.housework.member.HouseworkMember;
import com.heachi.mysql.define.housework.member.repository.HouseworkMemberRepository;
import com.heachi.mysql.define.housework.todo.HouseworkTodo;
import com.heachi.mysql.define.housework.todo.repository.HouseworkTodoRepository;
import com.heachi.mysql.define.user.User;
import com.heachi.mysql.define.user.repository.UserRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDate;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
class GroupInfoServiceTest extends TestConfig {

@Autowired private GroupMemberRepository groupMemberRepository;
@Autowired private UserRepository userRepository;
@Autowired private GroupInfoRepository groupInfoRepository;
@Autowired private HouseworkCategoryRepository houseworkCategoryRepository;
@Autowired private HouseworkInfoRepository houseworkInfoRepository;
@Autowired private HouseworkTodoRepository houseworkTodoRepository;
@Autowired private HouseworkMemberRepository houseworkMemberRepository;

@Autowired private GroupInfoService groupInfoService;

@AfterEach
void tearDown() {
houseworkTodoRepository.deleteAllInBatch();
houseworkMemberRepository.deleteAllInBatch();
houseworkInfoRepository.deleteAllInBatch();
houseworkCategoryRepository.deleteAllInBatch();
groupMemberRepository.deleteAllInBatch();
groupInfoRepository.deleteAllInBatch();
userRepository.deleteAllInBatch();
}

@Test
@DisplayName("유저의 email을 통해 유저가 속한 그룹과 각 그룹의 멤버, 해당 날짜의 그룹별 집안일 진행상황을 나타낸다.")
void userGroupInfoList() {
// given
User user = userRepository.save(generateUser());
User user2 = userRepository.save(generateCustomUser("[email protected]", "010-1111-1111"));
User user3 = userRepository.save(generateCustomUser("[email protected]", "010-2222-2222"));
GroupInfo groupInfo = groupInfoRepository.save(generateGroupInfo(user));
GroupInfo groupInfo2 = groupInfoRepository.save(generateGroupInfo(user2));
GroupInfo groupInfo3 = groupInfoRepository.save(generateGroupInfo(user3));
GroupMember groupMember = groupMemberRepository.save(generateGroupMember(user, groupInfo));
groupMemberRepository.save(generateGroupMember(user2, groupInfo));
groupMemberRepository.save(generateGroupMember(user3, groupInfo));
groupMemberRepository.save(generateGroupMember(user, groupInfo3));
groupMemberRepository.save(generateGroupMember(user3, groupInfo2));

HouseworkCategory houseworkCategory = houseworkCategoryRepository.save(generateHouseworkCategory());
HouseworkInfo houseworkInfo = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory));
HouseworkInfo houseworkInfo2 = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory));
HouseworkInfo houseworkInfo3 = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory));

HouseworkMember houseworkMember = houseworkMemberRepository.save(generateHouseworkMember(groupMember, houseworkInfo));
HouseworkInfo findHouseworkInfo = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo.getId()).get();
HouseworkInfo findHouseworkInfo2 = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo2.getId()).get();
HouseworkInfo findHouseworkInfo3 = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo3.getId()).get();

HouseworkTodo houseworkTodo = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo, groupInfo, LocalDate.now()));
HouseworkTodo houseworkTodo2 = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo2, groupInfo2, LocalDate.now()));
HouseworkTodo houseworkTodo3 = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo3, groupInfo3, LocalDate.now()));

// when
List<GroupInfoUserGroupServiceResponse> groupServiceResponses = groupInfoService.userGroupInfoList(user.getEmail());
groupServiceResponses.forEach(System.out::println);

// then
assertThat(groupServiceResponses.get(0).getGroupMembers().size()).isEqualTo(3);
assertThat(groupServiceResponses.get(0).getRemainTodoListCnt()).isEqualTo(1);
assertThat(groupServiceResponses.get(0).getProgressPercent()).isEqualTo(0);

assertThat(groupServiceResponses.get(1).getGroupMembers().size()).isEqualTo(1);
assertThat(groupServiceResponses.get(1).getRemainTodoListCnt()).isEqualTo(1);
assertThat(groupServiceResponses.get(1).getProgressPercent()).isEqualTo(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void test3() {
void test4() {
// given
User user = userRepository.save(generateUser());
User user2 = userRepository.save(generateUser("[email protected]", "010-1111-1111"));
User user2 = userRepository.save(generateCustomUser("[email protected]", "010-1111-1111"));
GroupInfo groupInfo = groupInfoRepository.save(generateGroupInfo(user));
GroupMember groupMember = groupMemberRepository.save(generateGroupMember(user, groupInfo));
GroupMember groupMember2 = groupMemberRepository.save(generateGroupMember(user2, groupInfo));
Expand Down

0 comments on commit 2c92e8c

Please sign in to comment.