Skip to content
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

Refactor/1365 커스텀 예외 수정 #1416

Merged
merged 5 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope(scopeName = "cucumber-glue")
Expand Down Expand Up @@ -65,7 +64,8 @@ public void invokeHttpGetWithToken(String path, Object... pathParams) {
response.then().log().all();
}

public void invokeHttpGetWithTokenAndCookies(String path, Map<String, ?> cookies, Object... pathParams) {
public void invokeHttpGetWithTokenAndCookies(String path, Map<String, ?> cookies,
Object... pathParams) {
request = RestAssured.given().log().all()
.cookies(cookies)
.auth().oauth2(accessToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public enum GithubResponses {
수달("7", "access_token_7", "수달", "her0807", "777777",
"https://avatars.githubusercontent.com/u/26570275?v=4");

private String code;
private String accessToken;
private String name;
private String login;
private String id;
private String avatarUrl;
private final String code;
private final String accessToken;
private final String name;
private final String login;
private final String id;
private final String avatarUrl;

GithubResponses(String code, String accessToken, String name, String login, String id,
String avatarUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public ResponseEntity<GithubProfileResponse> user(
String accessToken = authorization.split(" ")[1];
GithubResponses githubResponse = GithubResponses.findByToken(accessToken);
GithubProfileResponse response = new GithubProfileResponse(githubResponse.getName(),
githubResponse.getLogin(),
githubResponse.getId(),
githubResponse.getAvatarUrl());
githubResponse.getLogin(),
githubResponse.getId(),
githubResponse.getAvatarUrl());
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -1,68 +1,72 @@
package wooteco.prolog.fixtures;

import wooteco.prolog.studylog.application.dto.StudylogRequest;
import wooteco.prolog.studylog.application.dto.TagRequest;
import static java.util.stream.Collectors.toList;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG1;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG2;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG3;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG4;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG5;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG6;

import java.util.Arrays;
import java.util.List;

import static java.util.stream.Collectors.toList;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.*;
import wooteco.prolog.studylog.application.dto.StudylogRequest;
import wooteco.prolog.studylog.application.dto.TagRequest;

public enum PostAcceptanceFixture {
POST1(
"[자바][옵셔널] 학습log 제출합니다.",
"옵셔널은 NPE를 배제하기 위해 만들어진 자바8에 추가된 라이브러리입니다. \n " +
"다양한 메소드를 호출하여 원하는 대로 활용할 수 있습니다",
1L,
TAG1,
TAG2
"[자바][옵셔널] 학습log 제출합니다.",
"옵셔널은 NPE를 배제하기 위해 만들어진 자바8에 추가된 라이브러리입니다. \n " +
"다양한 메소드를 호출하여 원하는 대로 활용할 수 있습니다",
1L,
TAG1,
TAG2
),
POST2(
"[자바스크립트][비동기] 학습log 제출합니다.",
"모던 JS의 fetch문, ajax라이브러리인 axios등을 통해 비동기 요청을 \n " +
"편하게 할 수 있습니다. 자바 최고",
2L,
TAG3,
TAG4
"[자바스크립트][비동기] 학습log 제출합니다.",
"모던 JS의 fetch문, ajax라이브러리인 axios등을 통해 비동기 요청을 \n " +
"편하게 할 수 있습니다. 자바 최고",
2L,
TAG3,
TAG4
),
POST3(
"[자료구조] 자료구조는 어려워요",
"진짜 어려움",
1L,
TAG1,
TAG5
"[자료구조] 자료구조는 어려워요",
"진짜 어려움",
1L,
TAG1,
TAG5
),
POST4(
"[DOM] DOM DOM Dance",
"덤덤 댄스 아니고",
2L
"[DOM] DOM DOM Dance",
"덤덤 댄스 아니고",
2L
),
POST5(
"[알고리즘] 자료구조의 big O에 관하여",
"big O는 small O보다 크다",
2L,
TAG5,
TAG6
"[알고리즘] 자료구조의 big O에 관하여",
"big O는 small O보다 크다",
2L,
TAG5,
TAG6
),
POST6(
"새로운 스터디로그",
"옵셔널은 NPE를 배제하기 위해 만들어진 자바8에 추가된 라이브러리입니다. \n " +
"다양한 메소드를 호출하여 원하는 대로 활용할 수 있습니다",
1L,
TAG1,
TAG2
"새로운 스터디로그",
"옵셔널은 NPE를 배제하기 위해 만들어진 자바8에 추가된 라이브러리입니다. \n " +
"다양한 메소드를 호출하여 원하는 대로 활용할 수 있습니다",
1L,
TAG1,
TAG2
);

PostAcceptanceFixture(
String title,
String content,
Long missionId,
TagAcceptanceFixture... tags) {
String title,
String content,
Long missionId,
TagAcceptanceFixture... tags) {
this.tags = Arrays.asList(tags);
List<TagRequest> tagRequests = Arrays.stream(tags)
.map(TagAcceptanceFixture::getTagRequest)
.collect(toList());
.map(TagAcceptanceFixture::getTagRequest)
.collect(toList());
this.studylogRequest = new StudylogRequest(title, content, missionId, tagRequests);
}

Expand All @@ -75,15 +79,15 @@ public StudylogRequest getPostRequest() {

public static List<StudylogRequest> findByMissionNumber(Long missionId) {
return Arrays.stream(PostAcceptanceFixture.values())
.map(PostAcceptanceFixture::getPostRequest)
.filter(it -> it.getMissionId().equals(missionId))
.collect(toList());
.map(PostAcceptanceFixture::getPostRequest)
.filter(it -> it.getMissionId().equals(missionId))
.collect(toList());
}

public static List<StudylogRequest> findByTagNumber(Long tagId) {
return Arrays.stream(PostAcceptanceFixture.values())
.filter(it -> it.tags.stream().anyMatch(tag -> tag.getTagId().equals(tagId)))
.map(PostAcceptanceFixture::getPostRequest)
.collect(toList());
.filter(it -> it.tags.stream().anyMatch(tag -> tag.getTagId().equals(tagId)))
.map(PostAcceptanceFixture::getPostRequest)
.collect(toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public enum StudylogAcceptanceFixture {
List<TagRequest> tagRequests = Arrays.stream(tags)
.map(TagAcceptanceFixture::getTagRequest)
.collect(toList());
this.studylogRequest = new StudylogRequest(title, content, sessionId, missionId, tagRequests);
this.studylogRequest = new StudylogRequest(title, content, sessionId, missionId,
tagRequests);
}

public static List<StudylogRequest> findByMissionNumber(Long missionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public enum TagAcceptanceFixture {
TAG5(5L, "자료구조"),
TAG6(6L, "알고리즘");

private Long tagId;
private TagRequest tagRequest;
private final Long tagId;
private final TagRequest tagRequest;

TagAcceptanceFixture(Long id, String name) {
this.tagId = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import java.util.List;
import org.springframework.http.HttpStatus;
import wooteco.prolog.AcceptanceSteps;
import wooteco.prolog.common.exception.ExceptionDto;
import wooteco.prolog.badge.domain.BadgeType;
import wooteco.prolog.common.exception.ExceptionDto;

public class BadgesStepDefinitions extends AcceptanceSteps {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FilterStepDefinitions extends AcceptanceSteps {
public void nickname을기준으로멤버데이터들을오름차순정렬하여반환한다() {
assertThat(context.response.statusCode()).isEqualTo(HttpStatus.OK.value());
assertThat(context.response.body().jsonPath().getList("members"))
.extracting("nickname")
.containsExactly("브라운", "서니", "현구막");
.extracting("nickname")
.containsExactly("브라운", "서니", "현구막");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public GroupMemberStepDefinitions(MemberRepository memberRepository,
@Given("{string}을 멤버그룹과 그룹멤버에 등록하고")
public void 그룹멤버를_생성하고(String title) {
Member member = memberRepository.findById(1L).get();
MemberGroup 프론트엔드 = memberGroupRepository.save(new MemberGroup(null, "4기 프론트엔드", "4기 프론트엔드 설명"));
MemberGroup 프론트엔드 = memberGroupRepository.save(
new MemberGroup(null, "4기 프론트엔드", "4기 프론트엔드 설명"));
MemberGroup 백엔드 = memberGroupRepository.save(new MemberGroup(null, "4기 백엔드", "4기 백엔드 설명"));
MemberGroup 안드로이드 = memberGroupRepository.save(new MemberGroup(null, "4기 안드로이드", "4기 안드로이드 설명"));
MemberGroup 안드로이드 = memberGroupRepository.save(
new MemberGroup(null, "4기 안드로이드", "4기 안드로이드 설명"));
groupMemberRepository.save(new GroupMember(null, member, 백엔드));
groupMemberRepository.save(new GroupMember(null, member, 프론트엔드));
groupMemberRepository.save(new GroupMember(null, member, 안드로이드));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@ public class MemberStepDefinitions extends AcceptanceSteps {
}

@When("{int}번 스터디로그를 스크랩하면")
public void studylog를스크랩하면(int studylogId){
context.invokeHttpPostWithToken("/members/scrap", new MemberScrapRequest((long)studylogId));
public void studylog를스크랩하면(int studylogId) {
context.invokeHttpPostWithToken("/members/scrap",
new MemberScrapRequest((long) studylogId));
assertThat(context.response.statusCode()).isEqualTo(201);
}

@When("{int}번 스터디로그를 스크랩 취소하면")
public void studylog를스크랩취소하면(int studylogId){
public void studylog를스크랩취소하면(int studylogId) {
context.invokeHttpDeleteWithToken("/members/scrap?studylog=" + studylogId);
assertThat(context.response.statusCode()).isEqualTo(204);
}

@Then("스크랩한 {int}번 스터디로그를 볼 수 있다")
public void 스크랩한studylog를볼수있다(int studylogId){
public void 스크랩한studylog를볼수있다(int studylogId) {
context.invokeHttpGetWithToken("/members/scrap");
assertThat(checkIfScrap(studylogId)).isTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class NewSessionStepDefinitions extends AcceptanceSteps {
@Given("{int}번 커리큘럼에 {string} 세션을 작성하고")
@When("{int}번 커리큘럼에 {string} 세션을 작성하면")
public void 세션을_생성하고(int curriculumId, String name) {
context.invokeHttpPost("/curriculums/" + curriculumId + "/sessions", new SessionRequest(name));
context.invokeHttpPost("/curriculums/" + curriculumId + "/sessions",
new SessionRequest(name));
}

@Then("세션이 생성된다")
Expand All @@ -34,7 +35,8 @@ public class NewSessionStepDefinitions extends AcceptanceSteps {

@When("{int}번 커리큘럼의 {int}번 세션을 {string} 세션으로 수정하면")
public void 세션을_수정하면(int curriculumId, int sessionId, String name) {
context.invokeHttpPut("/curriculums/" + curriculumId + "/sessions/" + sessionId, new SessionRequest(name));
context.invokeHttpPut("/curriculums/" + curriculumId + "/sessions/" + sessionId,
new SessionRequest(name));
}

@Then("세션이 수정된다")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,28 @@ public class StudylogOverviewStepDefinitions extends AcceptanceSteps {
@Then("해당 유저의 태그 목록이 조회된다")
public void 나의태그목록이조회된다() {
final List<MemberTagResponse> data = context.response.then().extract()
.body()
.jsonPath()
.getList("data", MemberTagResponse.class);
.body()
.jsonPath()
.getList("data", MemberTagResponse.class);

assertThat(data)
.extracting(
memberTagResponse -> memberTagResponse.getTagResponse().getName(),
MemberTagResponse::getCount)
.containsExactlyInAnyOrder(
tuple(TagAcceptanceFixture.TAG1.getTagName(), 2),
tuple(TagAcceptanceFixture.TAG2.getTagName(), 2),
tuple(TagAcceptanceFixture.TAG3.getTagName(), 2),
tuple(TagAcceptanceFixture.TAG4.getTagName(), 2),
tuple("ALL", 4)
);
.extracting(
memberTagResponse -> memberTagResponse.getTagResponse().getName(),
MemberTagResponse::getCount)
.containsExactlyInAnyOrder(
tuple(TagAcceptanceFixture.TAG1.getTagName(), 2),
tuple(TagAcceptanceFixture.TAG2.getTagName(), 2),
tuple(TagAcceptanceFixture.TAG3.getTagName(), 2),
tuple(TagAcceptanceFixture.TAG4.getTagName(), 2),
tuple("ALL", 4)
);
}

@When("{string}의 {int}년 {int}월 스터디로그 목록을 조회하면")
public void 나의스터디로그목록을조회하면(String name, int year, int month) {
final String memberName = GithubResponses.findByName(name).getLogin();
String path = String.format("members/%s/calendar-studylogs?year=%d&month=%d", memberName, year, month);
String path = String.format("members/%s/calendar-studylogs?year=%d&month=%d", memberName,
year, month);
context.invokeHttpGet(path);
}

Expand All @@ -58,14 +59,14 @@ public class StudylogOverviewStepDefinitions extends AcceptanceSteps {
@Then("해당 유저의 스터디로그 목록이 조회된다")
public void 나의스터디로그목록이조회된다() {
final List<CalendarStudylogResponse> data = context.response.then().extract()
.body()
.jsonPath()
.getList("data", CalendarStudylogResponse.class);
.body()
.jsonPath()
.getList("data", CalendarStudylogResponse.class);

assertThat(data).extracting(CalendarStudylogResponse::getTitle)
.containsExactlyInAnyOrder(
PostAcceptanceFixture.POST1.getPostRequest().getTitle(),
PostAcceptanceFixture.POST2.getPostRequest().getTitle()
);
.containsExactlyInAnyOrder(
PostAcceptanceFixture.POST1.getPostRequest().getTitle(),
PostAcceptanceFixture.POST2.getPostRequest().getTitle()
);
}
}
Loading