From 2c92e8c254c26d7d01ecc67a1fb85d4cc6841532 Mon Sep 17 00:00:00 2001 From: ghdcksgml1 Date: Mon, 30 Oct 2023 19:48:27 +0900 Subject: [PATCH] =?UTF-8?q?test(#75):=20=EC=9C=A0=EC=A0=80=EC=9D=98=20?= =?UTF-8?q?=EA=B7=B8=EB=A3=B9=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/heachi/housework/TestConfig.java | 33 ++++++- .../group/info/GroupInfoServiceTest.java | 99 +++++++++++++++++++ .../housework/todo/TodoServiceTest.java | 2 +- 3 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/group/info/GroupInfoServiceTest.java diff --git a/heachi-core/housework-api/src/test/java/com/heachi/housework/TestConfig.java b/heachi-core/housework-api/src/test/java/com/heachi/housework/TestConfig.java index 58f1afb7..22e3e3e0 100644 --- a/heachi-core/housework-api/src/test/java/com/heachi/housework/TestConfig.java +++ b/heachi-core/housework-api/src/test/java/com/heachi/housework/TestConfig.java @@ -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") @@ -103,11 +103,29 @@ 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) @@ -115,6 +133,17 @@ public static HouseworkInfo generateHouseworkInfo(GroupInfo groupInfo, Housework .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() diff --git a/heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/group/info/GroupInfoServiceTest.java b/heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/group/info/GroupInfoServiceTest.java new file mode 100644 index 00000000..46c75f5e --- /dev/null +++ b/heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/group/info/GroupInfoServiceTest.java @@ -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("ghdcksgml1@naver.com", "010-1111-1111")); + User user3 = userRepository.save(generateCustomUser("ghdcksgml2@naver.com", "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 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); + } + +} \ No newline at end of file diff --git a/heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/housework/todo/TodoServiceTest.java b/heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/housework/todo/TodoServiceTest.java index 0080b0cc..f639686f 100644 --- a/heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/housework/todo/TodoServiceTest.java +++ b/heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/housework/todo/TodoServiceTest.java @@ -151,7 +151,7 @@ void test3() { void test4() { // given User user = userRepository.save(generateUser()); - User user2 = userRepository.save(generateUser("kmm@kakao.com", "010-1111-1111")); + User user2 = userRepository.save(generateCustomUser("kmm@kakao.com", "010-1111-1111")); GroupInfo groupInfo = groupInfoRepository.save(generateGroupInfo(user)); GroupMember groupMember = groupMemberRepository.save(generateGroupMember(user, groupInfo)); GroupMember groupMember2 = groupMemberRepository.save(generateGroupMember(user2, groupInfo));