Skip to content

Commit

Permalink
test: add RestAssured dependency for E2E Test (#155)
Browse files Browse the repository at this point in the history
* chore: add rest assured dependency

* test(member): add E2E Test for member API

* test(member): add E2E Test for member API

* chore(test): add Database clean Up component

* fix(exception): change exception parameter type

* chore(test): add test data

* chore(test): update RestAssured components

* test(team): add team api REST test

* fix(team): fix error

* feat(meetingRequest): add find meetingRequest query

* test(meetingRequest): test find meetingRequest query

* fix(member): fix member response data

* chore(rest): add support feature for RestAssured test

* test(team): fix team read test

* chore(rest): add COST to Deletion Exclusion list

* test(meeting): add meeting API test
  • Loading branch information
KAispread authored Oct 4, 2023
1 parent 69f05b6 commit b6262df
Show file tree
Hide file tree
Showing 26 changed files with 862 additions and 3 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ dependencies {
implementation 'software.amazon.awssdk:ses:2.20.86'
implementation 'software.amazon.awssdk:s3:2.20.82'

// REST - Assured
testImplementation 'io.rest-assured:rest-assured:5.3.2'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public ResponseEntity<ErrorResponse> handleNotEqualRoleException(
// SQL 관련 예외 핸들링 + sql & sql 예외 원인 Logging
@ExceptionHandler({DataAccessException.class, UndeclaredThrowableException.class})
public ResponseEntity<ErrorResponse> handleDatabaseAccessException(
final DataAccessException e) {
final RuntimeException e) {
final int code = DATA_ACCESS.getCode();

String message = messageSourceAccessor.getMessage(DATA_ACCESS.getMessageKey());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/e2i/wemeet/domain/cost/Cost.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "COST")
@Entity
public class Cost {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/e2i/wemeet/domain/cost/CostHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "COST_HISTORY")
@Entity
public class CostHistory extends CreateTimeEntity {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/e2i/wemeet/domain/heart/Heart.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "HEART")
@Entity
public class Heart extends CreateTimeEntity {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/e2i/wemeet/domain/history/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "HISTORY")
@Entity
public class History extends CreateTimeEntity {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/e2i/wemeet/domain/meeting/Meeting.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "MEETING")
@Entity
public class Meeting extends BaseTimeEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "MEETING_REQUEST")
@Entity
public class MeetingRequest extends BaseTimeEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ public interface MeetingRequestRepository extends JpaRepository<MeetingRequest,
""")
List<MeetingRequest> findAllByTeamAndAcceptStatus(@Param("team") Team team, @Param("acceptStatus") AcceptStatus acceptStatus);

// 내 받은 신청 조회 (대기중)
@Query("""
select mr from MeetingRequest mr
join mr.partnerTeam pt
join pt.teamLeader m
where m.memberId = :memberId and pt.deletedAt is null
and mr.acceptStatus = 0
""")
List<MeetingRequest> findAllByMemberId(@Param("memberId") Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface TeamRepository extends JpaRepository<Team, Long>, TeamCustomRep
SuggestionRepository {

@Query("select t from Team t where t.teamLeader.memberId = :memberId")
Optional<Team> findByMemberId(Long memberId);
Optional<Team> findByMemberId(@Param("memberId") Long memberId);

/*
** 팀이 차단된 사용자의 팀인지 확인
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;


@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "TEAM_IMAGE")
@Entity
public class TeamImage extends CreateTimeEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "TEAM_MEMBER")
@Entity
public class TeamMember extends BaseTimeEntity {

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.e2i.wemeet.domain.meeting.data.AcceptStatus.ACCEPT;
import static com.e2i.wemeet.domain.meeting.data.AcceptStatus.EXPIRED;
import static com.e2i.wemeet.domain.meeting.data.AcceptStatus.PENDING;
import static com.e2i.wemeet.domain.meeting.data.AcceptStatus.REJECT;
import static com.e2i.wemeet.support.fixture.MeetingRequestFixture.BASIC_REQUEST;
import static com.e2i.wemeet.support.fixture.MeetingRequestFixture.WITH_OUT_MESSAGE;
Expand Down Expand Up @@ -147,4 +148,49 @@ void findAllByTeamAndAcceptStatus(final AcceptStatus status, final int expectedS
// then
assertThat(findMeetingRequest).hasSize(expectedSize);
}

@DisplayName("내 ID를 통해 '대기중' 상태의 받은 신청을 조회할 수 있다.")
@Test
void findAllByMemberId() {
// given
Member kai = memberRepository.save(KAI.create(ANYANG_CODE));
Member rim = memberRepository.save(RIM.create(WOMANS_CODE));

Team kaiTeam = teamRepository.save(HONGDAE_TEAM_1.create(kai, create_3_man()));
Team rimTeam = teamRepository.save(HONGDAE_TEAM_1.create(rim, create_3_woman()));

meetingRequestRepository.save(WITH_OUT_MESSAGE.create(kaiTeam, rimTeam));

// when
List<MeetingRequest> findMeetingRequest = meetingRequestRepository.findAllByMemberId(rim.getMemberId());

// then
assertThat(findMeetingRequest).hasSize(1)
.extracting("acceptStatus")
.containsOnly(PENDING);
}

@DisplayName("받은 신청을 조회할 때 삭제된 팀 신청 내역은 조회되지 않는다.")
@Test
void findAllByMemberId_withoutDeletedTeam() {
// given
Member kai = memberRepository.save(KAI.create(ANYANG_CODE));
Member rim = memberRepository.save(RIM.create(WOMANS_CODE));

Team kaiTeam = teamRepository.save(HONGDAE_TEAM_1.create(kai, create_3_man()));
Team rimTeam = teamRepository.save(HONGDAE_TEAM_1.create(rim, create_3_woman()));
meetingRequestRepository.save(WITH_OUT_MESSAGE.create(kaiTeam, rimTeam));
rimTeam.delete(LocalDateTime.now());

Team rimTeam2 = teamRepository.save(HONGDAE_TEAM_1.create(rim, create_3_woman()));
meetingRequestRepository.save(WITH_OUT_MESSAGE.create(kaiTeam, rimTeam2));

// when
List<MeetingRequest> findMeetingRequest = meetingRequestRepository.findAllByMemberId(rim.getMemberId());

// then
assertThat(findMeetingRequest).hasSize(1)
.extracting("acceptStatus")
.containsOnly(PENDING);
}
}
88 changes: 88 additions & 0 deletions src/test/java/com/e2i/wemeet/rest/MeetingControllerRestTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.e2i.wemeet.rest;

import static com.e2i.wemeet.rest.support.RestAssuredRequestUtils.로그인된_상태로_POST_요청을_보낸다;
import static com.e2i.wemeet.security.token.JwtEnv.ACCESS;
import static com.e2i.wemeet.support.fixture.MemberFixture.KAI;
import static com.e2i.wemeet.support.fixture.MemberFixture.KARINA;
import static com.e2i.wemeet.support.fixture.RestAssuredFixture.카이;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;

import com.e2i.wemeet.domain.meeting.MeetingRepository;
import com.e2i.wemeet.domain.meeting.MeetingRequest;
import com.e2i.wemeet.domain.meeting.MeetingRequestRepository;
import com.e2i.wemeet.dto.request.meeting.SendMeetingRequestDto;
import com.e2i.wemeet.dto.response.meeting.AcceptedMeetingResponseDto;
import com.e2i.wemeet.rest.support.MultipartRequest;
import com.e2i.wemeet.support.module.AbstractAcceptanceTest;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import java.io.IOException;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

class MeetingControllerRestTest extends AbstractAcceptanceTest {

@Autowired
private MeetingRequestRepository meetingRequestRepository;

@Autowired
private MeetingRepository meetingRepository;

@DisplayName("회원가입, 사진 등록 후 팀을 생성하고 미팅을 신청할 수 있다.")
@Test
void meetingRequest() throws IOException {
// given
MultipartRequest<Object> images = createMultiPartRequest(
"images", "classpath:/static/test_image/software maestro.png");

final Long womanTeamId = 여자_4인팀을_생성한다(KARINA.create(WOMANS_CODE)).team().getTeamId();
String accessToken = 카이.회원입하고_1_팀을_생성한다(images).header(ACCESS.getKey());

SendMeetingRequestDto requestDto = new SendMeetingRequestDto(womanTeamId);

// when
final String url = "/v1/meeting";
ExtractableResponse<Response> response = 로그인된_상태로_POST_요청을_보낸다(url, accessToken, requestDto);

// then
assertThat(response.statusCode()).isEqualTo(200);
}

@DisplayName("미팅 신청 목록에서 ID를 확인한 뒤 수락할 수 있다.")
@Test
void requestAndAccept() {
// given
CreationData womanData = 여자_4인팀을_생성한다(KARINA.create(WOMANS_CODE));
CreationData manData = 남자_4인팀을_생성한다(KAI.create(ANYANG_CODE));

미팅을_신청한다(manData, womanData);
SendMeetingRequestDto meetingRequest = new SendMeetingRequestDto(womanData.team().getTeamId());

// when
List<MeetingRequest> findRequest = meetingRequestRepository.findAllByMemberId(womanData.member().getMemberId());
ExtractableResponse<Response> response = 로그인된_상태로_POST_요청을_보낸다(
"/v1/meeting/accept/" + findRequest.get(0).getMeetingRequestId(), womanData.accessToken(), meetingRequest);

// then
List<AcceptedMeetingResponseDto> acceptedMeetingList = meetingRepository.findAcceptedMeetingList(womanData.member().getMemberId());
long meetingId = response.body().jsonPath().getLong("data");

assertThat(response.statusCode()).isEqualTo(200);
assertThat(acceptedMeetingList).hasSize(1)
.extracting("meetingId", "teamId")
.contains(
tuple(meetingId, manData.team().getTeamId())
);
}

private MeetingRequest 미팅을_신청한다(CreationData manData, CreationData womanData) {
return meetingRequestRepository.save(MeetingRequest.builder()
.team(manData.team())
.partnerTeam(womanData.team())
.build());
}

}
Loading

0 comments on commit b6262df

Please sign in to comment.