-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] 인수 테스트 에서 사용하는 레포지토리 제거 및 설정 명확하게 변경 (#512) #522
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package corea.room.domain; | ||
|
||
import corea.auth.dto.GithubPullRequestReview; | ||
import corea.exception.CoreaException; | ||
import corea.exception.ExceptionType; | ||
|
||
import java.util.Arrays; | ||
|
||
public record PullRequestReviews(GithubPullRequestReview[] pullRequestReviews) { | ||
public String getReviewUrl(String githubUserId) { | ||
return Arrays.stream(pullRequestReviews) | ||
.filter(githubPullRequestReview -> githubPullRequestReview.isEqualGithubUserId(githubUserId)) | ||
.findFirst() | ||
.map(GithubPullRequestReview::html_url) | ||
.orElseThrow(() -> new CoreaException(ExceptionType.NOT_EXIST_GITHUB_REVIEW)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||||
package corea.bdd; | ||||||||
|
||||||||
import corea.matching.dto.MatchResultResponse; | ||||||||
import corea.matching.dto.MatchResultResponses; | ||||||||
import io.restassured.RestAssured; | ||||||||
import io.restassured.http.ContentType; | ||||||||
|
||||||||
import java.util.List; | ||||||||
|
||||||||
public class MatchingGiven { | ||||||||
public static void 매칭(String accessToken, long roomId) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
//@formatter:off | ||||||||
RestAssured.given().auth().oauth2(accessToken).contentType(ContentType.JSON) | ||||||||
.when().post("/rooms/"+roomId+"/matching") | ||||||||
.then().assertThat().statusCode(200); | ||||||||
//@formatter:on | ||||||||
} | ||||||||
|
||||||||
public static List<MatchResultResponse> 리뷰이_목록_조회(String accessToken, long roomId) { | ||||||||
//@formatter:off | ||||||||
MatchResultResponses responses = RestAssured.given().auth().oauth2(accessToken).contentType(ContentType.JSON) | ||||||||
.when().get("/rooms/"+roomId+"/reviewees") | ||||||||
.then().assertThat().statusCode(200).extract().as(MatchResultResponses.class); | ||||||||
//@formatter:on | ||||||||
return responses.matchResultResponses(); | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package corea.bdd; | ||
|
||
import corea.auth.dto.GithubUserInfo; | ||
import corea.auth.dto.LoginRequest; | ||
import corea.auth.service.GithubOAuthProvider; | ||
import corea.member.domain.Member; | ||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
import org.mockito.Mockito; | ||
|
||
public class MemberGiven { | ||
|
||
public static String 멤버_로그인(GithubOAuthProvider githubOAuthProvider, Member member) { | ||
String mockingCode = member.getGithubUserId(); | ||
Mockito.when(githubOAuthProvider.getUserInfo(mockingCode)) | ||
.thenReturn(new GithubUserInfo( | ||
member.getUsername(), | ||
member.getName(), | ||
member.getThumbnailUrl(), | ||
member.getEmail(), | ||
member.getGithubUserId() | ||
)); | ||
//@formatter:off | ||
return RestAssured.given().body(new LoginRequest(mockingCode)).contentType(ContentType.JSON) | ||
.when().post("/login") | ||
.then().statusCode(200).extract().header("Authorization"); | ||
//@formatter:on | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package corea.bdd; | ||
|
||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
|
||
public class ParticipationGiven { | ||
|
||
public static void 방_참가(String accessToken, long roomId) { | ||
//@formatter:off | ||
RestAssured.given().auth().oauth2(accessToken).contentType(ContentType.JSON) | ||
.when().post("/participate/"+roomId) | ||
.then().assertThat().statusCode(200); | ||
//@formatter:on | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||||||
package corea.bdd; | ||||||||
|
||||||||
import corea.review.dto.ReviewRequest; | ||||||||
import io.restassured.RestAssured; | ||||||||
import io.restassured.http.ContentType; | ||||||||
|
||||||||
public class ReviewGiven { | ||||||||
public static void 리뷰_완료(String accessToken, long roomId, long revieweeId) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
//@formatter:off | ||||||||
RestAssured.given().auth().oauth2(accessToken).body(new ReviewRequest(roomId,revieweeId)).contentType(ContentType.JSON) | ||||||||
.when().post("/review/complete") | ||||||||
.then().assertThat().statusCode(200); | ||||||||
//@formatter:on | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||
package corea.bdd; | ||||||||
|
||||||||
import corea.room.domain.RoomClassification; | ||||||||
import corea.room.dto.RoomCreateRequest; | ||||||||
import corea.room.dto.RoomResponse; | ||||||||
import io.restassured.RestAssured; | ||||||||
import io.restassured.http.ContentType; | ||||||||
|
||||||||
import java.time.LocalDateTime; | ||||||||
import java.util.List; | ||||||||
|
||||||||
public class RoomGiven { | ||||||||
public static RoomResponse 방생성(String accessToken, int matchingSize) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
LocalDateTime now = LocalDateTime.now(); | ||||||||
final RoomCreateRequest request = | ||||||||
new RoomCreateRequest( | ||||||||
"제목", "내용", "https://github.com/example/java-racingcar", | ||||||||
"https://gongu.copyright.or.kr/gongu/wrt/cmmn/wrtFileImageView.do?wrtSn=13301655&filePath=L2Rpc2sxL25ld2RhdGEvMjAyMS8yMS9DTFMxMDAwNC8xMzMwMTY1NV9XUlRfMjFfQ0xTMTAwMDRfMjAyMTEyMTNfMQ==&thumbAt=Y&thumbSe=b_tbumb&wrtTy=10004", | ||||||||
matchingSize, | ||||||||
List.of("TDD", "클린코드"), | ||||||||
200, | ||||||||
now.plusHours(2), | ||||||||
now.plusDays(2), | ||||||||
RoomClassification.BACKEND | ||||||||
); | ||||||||
|
||||||||
//@formatter:off | ||||||||
return RestAssured.given().auth().oauth2(accessToken).body(request).contentType(ContentType.JSON) | ||||||||
.when().post("/rooms") | ||||||||
.then().assertThat().statusCode(201).extract().as(RoomResponse.class); | ||||||||
//@formatter:on | ||||||||
} | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,68 +1,92 @@ | ||||
package corea.feedback.controller; | ||||
|
||||
import config.ControllerTest; | ||||
import corea.auth.service.TokenService; | ||||
import corea.auth.service.GithubOAuthProvider; | ||||
import corea.bdd.MemberGiven; | ||||
import corea.bdd.RoomGiven; | ||||
import corea.feedback.dto.SocialFeedbackRequest; | ||||
import corea.fixture.MatchResultFixture; | ||||
import corea.fixture.MemberFixture; | ||||
import corea.fixture.RoomFixture; | ||||
import corea.matching.repository.MatchResultRepository; | ||||
import corea.member.domain.Member; | ||||
import corea.member.repository.MemberRepository; | ||||
import corea.room.domain.Room; | ||||
import corea.room.repository.RoomRepository; | ||||
import corea.matching.domain.PullRequestInfo; | ||||
import corea.matching.dto.MatchResultResponse; | ||||
import corea.matching.service.PullRequestProvider; | ||||
import corea.room.domain.PullRequestReviews; | ||||
import io.restassured.RestAssured; | ||||
import io.restassured.http.ContentType; | ||||
import org.junit.jupiter.api.BeforeEach; | ||||
import org.junit.jupiter.api.DisplayName; | ||||
import org.junit.jupiter.api.Test; | ||||
import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.mockito.Mockito; | ||||
import org.springframework.boot.test.mock.mockito.MockBean; | ||||
|
||||
import java.time.LocalDateTime; | ||||
import java.util.List; | ||||
|
||||
import static corea.bdd.MatchingGiven.리뷰이_목록_조회; | ||||
import static corea.bdd.MatchingGiven.매칭; | ||||
import static corea.bdd.ParticipationGiven.방_참가; | ||||
import static corea.bdd.ReviewGiven.리뷰_완료; | ||||
import static org.mockito.ArgumentMatchers.any; | ||||
import static org.mockito.ArgumentMatchers.anyString; | ||||
import static org.mockito.Mockito.when; | ||||
|
||||
@ControllerTest | ||||
class SocialFeedbackFeedbackControllerTest { | ||||
|
||||
@Autowired | ||||
private RoomRepository roomRepository; | ||||
@MockBean | ||||
private PullRequestProvider pullRequestProvider; | ||||
|
||||
@MockBean | ||||
private GithubOAuthProvider githubOAuthProvider; | ||||
|
||||
@Autowired | ||||
private MemberRepository memberRepository; | ||||
@BeforeEach | ||||
void setUp() { | ||||
PullRequestInfo info = Mockito.mock(PullRequestInfo.class); | ||||
when(info.containsGithubMemberId(anyString())).thenReturn(true); | ||||
when(info.getPullrequestLinkWithGithubMemberId(anyString())).thenReturn(""); | ||||
when(pullRequestProvider.getUntilDeadline(anyString(), any(LocalDateTime.class))) | ||||
.thenReturn(info); | ||||
|
||||
@Autowired | ||||
private MatchResultRepository matchResultRepository; | ||||
PullRequestReviews pullRequestReviews = Mockito.mock(PullRequestReviews.class); | ||||
when(pullRequestReviews.getReviewUrl(anyString())).thenReturn(""); | ||||
|
||||
@Autowired | ||||
private TokenService tokenService; | ||||
when(githubOAuthProvider.getPullRequestReview(anyString())).thenReturn(pullRequestReviews); | ||||
} | ||||
|
||||
@Test | ||||
@DisplayName("소셜(리뷰이 -> 리뷰어)에 대한 피드백을 작성한다.") | ||||
void create() { | ||||
Member manager = memberRepository.save(MemberFixture.MEMBER_ROOM_MANAGER_JOYSON()); | ||||
Room room = roomRepository.save(RoomFixture.ROOM_DOMAIN(manager)); | ||||
Member reviewer = memberRepository.save(MemberFixture.MEMBER_PORORO()); | ||||
Member reviewee = memberRepository.save(MemberFixture.MEMBER_YOUNGSU()); | ||||
String token = tokenService.createAccessToken(reviewee); | ||||
matchResultRepository.save(MatchResultFixture.MATCH_RESULT_DOMAIN( | ||||
room.getId(), | ||||
reviewer, | ||||
reviewee | ||||
)); | ||||
String 액세스_토큰 = MemberGiven.멤버_로그인(githubOAuthProvider, MemberFixture.MEMBER_ROOM_MANAGER_JOYSON()); | ||||
long 방번호 = RoomGiven.방생성(액세스_토큰, 2) | ||||
.id(); | ||||
|
||||
String 리뷰어_토큰 = MemberGiven.멤버_로그인(githubOAuthProvider, MemberFixture.MEMBER_PORORO()); | ||||
String 리뷰이_토큰 = MemberGiven.멤버_로그인(githubOAuthProvider, MemberFixture.MEMBER_YOUNGSU()); | ||||
|
||||
방_참가(리뷰어_토큰, 방번호); | ||||
방_참가(리뷰이_토큰, 방번호); | ||||
|
||||
매칭(액세스_토큰, 방번호); | ||||
|
||||
Long 리뷰이_아이디 = 리뷰이_목록_조회(리뷰어_토큰, 방번호) | ||||
.stream() | ||||
.findAny() | ||||
.map(MatchResultResponse::userId) | ||||
.orElseThrow(); | ||||
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
리뷰_완료(리뷰어_토큰, 방번호, 리뷰이_아이디); | ||||
|
||||
SocialFeedbackRequest request = new SocialFeedbackRequest( | ||||
reviewer.getId(), | ||||
리뷰이_아이디, | ||||
4, | ||||
List.of("방의 목적에 맞게 코드를 작성했어요", "코드를 이해하기 쉬웠어요"), | ||||
"유용한 블로그나 아티클도 남겨주시고, \n 사소한 부분까지 잘 챙겨준게 좋았씁니다." | ||||
); | ||||
|
||||
RestAssured.given() | ||||
.auth() | ||||
.oauth2(token) | ||||
.contentType(ContentType.JSON) | ||||
.body(request) | ||||
.when() | ||||
.post("/rooms/" + room.getId() + "/social/feedbacks") | ||||
.then() | ||||
.statusCode(200); | ||||
//@formatter:off | ||||
RestAssured.given().auth().oauth2(리뷰어_토큰).body(request).contentType(ContentType.JSON) | ||||
.when().post("/rooms/" + 방번호 + "/social/feedbacks") | ||||
.then().statusCode(200); | ||||
//@formatter:on | ||||
} | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.