Skip to content

Commit

Permalink
Merge pull request #80 from Hanaro-trip-together-bank/feature/team
Browse files Browse the repository at this point in the history
fix: res 추가에 따른 테스트코드 수정
  • Loading branch information
mummhy0811 authored May 31, 2024
2 parents c91a367 + afe4213 commit 70e9901
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.hanaro.triptogether.member.domain.MemberRepository;
import com.hanaro.triptogether.team.domain.Team;
import com.hanaro.triptogether.team.domain.TeamRepository;
import com.hanaro.triptogether.teamMember.domain.TeamMember;
import com.hanaro.triptogether.teamMember.domain.TeamMemberRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
Expand All @@ -20,6 +21,7 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand All @@ -38,17 +40,19 @@ public List<TeamServiceListResDto> teamServiceList(Long memberIdx) {
List<Team> teams = teamRepository.findTeamsByMemberIdx(memberIdx);

for(int i = 0; i < teams.size(); i++) {
Long teamMemberIdx = teamMemberRepository.findTeamMemberByMember_MemberIdxAndTeam_TeamIdx(memberIdx, teams.get(i).getTeamIdx()).get().getTeamMemberIdx();
TeamServiceListResDto teamServiceListResDto = TeamServiceListResDto.builder()
.accIdx(teams.get(i).getAccount().getAccIdx())
.accNumber(teams.get(i).getAccount().getAccNumber())
.accBalance(teams.get(i).getAccount().getAccBalance())
.teamName(teams.get(i).getTeamName())
.teamIdx(teams.get(i).getTeamIdx())
.teamMemberIdx(teamMemberIdx)
.build();

teamServiceListResDtos.add(teamServiceListResDto);
Optional<TeamMember> teamMember= teamMemberRepository.findTeamMemberByMember_MemberIdxAndTeam_TeamIdx(memberIdx, teams.get(i).getTeamIdx());
if(teamMember.isPresent()) {
Long teamMemberIdx = teamMember.get().getTeamMemberIdx();
TeamServiceListResDto teamServiceListResDto = TeamServiceListResDto.builder()
.accIdx(teams.get(i).getAccount().getAccIdx())
.accNumber(teams.get(i).getAccount().getAccNumber())
.accBalance(teams.get(i).getAccount().getAccBalance())
.teamName(teams.get(i).getTeamName())
.teamIdx(teams.get(i).getTeamIdx())
.teamMemberIdx(teamMemberIdx)
.build();
teamServiceListResDtos.add(teamServiceListResDto);
}
}

return teamServiceListResDtos;
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/hanaro/triptogether/AccountServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import com.hanaro.triptogether.account.dto.response.TeamServiceListResDto;
import com.hanaro.triptogether.account.service.impl.AccountServiceImpl;
import com.hanaro.triptogether.enumeration.PreferenceType;
import com.hanaro.triptogether.enumeration.TeamMemberState;
import com.hanaro.triptogether.member.domain.Member;
import com.hanaro.triptogether.member.domain.MemberRepository;
import com.hanaro.triptogether.team.domain.Team;
import com.hanaro.triptogether.team.domain.TeamRepository;
import com.hanaro.triptogether.teamMember.domain.TeamMember;
import com.hanaro.triptogether.teamMember.domain.TeamMemberRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -30,6 +33,9 @@ public class AccountServiceTests extends TriptogetherApplicationTests {
@Mock
private AccountRepository accountRepository;

@Mock
private TeamMemberRepository teamMemberRepository;

@Mock
private MemberRepository memberRepository;

Expand All @@ -51,6 +57,8 @@ public class AccountServiceTests extends TriptogetherApplicationTests {
private Team team2;
private Long teamIdx1 = 1L;
private Long teamIdx2 = 2L;
private TeamMember teamMember1;
private TeamMember teamMember2;

@BeforeEach
void setUp() {
Expand Down Expand Up @@ -101,13 +109,27 @@ void setUp() {
.teamNotice("Team Notice2")
.createdAt(LocalDateTime.now())
.build();
teamMember1 = TeamMember.builder()
.teamMemberIdx(1L)
.member(member)
.team(team1)
.teamMemberState(TeamMemberState.총무)
.build();
teamMember2= TeamMember.builder()
.teamMemberIdx(2L)
.member(member)
.team(team2)
.teamMemberState(TeamMemberState.모임원)
.build();
}

@Test
@DisplayName("모임서비스 전체 조회 테스트")
void testTeamServiceList() {
// Given
when(teamRepository.findTeamsByMemberIdx(memberIdx)).thenReturn(Arrays.asList(team1, team2));
when(teamMemberRepository.findTeamMemberByMember_MemberIdxAndTeam_TeamIdx(memberIdx, team1.getTeamIdx())).thenReturn(Optional.of(teamMember1));
when(teamMemberRepository.findTeamMemberByMember_MemberIdxAndTeam_TeamIdx(memberIdx, team2.getTeamIdx())).thenReturn(Optional.of(teamMember2));

// When
List<TeamServiceListResDto> result = accountService.teamServiceList(memberIdx);
Expand Down

0 comments on commit 70e9901

Please sign in to comment.