Skip to content

Commit

Permalink
refactor: MyCalendarScheduleAcceptanceTest data.sql 의존성 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
sh111-coder committed Jul 27, 2023
1 parent 95d427e commit a2e8388
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package team.teamby.teambyteam.common.fixtures.acceptance;

import io.restassured.RestAssured;
import io.restassured.http.Header;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;

public class MyCalendarScheduleAcceptanceFixtures {

private static final String JWT_PREFIX = "Bearer ";
private static final String JWT_TOKEN = "eyJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InBpaWx5YW5nLmRldkBnbWFpbC5jb20iLCJpYXQiOjE2OTA0MzEzMDIsImV4cCI6MTY5MTQzMTMwMn0.W32l9nFapiQXUuQ2WzQ8-X8PA8VsDIX1rC1X67PWcn0";

public static ExtractableResponse<Response> FIND_PERIOD_SCHEDULE_REQUEST(final Integer year, final Integer month) {
return RestAssured.given().log().all()
.header(new Header("Authorization", JWT_PREFIX + JWT_TOKEN))
.queryParam("year", year)
.queryParam("month", month)
.when().log().all()
.get("/api/my-calendar/schedules")
.then().log().all()
.extract();
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
package team.teamby.teambyteam.schedule.acceptance;

import io.restassured.RestAssured;
import io.restassured.http.Header;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import team.teamby.teambyteam.common.AcceptanceTest;
import team.teamby.teambyteam.member.domain.Member;
import team.teamby.teambyteam.member.domain.MemberTeamPlace;
import team.teamby.teambyteam.schedule.application.dto.ScheduleWithTeamPlaceIdResponse;
import team.teamby.teambyteam.schedule.domain.Schedule;
import team.teamby.teambyteam.teamplace.domain.TeamPlace;

import java.util.List;

import static org.assertj.core.api.SoftAssertions.assertSoftly;
import static team.teamby.teambyteam.common.fixtures.MemberFixtures.PHILIP;
import static team.teamby.teambyteam.common.fixtures.MemberTeamPlaceFixtures.PHILIP_ENGLISH_TEAM_PLACE;
import static team.teamby.teambyteam.common.fixtures.MemberTeamPlaceFixtures.PHILIP_JAPANESE_TEAM_PLACE;
import static team.teamby.teambyteam.common.fixtures.ScheduleFixtures.MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE;
import static team.teamby.teambyteam.common.fixtures.ScheduleFixtures.MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE;
import static team.teamby.teambyteam.common.fixtures.TeamPlaceFixtures.ENGLISH_TEAM_PLACE;
import static team.teamby.teambyteam.common.fixtures.TeamPlaceFixtures.JAPANESE_TEAM_PLACE;
import static team.teamby.teambyteam.common.fixtures.acceptance.MyCalendarScheduleAcceptanceFixtures.FIND_PERIOD_SCHEDULE_REQUEST;

public class MyCalendarScheduleAcceptanceTest extends AcceptanceTest {

private static final String JWT_PREFIX = "Bearer ";
private static final String JWT_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiZW1haWwiOiJhYmNkQGdtYWlsLmNvbSIsImlhdCI6MTUxNjIzOTAyMn0.2Amns5eXoGSqLw5KW-i22lH3S85-wfNd3j6Zs2z2Fg4";

@Nested
@DisplayName("내 캘린더 일정 조회를 한다")
Expand All @@ -28,34 +36,35 @@ class MyCalendarFindSchedule {
@DisplayName("기간으로 조회 성공한다.")
void success() {
// given
final Member PHILIP = testFixtureBuilder.buildMember(PHILIP());

final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE());
final TeamPlace JAPANESE_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(JAPANESE_TEAM_PLACE());

final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE();
final MemberTeamPlace PHILIP_JAPANESE_TEAM_PLACE = PHILIP_JAPANESE_TEAM_PLACE();
PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE);
PHILIP_JAPANESE_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, JAPANESE_TEAM_PLACE);
testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE);
testFixtureBuilder.buildMemberTeamPlace(PHILIP_JAPANESE_TEAM_PLACE);

final Schedule MONTH_7_AND_DAY_12_ALL_DAY_ENGLISH_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE(ENGLISH_TEAM_PLACE.getId()));
final Schedule MONTH_7_AND_DAY_12_N_HOUR_JAPANESE_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(JAPANESE_TEAM_PLACE.getId()));

final int year = 2023;
final int month = 6;
final int month = 7;

// when
final ExtractableResponse<Response> response = requestMyCalendarSchedulesInPeriod(year, month);
final ExtractableResponse<Response> response = FIND_PERIOD_SCHEDULE_REQUEST(year, month);
final List<ScheduleWithTeamPlaceIdResponse> schedules = response.jsonPath().getList("schedules", ScheduleWithTeamPlaceIdResponse.class);

//then
assertSoftly(softly -> {
softly.assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
softly.assertThat(schedules).hasSize(5);
softly.assertThat(schedules.get(0).title()).isEqualTo("3번 팀플 6월 첫날");
softly.assertThat(schedules.get(1).title()).isEqualTo("1번 팀플 6월 일정");
softly.assertThat(schedules.get(2).title()).isEqualTo("3번 팀플 A");
softly.assertThat(schedules.get(3).title()).isEqualTo("1번 팀플 장기 일정");
softly.assertThat(schedules.get(4).title()).isEqualTo("3번 팀플 B");
softly.assertThat(schedules).hasSize(2);
softly.assertThat(schedules.get(0).title()).isEqualTo(MONTH_7_AND_DAY_12_ALL_DAY_ENGLISH_SCHEDULE.getTitle().getValue());
softly.assertThat(schedules.get(1).title()).isEqualTo(MONTH_7_AND_DAY_12_N_HOUR_JAPANESE_SCHEDULE.getTitle().getValue());
});
}
}

private ExtractableResponse<Response> requestMyCalendarSchedulesInPeriod(final Integer year, final Integer month) {
return RestAssured.given().log().all()
.header(new Header("Authorization", JWT_PREFIX + JWT_TOKEN))
.queryParam("year", year)
.queryParam("month", month)
.when().log().all()
.get("/api/my-calendar/schedules")
.then().log().all()
.extract();
}
}

0 comments on commit a2e8388

Please sign in to comment.