diff --git a/backend/src/test/java/team/teamby/teambyteam/common/AcceptanceTest.java b/backend/src/test/java/team/teamby/teambyteam/common/AcceptanceTest.java index 780302e15..1090fa0dd 100644 --- a/backend/src/test/java/team/teamby/teambyteam/common/AcceptanceTest.java +++ b/backend/src/test/java/team/teamby/teambyteam/common/AcceptanceTest.java @@ -2,13 +2,18 @@ import io.restassured.RestAssured; import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.test.context.jdbc.Sql; +import team.teamby.teambyteam.common.builder.TestFixtureBuilder; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@Sql({"/h2-truncate.sql", "/h2-data.sql"}) -public class AcceptanceTest { +@Sql({"/h2-truncate.sql"}) +public abstract class AcceptanceTest { + + @Autowired + protected TestFixtureBuilder testFixtureBuilder; @LocalServerPort private int port; diff --git a/backend/src/test/java/team/teamby/teambyteam/common/RepositoryTest.java b/backend/src/test/java/team/teamby/teambyteam/common/RepositoryTest.java index 0ba5451dc..b27225b8b 100644 --- a/backend/src/test/java/team/teamby/teambyteam/common/RepositoryTest.java +++ b/backend/src/test/java/team/teamby/teambyteam/common/RepositoryTest.java @@ -1,11 +1,19 @@ package team.teamby.teambyteam.common; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; import org.springframework.test.context.jdbc.Sql; +import team.teamby.teambyteam.common.builder.BuilderSupporter; +import team.teamby.teambyteam.common.builder.TestFixtureBuilder; @DataJpaTest +@Import(value = {TestFixtureBuilder.class, BuilderSupporter.class}) @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) -@Sql(value = {"/h2-truncate.sql", "/h2-data.sql"}) +@Sql(value = {"/h2-truncate.sql"}) public abstract class RepositoryTest { + + @Autowired + protected TestFixtureBuilder testFixtureBuilder; } diff --git a/backend/src/test/java/team/teamby/teambyteam/common/ServiceTest.java b/backend/src/test/java/team/teamby/teambyteam/common/ServiceTest.java index 2a02c46a9..5413f4c50 100644 --- a/backend/src/test/java/team/teamby/teambyteam/common/ServiceTest.java +++ b/backend/src/test/java/team/teamby/teambyteam/common/ServiceTest.java @@ -1,14 +1,14 @@ package team.teamby.teambyteam.common; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.jdbc.Sql; import org.springframework.transaction.annotation.Transactional; +import team.teamby.teambyteam.common.builder.TestFixtureBuilder; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) @Transactional -@Sql(value = {"/h2-truncate.sql", "/h2-data.sql"}) public abstract class ServiceTest { - - + @Autowired + protected TestFixtureBuilder testFixtureBuilder; } diff --git a/backend/src/test/java/team/teamby/teambyteam/common/builder/BuilderSupporter.java b/backend/src/test/java/team/teamby/teambyteam/common/builder/BuilderSupporter.java new file mode 100644 index 000000000..6205bf31b --- /dev/null +++ b/backend/src/test/java/team/teamby/teambyteam/common/builder/BuilderSupporter.java @@ -0,0 +1,40 @@ +package team.teamby.teambyteam.common.builder; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import team.teamby.teambyteam.member.domain.MemberRepository; +import team.teamby.teambyteam.member.domain.MemberTeamPlaceRepository; +import team.teamby.teambyteam.schedule.domain.ScheduleRepository; +import team.teamby.teambyteam.teamplace.domain.TeamPlaceRepository; + +@Component +public class BuilderSupporter { + + @Autowired + private ScheduleRepository scheduleRepository; + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private MemberTeamPlaceRepository memberTeamPlaceRepository; + + @Autowired + private TeamPlaceRepository teamPlaceRepository; + + public ScheduleRepository scheduleRepository() { + return scheduleRepository; + } + + public MemberRepository memberRepository() { + return memberRepository; + } + + public MemberTeamPlaceRepository memberTeamPlaceRepository() { + return memberTeamPlaceRepository; + } + + public TeamPlaceRepository teamPlaceRepository() { + return teamPlaceRepository; + } +} diff --git a/backend/src/test/java/team/teamby/teambyteam/common/builder/TestFixtureBuilder.java b/backend/src/test/java/team/teamby/teambyteam/common/builder/TestFixtureBuilder.java new file mode 100644 index 000000000..8c9358758 --- /dev/null +++ b/backend/src/test/java/team/teamby/teambyteam/common/builder/TestFixtureBuilder.java @@ -0,0 +1,49 @@ +package team.teamby.teambyteam.common.builder; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import team.teamby.teambyteam.member.domain.Member; +import team.teamby.teambyteam.member.domain.MemberTeamPlace; +import team.teamby.teambyteam.schedule.domain.Schedule; +import team.teamby.teambyteam.teamplace.domain.TeamPlace; + +import java.util.List; + +@Component +public class TestFixtureBuilder { + + @Autowired + private BuilderSupporter bs; + + public Schedule buildSchedule(final Schedule schedule) { + return bs.scheduleRepository().save(schedule); + } + + public Member buildMember(final Member member) { + return bs.memberRepository().save(member); + } + + public MemberTeamPlace buildMemberTeamPlace(final MemberTeamPlace memberTeamPlace) { + return bs.memberTeamPlaceRepository().save(memberTeamPlace); + } + + public TeamPlace buildTeamPlace(final TeamPlace teamPlace) { + return bs.teamPlaceRepository().save(teamPlace); + } + + public List buildSchedules(final List schedules) { + return bs.scheduleRepository().saveAll(schedules); + } + + public List buildMembers(final List members) { + return bs.memberRepository().saveAll(members); + } + + public List buildMemberTeamPlaces(final List memberTeamPlaces) { + return bs.memberTeamPlaceRepository().saveAll(memberTeamPlaces); + } + + public List buildTeamPlaces(final List teamPlaces) { + return bs.teamPlaceRepository().saveAll(teamPlaces); + } +} diff --git a/backend/src/test/java/team/teamby/teambyteam/common/fixtures/MemberFixtures.java b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/MemberFixtures.java new file mode 100644 index 000000000..af93d19cd --- /dev/null +++ b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/MemberFixtures.java @@ -0,0 +1,51 @@ +package team.teamby.teambyteam.common.fixtures; + +import team.teamby.teambyteam.member.domain.Member; +import team.teamby.teambyteam.member.domain.vo.Email; +import team.teamby.teambyteam.member.domain.vo.Name; +import team.teamby.teambyteam.member.domain.vo.ProfileImageUrl; + +public class MemberFixtures { + + /** + * NAME + */ + public static final String PHILIP_NAME = "jae_philip_yang"; + public static final String ROY_NAME = "roy"; + public static final String SEONGHA_NAME = "seongha"; + public static final String ENDEL_NAME = "endel"; + + /** + * EMAIL + */ + public static final String PHILIP_EMAIL = "piilyang.dev@gmail.com"; + public static final String ROY_EMAIL = "roy@gmail.com"; + public static final String SEONGHA_EMAIL = "seongha@naver.com"; + public static final String ENDEL_EMAIL = "abcd@gmail.com"; + + /** + * PROFILE_IMAGE_URL + */ + public static final String PHILIP_PROFILE_IMAGE_URL = "/profile/philip.gif"; + public static final String ROY_PROFILE_IMAGE_URL = "/profile/roy.png"; + public static final String SEONGHA_PROFILE_IMAGE_URL = "/profile/seongha.png"; + public static final String ENDEL_PROFILE_IMAGE_URL = "/profile/endel.png"; + + /** + * ENTITY + */ + public static Member PHILIP() { + return new Member(new Name(PHILIP_NAME), new Email(PHILIP_EMAIL), new ProfileImageUrl(PHILIP_PROFILE_IMAGE_URL)); + } + public static Member ROY() { + return new Member(new Name(ROY_NAME), new Email(ROY_EMAIL), new ProfileImageUrl(ROY_PROFILE_IMAGE_URL)); + } + + public static Member SEONGHA() { + return new Member(new Name(SEONGHA_NAME), new Email(SEONGHA_EMAIL), new ProfileImageUrl(SEONGHA_PROFILE_IMAGE_URL)); + } + + public static Member ENDEL() { + return new Member(new Name(ENDEL_NAME), new Email(ENDEL_EMAIL), new ProfileImageUrl(ENDEL_PROFILE_IMAGE_URL)); + } +} diff --git a/backend/src/test/java/team/teamby/teambyteam/common/fixtures/MemberTeamPlaceFixtures.java b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/MemberTeamPlaceFixtures.java new file mode 100644 index 000000000..7d3d8ecbc --- /dev/null +++ b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/MemberTeamPlaceFixtures.java @@ -0,0 +1,14 @@ +package team.teamby.teambyteam.common.fixtures; + +import team.teamby.teambyteam.member.domain.MemberTeamPlace; + +public class MemberTeamPlaceFixtures { + + public static MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE() { + return new MemberTeamPlace(); + } + + public static MemberTeamPlace PHILIP_JAPANESE_TEAM_PLACE() { + return new MemberTeamPlace(); + } +} diff --git a/backend/src/test/java/team/teamby/teambyteam/common/fixtures/ScheduleFixtures.java b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/ScheduleFixtures.java new file mode 100644 index 000000000..d1ba0acc9 --- /dev/null +++ b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/ScheduleFixtures.java @@ -0,0 +1,80 @@ +package team.teamby.teambyteam.common.fixtures; + +import team.teamby.teambyteam.schedule.application.dto.ScheduleRegisterRequest; +import team.teamby.teambyteam.schedule.application.dto.ScheduleUpdateRequest; +import team.teamby.teambyteam.schedule.domain.Schedule; +import team.teamby.teambyteam.schedule.domain.vo.Span; +import team.teamby.teambyteam.schedule.domain.vo.Title; + +import java.time.LocalDateTime; + +public class ScheduleFixtures { + + /** + * SCHEDULE + */ + public static final String MONTH_5_FIRST_DAY_SCHEDULE_TITLE = "5월 첫 날 일정"; + public static final String MONTH_5_LAST_DAY_SCHEDULE_TITLE = "5월 마지막 날 일정"; + public static final String MONTH_6_AND_MONTH_7_SCHEDULE_TITLE = "6월~7월 일정"; + public static final String MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_TITLE = "7월 12일 N시간 일정"; + public static final String MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE_TITLE = "7월 12일 종일 일정"; + public static final String MONTH_7_DAY_28_AND_MONTH_8_SCHEDULE_TITLE = "7월 28일~8월 일정"; + public static final String MONTH_7_DAY_29_AND_MONTH_8_SCHEDULE_TITLE = "7월 29일~8월 일정"; + + /** + * DATE + */ + public static final LocalDateTime DATE_2023_05_01_00_00_00 = LocalDateTime.of(2023, 5, 1, 0, 0, 0); + public static final LocalDateTime DATE_2023_05_01_23_59_59 = LocalDateTime.of(2023, 5, 1, 23, 59, 59); + public static final LocalDateTime DATE_2023_05_31_00_00_00 = LocalDateTime.of(2023, 5, 31, 0, 0, 0); + public static final LocalDateTime DATE_2023_05_31_23_59_59 = LocalDateTime.of(2023, 5, 31, 23, 59, 59); + public static final LocalDateTime DATE_2023_06_25_10_00_00 = LocalDateTime.of(2023, 6, 25, 10, 0, 0); + public static final LocalDateTime DATE_2023_07_12_00_00_00 = LocalDateTime.of(2023, 7, 12, 0, 0, 0); + public static final LocalDateTime DATE_2023_07_12_10_00_00 = LocalDateTime.of(2023, 7, 12, 10, 0, 0); + public static final LocalDateTime DATE_2023_07_12_18_00_00 = LocalDateTime.of(2023, 7, 12, 18, 0, 0); + public static final LocalDateTime DATE_2023_07_12_23_59_59 = LocalDateTime.of(2023, 7, 12, 23, 59, 59); + public static final LocalDateTime DATE_2023_07_28_10_00_00 = LocalDateTime.of(2023, 7, 28, 10, 0, 0); + public static final LocalDateTime DATE_2023_07_29_10_00_00 = LocalDateTime.of(2023, 7, 29, 10, 0, 0); + public static final LocalDateTime DATE_2023_08_30_12_00_00 = LocalDateTime.of(2023, 8, 30, 10, 0, 0); + + /** + * REGISTER_REQUEST + */ + public static final ScheduleRegisterRequest MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_REGISTER_REQUEST = new ScheduleRegisterRequest(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_TITLE, DATE_2023_07_12_10_00_00, DATE_2023_07_12_18_00_00); + + /** + * UPDATE_REQUEST + */ + public static final ScheduleUpdateRequest MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_UPDATE_REQUEST = new ScheduleUpdateRequest(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_TITLE, DATE_2023_07_12_00_00_00, DATE_2023_07_12_18_00_00); + + /** + * ENTITY + */ + public static Schedule MONTH_5_FIRST_DAY_SCHEDULE(final Long teamPlaceId) { + return new Schedule(teamPlaceId, new Title(teamPlaceId + "번 팀플 " + MONTH_5_FIRST_DAY_SCHEDULE_TITLE), new Span(DATE_2023_05_01_00_00_00, DATE_2023_05_01_23_59_59)); + } + + public static Schedule MONTH_5_LAST_DAY_SCHEDULE(final Long teamPlaceId) { + return new Schedule(teamPlaceId, new Title(teamPlaceId + "번 팀플 " + MONTH_5_LAST_DAY_SCHEDULE_TITLE), new Span(DATE_2023_05_31_00_00_00, DATE_2023_05_31_23_59_59)); + } + + public static Schedule MONTH_6_AND_MONTH_7_SCHEDULE(final Long teamPlaceId) { + return new Schedule(teamPlaceId, new Title(teamPlaceId + "번 팀플 " + MONTH_6_AND_MONTH_7_SCHEDULE_TITLE), new Span(DATE_2023_06_25_10_00_00, DATE_2023_07_12_18_00_00)); + } + + public static Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(final Long teamPlaceId) { + return new Schedule(teamPlaceId, new Title(teamPlaceId + "번 팀플 " + MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_TITLE), new Span(DATE_2023_07_12_10_00_00, DATE_2023_07_12_18_00_00)); + } + + public static Schedule MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE(final Long teamPlaceId) { + return new Schedule(teamPlaceId, new Title(teamPlaceId + "번 팀플 " + MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE_TITLE), new Span(DATE_2023_07_12_00_00_00, DATE_2023_07_12_23_59_59)); + } + + public static Schedule MONTH_7_DAY_28_AND_MONTH_8_SCHEDULE(final Long teamPlaceId) { + return new Schedule(teamPlaceId, new Title(teamPlaceId + "번 팀플 " + MONTH_7_DAY_28_AND_MONTH_8_SCHEDULE_TITLE), new Span(DATE_2023_07_28_10_00_00, DATE_2023_08_30_12_00_00)); + } + + public static Schedule MONTH_7_DAY_29_AND_MONTH_8_SCHEDULE(final Long teamPlaceId) { + return new Schedule(teamPlaceId, new Title(teamPlaceId + "번 팀플 " + MONTH_7_DAY_29_AND_MONTH_8_SCHEDULE_TITLE), new Span(DATE_2023_07_29_10_00_00, DATE_2023_08_30_12_00_00)); + } +} diff --git a/backend/src/test/java/team/teamby/teambyteam/common/fixtures/TeamPlaceFixtures.java b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/TeamPlaceFixtures.java new file mode 100644 index 000000000..e2fe75424 --- /dev/null +++ b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/TeamPlaceFixtures.java @@ -0,0 +1,18 @@ +package team.teamby.teambyteam.common.fixtures; + +import team.teamby.teambyteam.teamplace.domain.TeamPlace; +import team.teamby.teambyteam.teamplace.domain.vo.Name; + +public class TeamPlaceFixtures { + + public static final String ENGLISH_TEAM_PLACE_NAME = "영어 팀플"; + public static final String JAPANESE_TEAM_PLACE_NAME = "일본어 팀플"; + + public static TeamPlace ENGLISH_TEAM_PLACE() { + return new TeamPlace(new Name(ENGLISH_TEAM_PLACE_NAME)); + } + + public static TeamPlace JAPANESE_TEAM_PLACE() { + return new TeamPlace(new Name(JAPANESE_TEAM_PLACE_NAME)); + } +} diff --git a/backend/src/test/java/team/teamby/teambyteam/common/fixtures/acceptance/MyCalendarScheduleAcceptanceFixtures.java b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/acceptance/MyCalendarScheduleAcceptanceFixtures.java new file mode 100644 index 000000000..e465cb99b --- /dev/null +++ b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/acceptance/MyCalendarScheduleAcceptanceFixtures.java @@ -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 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(); + } +} diff --git a/backend/src/test/java/team/teamby/teambyteam/common/fixtures/acceptance/TeamCalendarScheduleAcceptanceFixtures.java b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/acceptance/TeamCalendarScheduleAcceptanceFixtures.java new file mode 100644 index 000000000..5e552a02f --- /dev/null +++ b/backend/src/test/java/team/teamby/teambyteam/common/fixtures/acceptance/TeamCalendarScheduleAcceptanceFixtures.java @@ -0,0 +1,78 @@ +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; +import org.springframework.http.MediaType; +import team.teamby.teambyteam.schedule.application.dto.ScheduleRegisterRequest; +import team.teamby.teambyteam.schedule.application.dto.ScheduleUpdateRequest; + +public class TeamCalendarScheduleAcceptanceFixtures { + + private static final String JWT_PREFIX = "Bearer "; + private static final String JWT_TOKEN = "eyJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InBpaWx5YW5nLmRldkBnbWFpbC5jb20iLCJpYXQiOjE2OTA0MzEzMDIsImV4cCI6MTY5MTQzMTMwMn0.W32l9nFapiQXUuQ2WzQ8-X8PA8VsDIX1rC1X67PWcn0"; + + public static ExtractableResponse REGISTER_SCHEDULE_REQUEST(final Long teamPlaceId, final ScheduleRegisterRequest request) { + return RestAssured.given().log().all() + .header("Authorization", JWT_PREFIX + JWT_TOKEN) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .body(request) + .post("/api/team-place/{teamPlaceId}/calendar/schedules", teamPlaceId) + .then().log().all() + .extract(); + } + + public static ExtractableResponse FIND_SPECIFIC_SCHEDULE_REQUEST(final Long scheduleId, final Long teamPlaceId) { + return RestAssured.given().log().all() + .header(new Header("Authorization", JWT_PREFIX + JWT_TOKEN)) + .when().log().all() + .get("/api/team-place/{teamPlaceId}/calendar/schedules/{scheduleId}", teamPlaceId, scheduleId) + .then().log().all() + .extract(); + } + + public static ExtractableResponse FIND_PERIOD_SCHEDULE_REQUEST(final Long teamPlaceId, final Integer year, final Integer month) { + return RestAssured.given().log().all() + .header(new Header("Authorization", JWT_PREFIX + JWT_TOKEN)) + .pathParam("teamPlaceId", teamPlaceId) + .queryParam("year", year) + .queryParam("month", month) + .when().log().all() + .get("/api/team-place/{teamPlaceId}/calendar/schedules") + .then().log().all() + .extract(); + } + + public static ExtractableResponse FIND_DAILY_SCHEDULE_REQUEST(final Long teamPlaceId, final int year, final int month, final int day) { + return RestAssured.given().log().all() + .header(new Header("Authorization", JWT_PREFIX + JWT_TOKEN)) + .pathParam("teamPlaceId", teamPlaceId) + .queryParam("year", year) + .queryParam("month", month) + .queryParam("day", day) + .when().log().all() + .get("/api/team-place/{teamPlaceId}/calendar/schedules") + .then().log().all() + .extract(); + } + + public static ExtractableResponse UPDATE_SCHEDULE_REQUEST(final Long id, final Long teamPlaceId, final ScheduleUpdateRequest request) { + return RestAssured.given().log().all() + .header("Authorization", JWT_PREFIX + JWT_TOKEN) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .body(request) + .patch("/api/team-place/{teamPlaceId}/calendar/schedules/{scheduleId}", teamPlaceId, id) + .then().log().all() + .extract(); + } + + public static ExtractableResponse DELETE_SCHEDULE_REQUEST(final Long teamPlaceId, final Long scheduleId) { + return RestAssured.given().log().all() + .header("Authorization", JWT_PREFIX + JWT_TOKEN) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .delete("/api/team-place/{teamPlaceId}/calendar/schedules/{scheduleId}", teamPlaceId, scheduleId) + .then().log().all() + .extract(); + } +} diff --git a/backend/src/test/java/team/teamby/teambyteam/schedule/acceptance/MyCalendarScheduleAcceptanceTest.java b/backend/src/test/java/team/teamby/teambyteam/schedule/acceptance/MyCalendarScheduleAcceptanceTest.java index 27b925afb..72d9930ab 100644 --- a/backend/src/test/java/team/teamby/teambyteam/schedule/acceptance/MyCalendarScheduleAcceptanceTest.java +++ b/backend/src/test/java/team/teamby/teambyteam/schedule/acceptance/MyCalendarScheduleAcceptanceTest.java @@ -1,7 +1,5 @@ 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; @@ -9,16 +7,26 @@ 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("내 캘린더 일정 조회를 한다") @@ -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 = requestMyCalendarSchedulesInPeriod(year, month); + final ExtractableResponse response = FIND_PERIOD_SCHEDULE_REQUEST(year, month); final List 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 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(); - } } diff --git a/backend/src/test/java/team/teamby/teambyteam/schedule/acceptance/TeamCalendarScheduleAcceptanceTest.java b/backend/src/test/java/team/teamby/teambyteam/schedule/acceptance/TeamCalendarScheduleAcceptanceTest.java index ba435c38a..6536bdee9 100644 --- a/backend/src/test/java/team/teamby/teambyteam/schedule/acceptance/TeamCalendarScheduleAcceptanceTest.java +++ b/backend/src/test/java/team/teamby/teambyteam/schedule/acceptance/TeamCalendarScheduleAcceptanceTest.java @@ -6,6 +6,7 @@ import io.restassured.http.Header; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; +import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -16,10 +17,13 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import team.teamby.teambyteam.common.AcceptanceTest; -import team.teamby.teambyteam.fixtures.ScheduleFixtures; +import team.teamby.teambyteam.member.domain.Member; +import team.teamby.teambyteam.member.domain.MemberTeamPlace; import team.teamby.teambyteam.schedule.application.dto.ScheduleRegisterRequest; import team.teamby.teambyteam.schedule.application.dto.ScheduleResponse; import team.teamby.teambyteam.schedule.application.dto.ScheduleUpdateRequest; +import team.teamby.teambyteam.schedule.domain.Schedule; +import team.teamby.teambyteam.teamplace.domain.TeamPlace; import java.time.LocalDateTime; import java.util.HashMap; @@ -28,7 +32,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static team.teamby.teambyteam.fixtures.ScheduleFixtures.Schedule1_N_Hour; +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.ScheduleFixtures.*; +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.TeamCalendarScheduleAcceptanceFixtures.*; public class TeamCalendarScheduleAcceptanceTest extends AcceptanceTest { @@ -36,7 +45,8 @@ public class TeamCalendarScheduleAcceptanceTest extends AcceptanceTest { private ObjectMapper objectMapper; private static final String JWT_PREFIX = "Bearer "; - private static final String JWT_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiZW1haWwiOiJhYmNkQGdtYWlsLmNvbSIsImlhdCI6MTUxNjIzOTAyMn0.2Amns5eXoGSqLw5KW-i22lH3S85-wfNd3j6Zs2z2Fg4"; + private static final String JWT_TOKEN = "eyJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InBpaWx5YW5nLmRldkBnbWFpbC5jb20iLCJpYXQiOjE2OTA0MzEzMDIsImV4cCI6MTY5MTQzMTMwMn0.W32l9nFapiQXUuQ2WzQ8-X8PA8VsDIX1rC1X67PWcn0"; + private static final String REQUEST_TITLE_KEY = "title"; private static final String REQUEST_START_DATE_TIME_KEY = "startDateTime"; private static final String REQUEST_END_DATE_KEY = "endDateTime"; @@ -49,16 +59,22 @@ class FindTeamPlaceSpecificSchedule { @DisplayName("팀에서 아이디를 가지고 특정 일정을 조회한다.") public void getSpecificSchedule() { // given - final Long teamPlaceId = 1L; - final Long scheduleId = 1L; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); // when - final ExtractableResponse response = requestSpecificSchedule(scheduleId, teamPlaceId); + final ExtractableResponse response = FIND_SPECIFIC_SCHEDULE_REQUEST( + MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId(), ENGLISH_TEAM_PLACE.getId() + ); // then assertSoftly(softly -> { softly.assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); - softly.assertThat(response.jsonPath().getString("title")).isEqualTo("1번 팀플 N시간 일정"); + softly.assertThat(response.jsonPath().getString("title")).isEqualTo(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getTitle().getValue()); softly.assertThat(response.jsonPath().getString("startDateTime")).isEqualTo("2023-07-12 10:00"); softly.assertThat(response.jsonPath().getString("endDateTime")).isEqualTo("2023-07-12 18:00"); }); @@ -68,42 +84,48 @@ public void getSpecificSchedule() { @DisplayName("존재하지 않는 일정 조회시도시 실패한다.") void failGetScheduleWhichIsNotExist() { // given - final Long teamPlaceId = 1L; - final Long wrongScheduleId = 100L; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + final Long wrongScheduleId = -1L; // when - final ExtractableResponse response = requestSpecificSchedule(wrongScheduleId, teamPlaceId); + final ExtractableResponse response = FIND_SPECIFIC_SCHEDULE_REQUEST( + wrongScheduleId, ENGLISH_TEAM_PLACE.getId() + ); // then - assertThat(response.statusCode()).isEqualTo(HttpStatus.NOT_FOUND.value()); - } - - @Test - @DisplayName("다른팀의 일정 조회 시도시 실패한다.") - void failGetScheduleWhichIsNot() { - // given - final Long teamPlaceId = 2L; - final Long wrongScheduleId = 1L; - - // when - final ExtractableResponse response = requestSpecificSchedule(wrongScheduleId, teamPlaceId); - - // then - assertThat(response.statusCode()).isEqualTo(HttpStatus.FORBIDDEN.value()); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(HttpStatus.NOT_FOUND.value()); + softly.assertThat(response.body().asString()).isEqualTo("조회한 일정이 존재하지 않습니다."); + }); } @Test @DisplayName("멤버가 소유하지 않은 팀플레이스의 특정 일정을 조회하면 실패한다.") void failMemberHasNotTeamPlaceSchedule() { // given - final Long unParticipatedTeamPlaceId = 2L; - final Long scheduleIdInTeamPlace = 7L; + 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(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(JAPANESE_TEAM_PLACE.getId())); // when - final ExtractableResponse response = requestSpecificSchedule(scheduleIdInTeamPlace, unParticipatedTeamPlaceId); + final ExtractableResponse response = FIND_SPECIFIC_SCHEDULE_REQUEST( + MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId(), JAPANESE_TEAM_PLACE.getId() + ); // then - assertThat(response.statusCode()).isEqualTo(HttpStatus.FORBIDDEN.value()); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(HttpStatus.FORBIDDEN.value()); + softly.assertThat(response.body().asString()).isEqualTo("접근할 수 없는 팀플레이스입니다."); + }); } } @@ -115,21 +137,31 @@ class FindTeamCalendarScheduleInPeriod { @DisplayName("기간으로 조회 성공한다.") void success() { // given - final Long teamPlaceId = 3L; - final int year = 2023; - final int month = 7; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + + final List schedulesToSave = List.of( + MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE(ENGLISH_TEAM_PLACE.getId()), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId()) + ); + final List expectedSchedules = testFixtureBuilder.buildSchedules(schedulesToSave); + + final LocalDateTime startDateTime = expectedSchedules.get(0).getSpan().getStartDateTime(); + final int year = startDateTime.getYear(); + final int month = startDateTime.getMonthValue(); // when - final ExtractableResponse response = requestTeamPlaceSchedulesInPeriod(teamPlaceId, year, month); - final List schedules = response.jsonPath().getList("schedules", ScheduleResponse.class); + final ExtractableResponse response = FIND_PERIOD_SCHEDULE_REQUEST(ENGLISH_TEAM_PLACE.getId(), year, month); + final List actualSchedules = response.jsonPath().getList("schedules", ScheduleResponse.class); //then assertSoftly(softly -> { softly.assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); - softly.assertThat(schedules.get(0).title()).isEqualTo("3번 팀플 B"); - softly.assertThat(schedules.get(1).title()).isEqualTo("3번 팀플 C"); - softly.assertThat(schedules.get(2).title()).isEqualTo("3번 팀플 E"); - softly.assertThat(schedules.get(3).title()).isEqualTo("3번 팀플 D"); + softly.assertThat(actualSchedules.size()).isEqualTo(2); + softly.assertThat(actualSchedules.get(0).title()).isEqualTo(expectedSchedules.get(0).getTitle().getValue()); + softly.assertThat(actualSchedules.get(1).title()).isEqualTo(expectedSchedules.get(1).getTitle().getValue()); }); } @@ -137,11 +169,20 @@ void success() { @DisplayName("요청에 날짜 정보가 누락되면 조회에 실패한다.") void failWithMissingQuery() { // given - final Long teamPlaceId = 3L; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + + final List schedulesToSave = List.of(MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE( + ENGLISH_TEAM_PLACE.getId()), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId()) + ); + final List expectedSchedules = testFixtureBuilder.buildSchedules(schedulesToSave); final int month = 7; // when - final ExtractableResponse response = requestTeamPlaceSchedulesInPeriod(teamPlaceId, null, month); + final ExtractableResponse response = FIND_PERIOD_SCHEDULE_REQUEST(ENGLISH_TEAM_PLACE.getId(), null, month); //then assertThat(response.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); @@ -151,14 +192,19 @@ void failWithMissingQuery() { @DisplayName("기간 요쳥에 잘못된 형식으로 요쳥되면 조회에 실패한다.") void failWithWrongQuery() { // given - final Long teamPlaceId = 3L; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final String year = "y2023"; final int month = 7; // when final ExtractableResponse response = RestAssured.given().log().all() .header(new Header("Authorization", JWT_PREFIX + JWT_TOKEN)) - .pathParam("teamPlaceId", teamPlaceId) + .pathParam("teamPlaceId", ENGLISH_TEAM_PLACE.getId()) .queryParam("year", year) .queryParam("month", month) .when().log().all() @@ -179,13 +225,23 @@ class FindTeamCalendarDailySchedule { @DisplayName("팀 캘린더 하루 일정 조회에 성공한다.") void success() { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final int year = Schedule1_N_Hour.START_DATE_TIME.getYear(); - final int month = Schedule1_N_Hour.START_DATE_TIME.getMonthValue(); - final int day = Schedule1_N_Hour.START_DATE_TIME.getDayOfMonth(); + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + + final List schedulesToSave = List.of(MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE( + ENGLISH_TEAM_PLACE.getId()), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId()) + ); + final List expectedSchedules = testFixtureBuilder.buildSchedules(schedulesToSave); + + final int year = 2023; + final int month = 7; + final int day = 12; // when - final ExtractableResponse response = requestTeamCalendarDailySchedule(teamPlaceId, year, month, day); + final ExtractableResponse response = FIND_DAILY_SCHEDULE_REQUEST(ENGLISH_TEAM_PLACE.getId(), year, month, day); final List schedules = response.jsonPath().getList("schedules", ScheduleResponse.class); // then @@ -193,7 +249,7 @@ void success() { softly.assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); softly.assertThat(schedules.stream() .map(ScheduleResponse::title)) - .containsExactly("1번 팀플 종일 일정", "1번 팀플 N시간 일정"); + .containsExactly(expectedSchedules.get(0).getTitle().getValue(), expectedSchedules.get(1).getTitle().getValue()); }); } @@ -201,13 +257,18 @@ void success() { @DisplayName("조회한 팀 캘린더 하루 일정이 없으면 빈 리스트가 반환된다.") void successNotExistSchedule() { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final int year = 1000; final int month = 1; final int day = 1; // when - final ExtractableResponse response = requestTeamCalendarDailySchedule(teamPlaceId, year, month, day); + final ExtractableResponse response = FIND_DAILY_SCHEDULE_REQUEST(ENGLISH_TEAM_PLACE.getId(), year, month, day); final List schedules = response.jsonPath().getList("schedules", ScheduleResponse.class); // then @@ -218,13 +279,14 @@ void successNotExistSchedule() { @DisplayName("조회할 팀 플레이스가 존재하지 않으면 조회에 실패한다.") void failTeamPlaceNotExist() { // given + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); final Long notExistTeamPlaceId = -1L; - final int year = Schedule1_N_Hour.START_DATE_TIME.getYear(); - final int month = Schedule1_N_Hour.START_DATE_TIME.getMonthValue(); - final int day = Schedule1_N_Hour.START_DATE_TIME.getDayOfMonth(); + final int year = 2023; + final int month = 7; + final int day = 12; // when - final ExtractableResponse response = requestTeamCalendarDailySchedule(notExistTeamPlaceId, year, month, day); + final ExtractableResponse response = FIND_DAILY_SCHEDULE_REQUEST(notExistTeamPlaceId, year, month, day); // then assertSoftly(softly -> { @@ -232,67 +294,82 @@ void failTeamPlaceNotExist() { softly.assertThat(response.body().asString()).isEqualTo("조회한 팀 플레이스가 존재하지 않습니다."); }); } + } - @Nested - @DisplayName("기간 요쳥에 잘못된 형식으로 요쳥되면 조회에 실패한다.") - class failWithWrongDateTimeType { - - @Test - @DisplayName("잘못된 연도 형식일 경우 실패한다.") - void wrongYear() { - // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final int wrongYear = Integer.MAX_VALUE; - final int month = 7; - final int day = 12; - - // when - ExtractableResponse wrongDayResponse = requestTeamCalendarDailySchedule(teamPlaceId, wrongYear, month, day); - - // then - assertSoftly(softly -> { - softly.assertThat(wrongDayResponse.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); - softly.assertThat(wrongDayResponse.body().asString()).isEqualTo("DateTime 형식이 잘못되었습니다. 서버 관리자에게 문의해주세요."); - }); - } - - @Test - @DisplayName("잘못된 월 형식일 경우 실패한다.") - void wrongMonth() { - // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final int year = 2023; - final int wrongMonth = -1; - final int day = 12; - - // when - ExtractableResponse wrongDayResponse = requestTeamCalendarDailySchedule(teamPlaceId, year, wrongMonth, day); - - // then - assertSoftly(softly -> { - softly.assertThat(wrongDayResponse.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); - softly.assertThat(wrongDayResponse.body().asString()).isEqualTo("DateTime 형식이 잘못되었습니다. 서버 관리자에게 문의해주세요."); - }); - } - - @Test - @DisplayName("잘못된 일 형식일 경우 실패한다.") - void wrongDay() { - // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final int year = 2023; - final int month = 7; - final int wrongDay = -1; - - // when - ExtractableResponse wrongDayResponse = requestTeamCalendarDailySchedule(teamPlaceId, year, month, wrongDay); - - // then - assertSoftly(softly -> { - softly.assertThat(wrongDayResponse.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); - softly.assertThat(wrongDayResponse.body().asString()).isEqualTo("DateTime 형식이 잘못되었습니다. 서버 관리자에게 문의해주세요."); - }); - } + @Nested + @DisplayName("기간 요쳥에 잘못된 형식으로 요쳥되면 조회에 실패한다.") + class failWithWrongDateTimeType { + + @Test + @DisplayName("잘못된 연도 형식일 경우 실패한다.") + void wrongYear() { + // given + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + + final int wrongYear = Integer.MAX_VALUE; + final int month = 7; + final int day = 12; + + // when + ExtractableResponse wrongDayResponse = FIND_DAILY_SCHEDULE_REQUEST(ENGLISH_TEAM_PLACE.getId(), wrongYear, month, day); + + // then + assertSoftly(softly -> { + softly.assertThat(wrongDayResponse.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); + softly.assertThat(wrongDayResponse.body().asString()).isEqualTo("DateTime 형식이 잘못되었습니다. 서버 관리자에게 문의해주세요."); + }); + } + + @Test + @DisplayName("잘못된 월 형식일 경우 실패한다.") + void wrongMonth() { + // given + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + + final int year = 2023; + final int wrongMonth = -1; + final int day = 12; + + // when + ExtractableResponse wrongDayResponse = FIND_DAILY_SCHEDULE_REQUEST(ENGLISH_TEAM_PLACE.getId(), year, wrongMonth, day); + + // then + assertSoftly(softly -> { + softly.assertThat(wrongDayResponse.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); + softly.assertThat(wrongDayResponse.body().asString()).isEqualTo("DateTime 형식이 잘못되었습니다. 서버 관리자에게 문의해주세요."); + }); + } + + @Test + @DisplayName("잘못된 일 형식일 경우 실패한다.") + void wrongDay() { + // given + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + + final int year = 2023; + final int month = 7; + final int wrongDay = -1; + + // when + ExtractableResponse wrongDayResponse = FIND_DAILY_SCHEDULE_REQUEST(ENGLISH_TEAM_PLACE.getId(), year, month, wrongDay); + + // then + assertSoftly(softly -> { + softly.assertThat(wrongDayResponse.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); + softly.assertThat(wrongDayResponse.body().asString()).isEqualTo("DateTime 형식이 잘못되었습니다. 서버 관리자에게 문의해주세요."); + }); } } @@ -304,15 +381,19 @@ class RegisterSchedule { @DisplayName("일정 등록에 성공한다.") void success() { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); // when - final ExtractableResponse successRequest = registerScheduleRequest(teamPlaceId, Schedule1_N_Hour.REQUEST); + final ExtractableResponse successRequest = REGISTER_SCHEDULE_REQUEST(ENGLISH_TEAM_PLACE.getId(), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_REGISTER_REQUEST); // then assertSoftly(softly -> { softly.assertThat(successRequest.statusCode()).isEqualTo(HttpStatus.CREATED.value()); - softly.assertThat(successRequest.header(HttpHeaders.LOCATION)).contains("/api/team-place/" + teamPlaceId + "/calendar/schedules/"); + softly.assertThat(successRequest.header(HttpHeaders.LOCATION)).contains("/api/team-place/" + ENGLISH_TEAM_PLACE.getId() + "/calendar/schedules/"); }); } @@ -321,11 +402,20 @@ void success() { @DisplayName("일정 제목이 빈 값인 요청이면 실패한다.") void failBlankTitleRequest(final String blankTitle) { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final ScheduleRegisterRequest request = new ScheduleRegisterRequest(blankTitle, Schedule1_N_Hour.START_DATE_TIME, Schedule1_N_Hour.END_DATE_TIME); + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId()); + LocalDateTime startDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime(); + LocalDateTime endDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getEndDateTime(); + + final ScheduleRegisterRequest request = new ScheduleRegisterRequest(blankTitle, startDateTime, endDateTime); // when - final ExtractableResponse blankTitleRequest = registerScheduleRequest(teamPlaceId, request); + final ExtractableResponse blankTitleRequest = REGISTER_SCHEDULE_REQUEST(ENGLISH_TEAM_PLACE.getId(), request); // then assertSoftly(softly -> { @@ -339,17 +429,21 @@ void failBlankTitleRequest(final String blankTitle) { @DisplayName("잘못된 날짜 형식 요청이면 실패한다.") void failWrongDateTimeTypeRequest(final String wrongStartDateTimeType) throws JsonProcessingException { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final String title = Schedule1_N_Hour.TITLE; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final String correctEndDateTimeType = "2023-07-12 18:00"; final Map requestMap = new HashMap<>(); - requestMap.put(REQUEST_TITLE_KEY, title); + requestMap.put(REQUEST_TITLE_KEY, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_TITLE); requestMap.put(REQUEST_START_DATE_TIME_KEY, wrongStartDateTimeType); requestMap.put(REQUEST_END_DATE_KEY, correctEndDateTimeType); // when - final ExtractableResponse wrongDateTimeTypeRequest = wrongDateTimeTypeRegisterScheduleRequest(teamPlaceId, requestMap); + final ExtractableResponse wrongDateTimeTypeRequest = wrongDateTimeTypeRegisterScheduleRequest(ENGLISH_TEAM_PLACE.getId(), requestMap); // then assertSoftly(softly -> { @@ -362,14 +456,19 @@ void failWrongDateTimeTypeRequest(final String wrongStartDateTimeType) throws Js @DisplayName("시작 일자와 종료 일자의 순서가 맞지 않으면 실패한다.") void failSpanWrongOrder() { // given - final String title = ScheduleFixtures.Schedule1_N_Hour.TITLE; - final Long teamPlaceId = ScheduleFixtures.Schedule1_N_Hour.TEAM_PLACE_ID; - final LocalDateTime startDateTime = ScheduleFixtures.Schedule1_N_Hour.START_DATE_TIME; - final LocalDateTime wrongEndDateTime = ScheduleFixtures.Schedule1_N_Hour.START_DATE_TIME.minusDays(1); + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + + final String title = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_TITLE; + final LocalDateTime startDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId()).getSpan().getStartDateTime(); + final LocalDateTime wrongEndDateTime = startDateTime.minusDays(1); final ScheduleRegisterRequest request = new ScheduleRegisterRequest(title, startDateTime, wrongEndDateTime); // when & then - final ExtractableResponse wrongSpanOrderResponse = registerScheduleRequest(teamPlaceId, request); + final ExtractableResponse wrongSpanOrderResponse = REGISTER_SCHEDULE_REQUEST(ENGLISH_TEAM_PLACE.getId(), request); // then assertSoftly(softly -> { @@ -382,10 +481,11 @@ void failSpanWrongOrder() { @DisplayName("없는 팀 플레이스 ID로 요청하면 실패한다.") void failNotExistTeamPlaceIdRequest() { // given + testFixtureBuilder.buildMember(PHILIP()); final Long notExistTeamPlaceId = -1L; // when - final ExtractableResponse notExistTeamPlaceIdRequest = registerScheduleRequest(notExistTeamPlaceId, Schedule1_N_Hour.REQUEST); + final ExtractableResponse notExistTeamPlaceIdRequest = REGISTER_SCHEDULE_REQUEST(notExistTeamPlaceId, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_REGISTER_REQUEST); // then assertSoftly(softly -> { @@ -405,6 +505,7 @@ private ExtractableResponse wrongDateTimeTypeRegisterScheduleRequest(f } } + @Nested @DisplayName("일정 수정 시") class UpdateSchedule { @@ -413,12 +514,17 @@ class UpdateSchedule { @DisplayName("일정 수정에 성공한다.") void success() { // given - Long id = Schedule1_N_Hour.ID; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final ScheduleUpdateRequest request = Schedule1_N_Hour.UPDATE_REQUEST; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + + final ScheduleUpdateRequest request = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_UPDATE_REQUEST; // when - final ExtractableResponse updateScheduleResponse = updateSchedule(id, teamPlaceId, request); + final ExtractableResponse updateScheduleResponse = UPDATE_SCHEDULE_REQUEST(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId(), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getTeamPlaceId(), request); // then assertThat(updateScheduleResponse.statusCode()).isEqualTo(HttpStatus.OK.value()); @@ -429,12 +535,19 @@ void success() { @DisplayName("일정 제목이 빈 값인 요청이면 실패한다.") void failBlankTitleRequest(final String blankTitle) { // given - final Long id = Schedule1_N_Hour.ID; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final ScheduleUpdateRequest request = new ScheduleUpdateRequest(blankTitle, Schedule1_N_Hour.START_DATE_TIME, Schedule1_N_Hour.END_DATE_TIME); + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + final LocalDateTime startDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime(); + final LocalDateTime endDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getEndDateTime(); + + final ScheduleUpdateRequest request = new ScheduleUpdateRequest(blankTitle, startDateTime, endDateTime); // when - final ExtractableResponse blankTitleRequest = updateSchedule(id, teamPlaceId, request); + final ExtractableResponse blankTitleRequest = UPDATE_SCHEDULE_REQUEST(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId(), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getTeamPlaceId(), request); // then assertSoftly(softly -> { @@ -448,18 +561,21 @@ void failBlankTitleRequest(final String blankTitle) { @DisplayName("잘못된 날짜 형식 요청이면 실패한다.") void failWrongDateTimeTypeRequest(final String wrongStartDateTimeType) throws JsonProcessingException { // given - final Long id = Schedule1_N_Hour.ID; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final String title = Schedule1_N_Hour.TITLE; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); final String correctEndDateTimeType = "2023-07-12 18:00"; final Map requestMap = new HashMap<>(); - requestMap.put(REQUEST_TITLE_KEY, title); + requestMap.put(REQUEST_TITLE_KEY, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getTitle().getValue()); requestMap.put(REQUEST_START_DATE_TIME_KEY, wrongStartDateTimeType); requestMap.put(REQUEST_END_DATE_KEY, correctEndDateTimeType); // when - final ExtractableResponse wrongDateTimeTypeRequest = wrongDateTimeTypeUpdateScheduleRequest(teamPlaceId, id, requestMap); + final ExtractableResponse wrongDateTimeTypeRequest = wrongDateTimeTypeUpdateScheduleRequest(ENGLISH_TEAM_PLACE.getId(), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId(), requestMap); // then assertSoftly(softly -> { @@ -472,12 +588,18 @@ void failWrongDateTimeTypeRequest(final String wrongStartDateTimeType) throws Js @DisplayName("없는 팀 플레이스 ID로 요청하면 실패한다.") void failNotExistTeamPlaceIdRequest() { // given - final Long id = 1L; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + + ScheduleUpdateRequest request = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_UPDATE_REQUEST; final Long notExistTeamPlaceId = -1L; - ScheduleUpdateRequest request = Schedule1_N_Hour.UPDATE_REQUEST; // when - final ExtractableResponse notExistTeamPlaceIdRequest = updateSchedule(id, notExistTeamPlaceId, request); + final ExtractableResponse notExistTeamPlaceIdRequest = UPDATE_SCHEDULE_REQUEST(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId(), notExistTeamPlaceId, request); // then assertSoftly(softly -> { @@ -505,27 +627,35 @@ class DeleteSchedule { @DisplayName("일정 삭제가 성공한다.") void success() { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final Long scheduleId = Schedule1_N_Hour.ID; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); // when - final ExtractableResponse deleteScheduleResponse = deleteSchedule(teamPlaceId, scheduleId); + final ExtractableResponse deleteScheduleResponse = DELETE_SCHEDULE_REQUEST(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getTeamPlaceId(), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId()); // then - assertSoftly(softly -> { - softly.assertThat(deleteScheduleResponse.statusCode()).isEqualTo(HttpStatus.NO_CONTENT.value()); - }); + assertThat(deleteScheduleResponse.statusCode()).isEqualTo(HttpStatus.NO_CONTENT.value()); } @Test @DisplayName("없는 팀 플레이스의 ID로 요청하면 실패한다.") void failNotExistTeamPlaceIdRequest() { // given + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + final Long notExistTeamPlaceId = -1L; - final Long existScheduleId = Schedule1_N_Hour.ID; // when - final ExtractableResponse notExistTeamPlaceIdDeleteScheduleResponse = deleteSchedule(notExistTeamPlaceId, existScheduleId); + final ExtractableResponse notExistTeamPlaceIdDeleteScheduleResponse = DELETE_SCHEDULE_REQUEST(notExistTeamPlaceId, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId()); // then assertSoftly(softly -> { @@ -538,11 +668,17 @@ void failNotExistTeamPlaceIdRequest() { @DisplayName("없는 팀 일정 ID로 요청하면 실패한다.") void failNotExistScheduleId() { // given - final Long existTeamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; + final Member PHILIP = testFixtureBuilder.buildMember(PHILIP()); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final MemberTeamPlace PHILIP_ENGLISH_TEAM_PLACE = PHILIP_ENGLISH_TEAM_PLACE(); + PHILIP_ENGLISH_TEAM_PLACE.setMemberAndTeamPlace(PHILIP, ENGLISH_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlace(PHILIP_ENGLISH_TEAM_PLACE); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + final Long notExistScheduleId = -1L; // when - final ExtractableResponse notExistScheduleIdDeleteResponse = deleteSchedule(existTeamPlaceId, notExistScheduleId); + final ExtractableResponse notExistScheduleIdDeleteResponse = DELETE_SCHEDULE_REQUEST(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getTeamPlaceId(), notExistScheduleId); // then assertSoftly(softly -> { @@ -551,68 +687,5 @@ void failNotExistScheduleId() { }); } } - - - private ExtractableResponse registerScheduleRequest(final Long teamPlaceId, final ScheduleRegisterRequest request) { - return RestAssured.given().log().all() - .header("Authorization", JWT_PREFIX + JWT_TOKEN) - .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(request) - .post("/api/team-place/{teamPlaceId}/calendar/schedules", teamPlaceId) - .then().log().all() - .extract(); - } - - private ExtractableResponse requestSpecificSchedule(final Long scheduleId, final Long teamPlaceId) { - return RestAssured.given().log().all() - .header(new Header("Authorization", JWT_PREFIX + JWT_TOKEN)) - .when().log().all() - .get("/api/team-place/{teamPlaceId}/calendar/schedules/{scheduleId}", teamPlaceId, scheduleId) - .then().log().all() - .extract(); - } - - private ExtractableResponse requestTeamPlaceSchedulesInPeriod(final Long teamPlaceId, final Integer year, final Integer month) { - return RestAssured.given().log().all() - .header(new Header("Authorization", JWT_PREFIX + JWT_TOKEN)) - .pathParam("teamPlaceId", teamPlaceId) - .queryParam("year", year) - .queryParam("month", month) - .when().log().all() - .get("/api/team-place/{teamPlaceId}/calendar/schedules") - .then().log().all() - .extract(); - } - - private ExtractableResponse requestTeamCalendarDailySchedule(final Long teamPlaceId, final int year, final int month, final int day) { - return RestAssured.given().log().all() - .header(new Header("Authorization", JWT_PREFIX + JWT_TOKEN)) - .pathParam("teamPlaceId", teamPlaceId) - .queryParam("year", year) - .queryParam("month", month) - .queryParam("day", day) - .when().log().all() - .get("/api/team-place/{teamPlaceId}/calendar/schedules") - .then().log().all() - .extract(); - } - - private ExtractableResponse updateSchedule(final Long id, final Long teamPlaceId, final ScheduleUpdateRequest request) { - return RestAssured.given().log().all() - .header("Authorization", JWT_PREFIX + JWT_TOKEN) - .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(request) - .patch("/api/team-place/{teamPlaceId}/calendar/schedules/{scheduleId}", teamPlaceId, id) - .then().log().all() - .extract(); - } - - private ExtractableResponse deleteSchedule(final Long teamPlaceId, final Long scheduleId) { - return RestAssured.given().log().all() - .header("Authorization", JWT_PREFIX + JWT_TOKEN) - .contentType(MediaType.APPLICATION_JSON_VALUE) - .delete("/api/team-place/{teamPlaceId}/calendar/schedules/{scheduleId}", teamPlaceId, scheduleId) - .then().log().all() - .extract(); - } } + diff --git a/backend/src/test/java/team/teamby/teambyteam/schedule/application/MyCalendarScheduleServiceTest.java b/backend/src/test/java/team/teamby/teambyteam/schedule/application/MyCalendarScheduleServiceTest.java index 685d1887b..2c17778a2 100644 --- a/backend/src/test/java/team/teamby/teambyteam/schedule/application/MyCalendarScheduleServiceTest.java +++ b/backend/src/test/java/team/teamby/teambyteam/schedule/application/MyCalendarScheduleServiceTest.java @@ -4,21 +4,27 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.transaction.annotation.Transactional; +import team.teamby.teambyteam.common.ServiceTest; import team.teamby.teambyteam.member.configuration.dto.MemberEmailDto; +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.application.dto.SchedulesWithTeamPlaceIdResponse; +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; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) -@Transactional -@Sql({"/h2-reset-pk.sql", "/h2-data.sql"}) -public class MyCalendarScheduleServiceTest { +public class MyCalendarScheduleServiceTest extends ServiceTest { @Autowired private MyCalendarScheduleService myCalendarScheduleService; @@ -31,25 +37,38 @@ class FindScheduleInMyCalendar { @DisplayName("내 캘린더 정보 조회를 성공한다.") void success() { // given - // member who participate in team 2, 3 - final MemberEmailDto memberEmailDto = new MemberEmailDto("dfg345@gmail.com"); + 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); + + List memberTeamPlaces = List.of(PHILIP_ENGLISH_TEAM_PLACE, PHILIP_JAPANESE_TEAM_PLACE); + testFixtureBuilder.buildMemberTeamPlaces(memberTeamPlaces); + + List expectedSchedules = List.of( + MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE(ENGLISH_TEAM_PLACE.getId()), + MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(JAPANESE_TEAM_PLACE.getId()) + ); + testFixtureBuilder.buildSchedules(expectedSchedules); + + final MemberEmailDto memberEmailDto = new MemberEmailDto(PHILIP.getEmail().getValue()); final int year = 2023; - final int month = 6; + final int month = 7; // when - final SchedulesWithTeamPlaceIdResponse scheduleInPeriod = myCalendarScheduleService.findScheduleInPeriod(memberEmailDto, year, month); + final SchedulesWithTeamPlaceIdResponse scheduleInPeriod = myCalendarScheduleService.findScheduleInPeriod(memberEmailDto, year, month); final List scheduleResponses = scheduleInPeriod.schedules(); //then assertSoftly(softly -> { - softly.assertThat(scheduleResponses).hasSize(5); - softly.assertThat(scheduleResponses.get(0).title()).isEqualTo("3번 팀플 6월 첫날"); - softly.assertThat(scheduleResponses.get(1).title()).isEqualTo("2번 팀플 6월 첫날"); - softly.assertThat(scheduleResponses.get(2).title()).isEqualTo("3번 팀플 A"); - softly.assertThat(scheduleResponses.get(3).title()).isEqualTo("2번 팀플 6월 어느날"); - softly.assertThat(scheduleResponses.get(4).title()).isEqualTo("3번 팀플 B"); + softly.assertThat(scheduleResponses).hasSize(2); + softly.assertThat(scheduleResponses.get(0).title()).isEqualTo(expectedSchedules.get(0).getTitle().getValue()); + softly.assertThat(scheduleResponses.get(1).title()).isEqualTo(expectedSchedules.get(1).getTitle().getValue()); }); } - } } diff --git a/backend/src/test/java/team/teamby/teambyteam/schedule/application/TeamCalendarScheduleServiceTest.java b/backend/src/test/java/team/teamby/teambyteam/schedule/application/TeamCalendarScheduleServiceTest.java index 91ec404ac..0ead5f333 100644 --- a/backend/src/test/java/team/teamby/teambyteam/schedule/application/TeamCalendarScheduleServiceTest.java +++ b/backend/src/test/java/team/teamby/teambyteam/schedule/application/TeamCalendarScheduleServiceTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import team.teamby.teambyteam.common.ServiceTest; -import team.teamby.teambyteam.fixtures.ScheduleFixtures; +import team.teamby.teambyteam.common.fixtures.ScheduleFixtures; import team.teamby.teambyteam.schedule.application.dto.ScheduleRegisterRequest; import team.teamby.teambyteam.schedule.application.dto.ScheduleResponse; import team.teamby.teambyteam.schedule.application.dto.ScheduleUpdateRequest; @@ -15,16 +15,20 @@ import team.teamby.teambyteam.schedule.domain.Schedule; import team.teamby.teambyteam.schedule.domain.ScheduleRepository; import team.teamby.teambyteam.schedule.exception.ScheduleException; +import team.teamby.teambyteam.teamplace.domain.TeamPlace; import team.teamby.teambyteam.teamplace.exception.TeamPlaceException; import java.time.DateTimeException; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static team.teamby.teambyteam.fixtures.ScheduleFixtures.Schedule1_N_Hour; +import static team.teamby.teambyteam.common.fixtures.ScheduleFixtures.*; +import static team.teamby.teambyteam.common.fixtures.TeamPlaceFixtures.ENGLISH_TEAM_PLACE; +import static team.teamby.teambyteam.common.fixtures.TeamPlaceFixtures.JAPANESE_TEAM_PLACE; public class TeamCalendarScheduleServiceTest extends ServiceTest { @@ -34,6 +38,8 @@ public class TeamCalendarScheduleServiceTest extends ServiceTest { @Autowired private ScheduleRepository scheduleRepository; + private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + @Nested @DisplayName("팀 캘린더 일정 정보 조회시") class FindScheduleInTeamCalendar { @@ -42,17 +48,20 @@ class FindScheduleInTeamCalendar { @DisplayName("특정 일정의 정보를 조회한다.") void findSpecificSchedule() { // given - final Long scheduleId = 1L; - final Long teamPlaceId = 1L; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + final String expectedStartDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime().format(dateTimeFormatter); + final String expectedEndDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getEndDateTime().format(dateTimeFormatter); // when - final ScheduleResponse scheduleResponse = teamCalendarScheduleService.findSchedule(scheduleId, teamPlaceId); + final ScheduleResponse scheduleResponse = teamCalendarScheduleService.findSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId(), ENGLISH_TEAM_PLACE_ID); //then assertSoftly(softly -> { - softly.assertThat(scheduleResponse.title()).isEqualTo("1번 팀플 N시간 일정"); - softly.assertThat(scheduleResponse.startDateTime()).isEqualTo("2023-07-12 10:00"); - softly.assertThat(scheduleResponse.endDateTime()).isEqualTo("2023-07-12 18:00"); + softly.assertThat(scheduleResponse.title()).isEqualTo(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getTitle().getValue()); + softly.assertThat(scheduleResponse.startDateTime()).isEqualTo(expectedStartDateTime); + softly.assertThat(scheduleResponse.endDateTime()).isEqualTo(expectedEndDateTime); }); } @@ -60,11 +69,12 @@ void findSpecificSchedule() { @DisplayName("요청한 일정의 정보가 없으면 예외를 발생시킨다.") void failFindUnExistingSchedule() { // given - final Long wrongScheduleId = 100L; - final Long teamPlaceId = 1L; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Long wrongScheduleId = -1L; // when & then - assertThatThrownBy(() -> teamCalendarScheduleService.findSchedule(wrongScheduleId, teamPlaceId)) + assertThatThrownBy(() -> teamCalendarScheduleService.findSchedule(wrongScheduleId, ENGLISH_TEAM_PLACE_ID)) .isInstanceOf(ScheduleException.ScheduleNotFoundException.class) .hasMessage("조회한 일정이 존재하지 않습니다."); @@ -74,11 +84,15 @@ void failFindUnExistingSchedule() { @DisplayName("요청한 정보가 팀의 일정이 아니면 예외를 발생시킨다.") void failFindOtherTeamPlaceSchedule() { // given - final Long scheduleId = 1L; - final Long otherTeamId = 2L; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final TeamPlace JAPANESE_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(JAPANESE_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Long JAPANESE_TEAM_PLACE_ID = JAPANESE_TEAM_PLACE.getId(); + + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); // when & then - assertThatThrownBy(() -> teamCalendarScheduleService.findSchedule(scheduleId, otherTeamId)) + assertThatThrownBy(() -> teamCalendarScheduleService.findSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId(), JAPANESE_TEAM_PLACE_ID)) .isInstanceOf(ScheduleException.TeamAccessForbidden.class) .hasMessage("해당 팀플레이스에 일정을 조회할 권한이 없습니다."); } @@ -87,21 +101,26 @@ void failFindOtherTeamPlaceSchedule() { @DisplayName("팀 캘린더에서 특정 기간 내 일정들을 조회한다.") void findAllInPeriod() { // given - final Long teamPlaceId = 3L; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Schedule MONTH_6_AND_MONTH_7_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_6_AND_MONTH_7_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + final Schedule MONTH_7_DAY_28_AND_MONTH_8_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_DAY_28_AND_MONTH_8_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + final Schedule MONTH_7_DAY_29_AND_MONTH_8_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_DAY_29_AND_MONTH_8_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + final int year = 2023; final int month = 7; // when - final SchedulesResponse schedulesResponse = teamCalendarScheduleService.findScheduleInPeriod(teamPlaceId, year, month); + final SchedulesResponse schedulesResponse = teamCalendarScheduleService.findScheduleInPeriod(ENGLISH_TEAM_PLACE.getId(), year, month); final List scheduleResponses = schedulesResponse.schedules(); //then assertSoftly(softly -> { softly.assertThat(scheduleResponses).hasSize(4); - softly.assertThat(scheduleResponses.get(0).title()).isEqualTo("3번 팀플 B"); - softly.assertThat(scheduleResponses.get(1).title()).isEqualTo("3번 팀플 C"); - softly.assertThat(scheduleResponses.get(2).title()).isEqualTo("3번 팀플 E"); - softly.assertThat(scheduleResponses.get(3).title()).isEqualTo("3번 팀플 D"); + softly.assertThat(scheduleResponses.get(0).title()).isEqualTo(MONTH_6_AND_MONTH_7_SCHEDULE.getTitle().getValue()); + softly.assertThat(scheduleResponses.get(1).title()).isEqualTo(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getTitle().getValue()); + softly.assertThat(scheduleResponses.get(2).title()).isEqualTo(MONTH_7_DAY_28_AND_MONTH_8_SCHEDULE.getTitle().getValue()); + softly.assertThat(scheduleResponses.get(3).title()).isEqualTo(MONTH_7_DAY_29_AND_MONTH_8_SCHEDULE.getTitle().getValue()); }); } @@ -109,12 +128,12 @@ void findAllInPeriod() { @DisplayName("팀 캘린더에서 일정이 없는 기간 내 일정들을 조회한다.") void findAllInPeriodWith0Schedule() { // given - final Long teamPlaceId = 3L; - final int year = 1000; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final int notExistYear = -1; final int month = 7; // when - final SchedulesResponse schedulesResponse = teamCalendarScheduleService.findScheduleInPeriod(teamPlaceId, year, month); + final SchedulesResponse schedulesResponse = teamCalendarScheduleService.findScheduleInPeriod(ENGLISH_TEAM_PLACE.getId(), notExistYear, month); final List scheduleResponses = schedulesResponse.schedules(); //then @@ -125,23 +144,26 @@ void findAllInPeriodWith0Schedule() { @DisplayName("첫날과 마지막날 일정이 정상적으로 조회 된다.") void firstAndLastDateScheduleFind() { // given - final Long teamPlaceId = 3L; - final int year = 2023; - final int month = 5; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Schedule MONTH_5_FIRST_DAY_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_5_FIRST_DAY_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + final Schedule MONTH_5_LAST_DAY_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_5_LAST_DAY_SCHEDULE(ENGLISH_TEAM_PLACE.getId())); + + final int year = MONTH_5_FIRST_DAY_SCHEDULE.getSpan().getStartDateTime().getYear(); + final int month = MONTH_5_FIRST_DAY_SCHEDULE.getSpan().getStartDateTime().getMonthValue(); // when - final SchedulesResponse schedulesResponse = teamCalendarScheduleService.findScheduleInPeriod(teamPlaceId, year, month); + final SchedulesResponse schedulesResponse = teamCalendarScheduleService.findScheduleInPeriod(ENGLISH_TEAM_PLACE.getId(), year, month); final List scheduleResponses = schedulesResponse.schedules(); //then assertSoftly(softly -> { softly.assertThat(scheduleResponses).hasSize(2); - softly.assertThat(scheduleResponses.get(0).title()).isEqualTo("3번 팀플 5월 첫날"); - softly.assertThat(scheduleResponses.get(1).title()).isEqualTo("3번 팀플 5월 마지막날"); + softly.assertThat(scheduleResponses.get(0).title()).isEqualTo(MONTH_5_FIRST_DAY_SCHEDULE.getTitle().getValue()); + softly.assertThat(scheduleResponses.get(1).title()).isEqualTo(MONTH_5_LAST_DAY_SCHEDULE.getTitle().getValue()); }); } } - + @Nested @DisplayName("팀 캘린더 하루 일정 조회 시") class FindTeamCalendarDailySchedule { @@ -150,22 +172,26 @@ class FindTeamCalendarDailySchedule { @DisplayName("팀 캘린더 하루 일정 조회를 성공한다.") void success() { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final int year = Schedule1_N_Hour.START_DATE_TIME.getYear(); - final int month = Schedule1_N_Hour.START_DATE_TIME.getMonthValue(); - final int day = Schedule1_N_Hour.START_DATE_TIME.getDayOfMonth(); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + final Schedule MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + + final int year = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime().getYear(); + final int month = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime().getMonthValue(); + final int day = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime().getDayOfMonth(); // when final SchedulesResponse dailySchedulesResponse = - teamCalendarScheduleService.findDailySchedule(teamPlaceId, year, month, day); + teamCalendarScheduleService.findDailySchedule(ENGLISH_TEAM_PLACE_ID, year, month, day); final List dailyTeamCalendarSchedulesResponses = dailySchedulesResponse.schedules(); // then assertSoftly(softly -> { softly.assertThat(dailyTeamCalendarSchedulesResponses).hasSize(2); softly.assertThat(dailyTeamCalendarSchedulesResponses.stream() - .map(ScheduleResponse::title)) - .containsExactly("1번 팀플 종일 일정", "1번 팀플 N시간 일정"); + .map(ScheduleResponse::title)) + .containsExactly(MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE.getTitle().getValue(), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getTitle().getValue()); }); } @@ -177,13 +203,15 @@ class failWrongDateTimeType { @DisplayName("잘못된 연도 형식일 경우 실패한다.") void wrongYear() { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); final int wrongYear = Integer.MAX_VALUE; - final int month = 7; - final int day = 12; + final int month = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime().getMonthValue(); + final int day = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime().getDayOfMonth(); // when & then - assertThatThrownBy(() -> teamCalendarScheduleService.findDailySchedule(teamPlaceId, wrongYear, month, day)) + assertThatThrownBy(() -> teamCalendarScheduleService.findDailySchedule(ENGLISH_TEAM_PLACE_ID, wrongYear, month, day)) .isInstanceOf(DateTimeException.class) .hasMessageContaining("Invalid value for Year (valid values -999999999 - 999999999)"); } @@ -192,13 +220,15 @@ void wrongYear() { @DisplayName("잘못된 월 형식일 경우 실패한다.") void wrongMonth() { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final int year = 2023; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + final int year = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime().getYear(); final int wrongMonth = -1; - final int day = 12; + final int day = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime().getDayOfMonth(); // when & then - assertThatThrownBy(() -> teamCalendarScheduleService.findDailySchedule(teamPlaceId, year, wrongMonth, day)) + assertThatThrownBy(() -> teamCalendarScheduleService.findDailySchedule(ENGLISH_TEAM_PLACE_ID, year, wrongMonth, day)) .isInstanceOf(DateTimeException.class) .hasMessageContaining("Invalid value for MonthOfYear (valid values 1 - 12)"); } @@ -207,13 +237,15 @@ void wrongMonth() { @DisplayName("잘못된 일 형식일 경우 실패한다.") void wrongDay() { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final int year = 2023; - final int month = 7; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + final int year = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime().getYear(); + final int month = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime().getDayOfMonth(); final int wrongDay = -1; // when & then - assertThatThrownBy(() -> teamCalendarScheduleService.findDailySchedule(teamPlaceId, year, month, wrongDay)) + assertThatThrownBy(() -> teamCalendarScheduleService.findDailySchedule(ENGLISH_TEAM_PLACE_ID, year, month, wrongDay)) .isInstanceOf(DateTimeException.class) .hasMessageContaining("Invalid value for DayOfMonth (valid values 1 - 28/31)"); } @@ -223,13 +255,13 @@ void wrongDay() { @DisplayName("조회한 팀 캘린더 하루 일정이 없으면 빈 리스트가 반환된다.") void successNotExistSchedule() { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final int year = 1000; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final int year = -1; final int month = 1; final int day = 1; // when - SchedulesResponse schedules = teamCalendarScheduleService.findDailySchedule(teamPlaceId, year, month, day); + SchedulesResponse schedules = teamCalendarScheduleService.findDailySchedule(ENGLISH_TEAM_PLACE.getId(), year, month, day); // then assertThat(schedules.schedules()).hasSize(0); @@ -240,9 +272,9 @@ void successNotExistSchedule() { void failTeamPlaceNotExist() { // given final Long notExistTeamPlaceId = -1L; - final int year = Schedule1_N_Hour.START_DATE_TIME.getYear(); - final int month = Schedule1_N_Hour.START_DATE_TIME.getMonthValue(); - final int day = Schedule1_N_Hour.START_DATE_TIME.getDayOfMonth(); + final int year = 2023; + final int month = 1; + final int day = 1; // when & then assertThatThrownBy(() -> teamCalendarScheduleService.findDailySchedule(notExistTeamPlaceId, year, month, day)) @@ -259,11 +291,11 @@ class RegisterSchedule { @DisplayName("일정 등록에 성공한다.") void success() { // given - final Long teamPlaceId = 1L; - final ScheduleRegisterRequest request = ScheduleFixtures.Schedule1_N_Hour.REQUEST; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final ScheduleRegisterRequest request = ScheduleFixtures.MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_REGISTER_REQUEST; // when - final Long registeredId = teamCalendarScheduleService.register(request, teamPlaceId); + final Long registeredId = teamCalendarScheduleService.register(request, ENGLISH_TEAM_PLACE.getId()); // then assertThat(registeredId).isNotNull(); @@ -273,14 +305,15 @@ void success() { @DisplayName("일정 등록 시 Span 순서가 맞지 않으면 예외가 발생한다.") void failSpanWrongOrder() { // given - final String title = ScheduleFixtures.Schedule1_N_Hour.TITLE; - final Long teamPlaceId = ScheduleFixtures.Schedule1_N_Hour.TEAM_PLACE_ID; - final LocalDateTime startDateTime = ScheduleFixtures.Schedule1_N_Hour.START_DATE_TIME; - final LocalDateTime wrongEndDateTime = ScheduleFixtures.Schedule1_N_Hour.START_DATE_TIME.minusDays(1); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE.getId()); + final String title = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getTitle().getValue(); + final LocalDateTime startDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime(); + final LocalDateTime wrongEndDateTime = startDateTime.minusDays(1); final ScheduleRegisterRequest request = new ScheduleRegisterRequest(title, startDateTime, wrongEndDateTime); // when & then - assertThatThrownBy(() -> teamCalendarScheduleService.register(request, teamPlaceId)) + assertThatThrownBy(() -> teamCalendarScheduleService.register(request, ENGLISH_TEAM_PLACE.getId())) .isInstanceOf(ScheduleException.SpanWrongOrderException.class) .hasMessage("시작 일자가 종료 일자보다 이후일 수 없습니다."); } @@ -289,7 +322,7 @@ void failSpanWrongOrder() { @DisplayName("일정 등록 시 팀 플레이스 ID에 해당하는 팀 플레이스가 존재하지 않으면 예외가 발생한다.") void failTeamPlaceNotExistById() { // given - final ScheduleRegisterRequest request = ScheduleFixtures.Schedule1_N_Hour.REQUEST; + final ScheduleRegisterRequest request = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_REGISTER_REQUEST; final Long notExistTeamPlaceId = -1L; // when & then @@ -307,18 +340,21 @@ class UpdateSchedule { @DisplayName("일정 수정에 성공한다.") void success() { // given - final Long id = Schedule1_N_Hour.ID; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final ScheduleUpdateRequest request = Schedule1_N_Hour.UPDATE_REQUEST; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + final Long MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_ID = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId(); + + final LocalDateTime startTimeToUpdate = DATE_2023_07_12_00_00_00; + final ScheduleUpdateRequest request = new ScheduleUpdateRequest(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_TITLE, startTimeToUpdate, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getEndDateTime()); + // when - teamCalendarScheduleService.update(request, teamPlaceId, id); - final Schedule updatedSchedule = scheduleRepository.findById(id).get(); + teamCalendarScheduleService.update(request, ENGLISH_TEAM_PLACE_ID, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_ID); + final Schedule updatedSchedule = scheduleRepository.findById(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_ID).get(); // then - assertThat(updatedSchedule).usingRecursiveComparison() - .ignoringFields("id", "createdAt", "updatedAt") - .isEqualTo(Schedule1_N_Hour.UPDATE_ENTITY()); + assertThat(updatedSchedule.getSpan().getStartDateTime()).isEqualTo(startTimeToUpdate); } @ParameterizedTest @@ -326,14 +362,16 @@ void success() { @DisplayName("일정 수정 시 수정할 일정 제목이 빈 값이면 예외가 발생한다.") void failUpdateTitleBlank(String titleToUpdate) { // given - final Long id = Schedule1_N_Hour.ID; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final LocalDateTime startDateTime = Schedule1_N_Hour.START_DATE_TIME; - final LocalDateTime endDateTime = Schedule1_N_Hour.END_DATE_TIME; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + + final LocalDateTime startDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime(); + final LocalDateTime endDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getEndDateTime(); final ScheduleUpdateRequest request = new ScheduleUpdateRequest(titleToUpdate, startDateTime, endDateTime); // when & then - assertThatThrownBy(() -> teamCalendarScheduleService.update(request, teamPlaceId, id)) + assertThatThrownBy(() -> teamCalendarScheduleService.update(request, ENGLISH_TEAM_PLACE_ID, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId())) .isInstanceOf(ScheduleException.TitleBlankException.class) .hasMessage("일정의 제목은 빈 칸일 수 없습니다."); } @@ -342,15 +380,17 @@ void failUpdateTitleBlank(String titleToUpdate) { @DisplayName("일정 수정 시 Span 순서가 맞지 않으면 예외가 발생한다.") void failSpanWrongOrder() { // given - final Long id = Schedule1_N_Hour.ID; - final String title = Schedule1_N_Hour.TITLE; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final LocalDateTime startDateTime = Schedule1_N_Hour.START_DATE_TIME; - final LocalDateTime wrongEndDateTime = Schedule1_N_Hour.START_DATE_TIME.minusDays(1); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + + String title = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getTitle().getValue(); + final LocalDateTime startDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime(); + final LocalDateTime wrongEndDateTime = startDateTime.minusDays(1); final ScheduleUpdateRequest request = new ScheduleUpdateRequest(title, startDateTime, wrongEndDateTime); // when & then - assertThatThrownBy(() -> teamCalendarScheduleService.update(request, teamPlaceId, id)) + assertThatThrownBy(() -> teamCalendarScheduleService.update(request, ENGLISH_TEAM_PLACE_ID, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId())) .isInstanceOf(ScheduleException.SpanWrongOrderException.class) .hasMessage("시작 일자가 종료 일자보다 이후일 수 없습니다."); } @@ -359,12 +399,14 @@ void failSpanWrongOrder() { @DisplayName("일정 수정 시 팀 플레이스 ID에 해당하는 팀 플레이스가 존재하지 않으면 예외가 발생한다.") void failTeamPlaceNotExistById() { // given - final Long id = Schedule1_N_Hour.ID; - final ScheduleUpdateRequest request = Schedule1_N_Hour.UPDATE_REQUEST; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + final ScheduleUpdateRequest request = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_UPDATE_REQUEST; final Long notExistTeamPlaceId = -1L; // when & then - assertThatThrownBy(() -> teamCalendarScheduleService.update(request, notExistTeamPlaceId, id)) + assertThatThrownBy(() -> teamCalendarScheduleService.update(request, notExistTeamPlaceId, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId())) .isInstanceOf(TeamPlaceException.NotFoundException.class) .hasMessage("조회한 팀 플레이스가 존재하지 않습니다."); } @@ -373,12 +415,12 @@ void failTeamPlaceNotExistById() { @DisplayName("일정 수정 시 수정할 일정 ID에 해당하는 일정이 존재하지 않으면 예외가 발생한다.") void failScheduleNotExistById() { // given + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); final Long notExistScheduleId = -1L; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final ScheduleUpdateRequest request = Schedule1_N_Hour.UPDATE_REQUEST; + final ScheduleUpdateRequest request = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_UPDATE_REQUEST; // when & then - assertThatThrownBy(() -> teamCalendarScheduleService.update(request, teamPlaceId, notExistScheduleId)) + assertThatThrownBy(() -> teamCalendarScheduleService.update(request, ENGLISH_TEAM_PLACE.getId(), notExistScheduleId)) .isInstanceOf(ScheduleException.ScheduleNotFoundException.class) .hasMessage("조회한 일정이 존재하지 않습니다."); } @@ -392,18 +434,20 @@ class DeleteSchedule { @DisplayName("일정 삭제에 성공한다.") void success() { // given - final Long teamPlaceId = 1L; - final ScheduleRegisterRequest request = ScheduleFixtures.Schedule1_N_Hour.REQUEST; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); // when - final Long registeredId = teamCalendarScheduleService.register(request, teamPlaceId); + teamCalendarScheduleService.delete(ENGLISH_TEAM_PLACE_ID, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId()); + // then - assertThat(registeredId).isNotNull(); + assertThat(scheduleRepository.findById(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getId()).isEmpty()).isTrue(); } @Test - @DisplayName("일정 등록 시 팀 플레이스 ID에 해당하는 팀 플레이스가 존재하지 않으면 예외가 발생한다.") + @DisplayName("일정 삭제 시 팀 플레이스 ID에 해당하는 팀 플레이스가 존재하지 않으면 예외가 발생한다.") void failTeamPlaceNotExistById() { // given final Long notExistTramPlaceId = -1L; @@ -419,11 +463,12 @@ void failTeamPlaceNotExistById() { @DisplayName("일정 삭제 시 존재하지 않는 일정 Id면 실패한다.") void failScheduleNotExistById() { // given - final Long existTramPlaceId = 1L; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); final Long notExistScheduleId = -1L; // when & then - assertThatThrownBy(() -> teamCalendarScheduleService.delete(existTramPlaceId, notExistScheduleId)) + assertThatThrownBy(() -> teamCalendarScheduleService.delete(ENGLISH_TEAM_PLACE_ID, notExistScheduleId)) .isInstanceOf(ScheduleException.ScheduleNotFoundException.class) .hasMessage("조회한 일정이 존재하지 않습니다."); } diff --git a/backend/src/test/java/team/teamby/teambyteam/schedule/docs/TeamCalendarScheduleApiDocsTest.java b/backend/src/test/java/team/teamby/teambyteam/schedule/docs/TeamCalendarScheduleApiDocsTest.java index d878a7001..34a80f279 100644 --- a/backend/src/test/java/team/teamby/teambyteam/schedule/docs/TeamCalendarScheduleApiDocsTest.java +++ b/backend/src/test/java/team/teamby/teambyteam/schedule/docs/TeamCalendarScheduleApiDocsTest.java @@ -15,11 +15,11 @@ import org.springframework.http.MediaType; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.web.servlet.MockMvc; -import team.teamby.teambyteam.fixtures.ScheduleFixtures; import team.teamby.teambyteam.member.configuration.MemberInterceptor; import team.teamby.teambyteam.schedule.application.TeamCalendarScheduleService; import team.teamby.teambyteam.schedule.application.dto.ScheduleRegisterRequest; import team.teamby.teambyteam.schedule.application.dto.ScheduleUpdateRequest; +import team.teamby.teambyteam.schedule.domain.Schedule; import team.teamby.teambyteam.schedule.exception.ScheduleException; import team.teamby.teambyteam.schedule.presentation.TeamCalendarScheduleController; import team.teamby.teambyteam.teamplace.configuration.TeamPlaceInterceptor; @@ -45,7 +45,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static team.teamby.teambyteam.fixtures.ScheduleFixtures.Schedule1_N_Hour; +import static team.teamby.teambyteam.common.fixtures.ScheduleFixtures.*; @AutoConfigureRestDocs @WebMvcTest(TeamCalendarScheduleController.class) @@ -91,8 +91,8 @@ class RegisterScheduleDocs { @DisplayName("일정 등록 성공") void success() throws Exception { // given - final ScheduleRegisterRequest request = Schedule1_N_Hour.REQUEST; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; + final Long teamPlaceId = 1L; + final ScheduleRegisterRequest request = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_REGISTER_REQUEST; final Long registeredId = 1L; given(teamCalendarScheduleService.register(request, teamPlaceId)) .willReturn(registeredId); @@ -127,9 +127,11 @@ void success() throws Exception { @DisplayName("제목이 빈 값이면 실패") void failBlankTitle() throws Exception { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; + final Long teamPlaceId = 1L; final String blankTitle = " "; - ScheduleUpdateRequest request = new ScheduleUpdateRequest(blankTitle, Schedule1_N_Hour.START_DATE_TIME, Schedule1_N_Hour.END_DATE_TIME); + LocalDateTime startDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(teamPlaceId).getSpan().getStartDateTime(); + LocalDateTime endDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(teamPlaceId).getSpan().getEndDateTime(); + ScheduleUpdateRequest request = new ScheduleUpdateRequest(blankTitle, startDateTime, endDateTime); willThrow(new ScheduleException.TitleBlankException()) .given(teamCalendarScheduleService) .register(any(ScheduleRegisterRequest.class), eq(teamPlaceId)); @@ -153,12 +155,12 @@ void failBlankTitle() throws Exception { @DisplayName("잘못된 날짜 형식이면 실패") void failWrongDateTimeType() throws Exception { // given - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; + final Long teamPlaceId = 1L; final String wrongStartDateTime = "2023:07:12 10:00"; final String correctEndDateTimeType = "2023-07-12 18:00"; final Map requestMap = new HashMap<>(); - requestMap.put(REQUEST_TITLE_KEY, Schedule1_N_Hour.TITLE); + requestMap.put(REQUEST_TITLE_KEY, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_TITLE); requestMap.put(REQUEST_START_DATE_TIME_KEY, wrongStartDateTime); requestMap.put(REQUEST_END_DATE_KEY, correctEndDateTimeType); @@ -186,7 +188,7 @@ void failWrongDateTimeType() throws Exception { void failNotExistTeamPlaceId() throws Exception { // given final Long notExistTeamPlaceId = -1L; - ScheduleRegisterRequest request = Schedule1_N_Hour.REQUEST; + final ScheduleRegisterRequest request = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_REGISTER_REQUEST; willThrow(new TeamPlaceException.NotFoundException()) .given(teamCalendarScheduleService) .register(any(), eq(notExistTeamPlaceId)); @@ -210,10 +212,10 @@ void failNotExistTeamPlaceId() throws Exception { @DisplayName("시작 일자와 종료 일자의 순서가 맞지 않으면 실패") void failSpanWrongOrder() throws Exception { // given - final String title = ScheduleFixtures.Schedule1_N_Hour.TITLE; - final Long teamPlaceId = ScheduleFixtures.Schedule1_N_Hour.TEAM_PLACE_ID; - final LocalDateTime startDateTime = ScheduleFixtures.Schedule1_N_Hour.START_DATE_TIME; - final LocalDateTime wrongEndDateTime = ScheduleFixtures.Schedule1_N_Hour.START_DATE_TIME.minusDays(1); + final String title = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_TITLE; + final Long teamPlaceId = 1L; + final LocalDateTime startDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(teamPlaceId).getSpan().getStartDateTime(); + final LocalDateTime wrongEndDateTime = startDateTime.minusDays(1); final ScheduleRegisterRequest request = new ScheduleRegisterRequest(title, startDateTime, wrongEndDateTime); willThrow(new ScheduleException.SpanWrongOrderException()) @@ -235,6 +237,7 @@ void failSpanWrongOrder() throws Exception { } } + @Nested @DisplayName("일정 수정 문서화") class UpdateScheduleDocs { @@ -243,9 +246,9 @@ class UpdateScheduleDocs { @DisplayName("일정 수정 성공") void success() throws Exception { // given - final ScheduleUpdateRequest request = Schedule1_N_Hour.UPDATE_REQUEST; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - final Long id = Schedule1_N_Hour.ID; + final ScheduleUpdateRequest request = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_UPDATE_REQUEST; + final Long teamPlaceId = 1L; + final Long id = 1L; willDoNothing().given(teamCalendarScheduleService).update(request, teamPlaceId, id); // when & then @@ -278,10 +281,14 @@ void success() throws Exception { @DisplayName("제목이 빈 값이면 실패") void failBlankTitle() throws Exception { // given - final Long id = Schedule1_N_Hour.ID; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; + final Long id = 1L; + final Long teamPlaceId = 1L; final String blankTitle = " "; - ScheduleUpdateRequest request = new ScheduleUpdateRequest(blankTitle, Schedule1_N_Hour.START_DATE_TIME, Schedule1_N_Hour.END_DATE_TIME); + final Schedule MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(teamPlaceId); + final LocalDateTime startDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getStartDateTime(); + final LocalDateTime endDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE.getSpan().getEndDateTime(); + + ScheduleUpdateRequest request = new ScheduleUpdateRequest(blankTitle, startDateTime, endDateTime); willThrow(new ScheduleException.TitleBlankException()) .given(teamCalendarScheduleService) .update(any(ScheduleUpdateRequest.class), eq(teamPlaceId), eq(id)); @@ -305,13 +312,13 @@ void failBlankTitle() throws Exception { @DisplayName("잘못된 날짜 형식이면 실패") void failWrongDateTimeType() throws Exception { // given - final Long id = Schedule1_N_Hour.ID; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; + final Long id = 1L; + final Long teamPlaceId = 1L; final String wrongStartDateTime = "2023:07:12 10:00"; final String correctEndDateTimeType = "2023-07-12 18:00"; final Map requestMap = new HashMap<>(); - requestMap.put(REQUEST_TITLE_KEY, Schedule1_N_Hour.TITLE); + requestMap.put(REQUEST_TITLE_KEY, MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_TITLE); requestMap.put(REQUEST_START_DATE_TIME_KEY, wrongStartDateTime); requestMap.put(REQUEST_END_DATE_KEY, correctEndDateTimeType); @@ -338,9 +345,9 @@ void failWrongDateTimeType() throws Exception { @DisplayName("없는 팀 플레이스 ID면 실패") void failNotExistTeamPlaceId() throws Exception { // given - final Long id = Schedule1_N_Hour.ID; + final Long id = 1L; final Long notExistTeamPlaceId = -1L; - ScheduleRegisterRequest request = Schedule1_N_Hour.REQUEST; + final ScheduleRegisterRequest request = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_REGISTER_REQUEST; willThrow(new TeamPlaceException.NotFoundException()) .given(teamCalendarScheduleService) .update(any(), eq(notExistTeamPlaceId), eq(id)); @@ -364,11 +371,11 @@ void failNotExistTeamPlaceId() throws Exception { @DisplayName("시작 일자와 종료 일자의 순서가 맞지 않으면 실패") void failSpanWrongOrder() throws Exception { // given - final Long id = Schedule1_N_Hour.ID; - final String title = ScheduleFixtures.Schedule1_N_Hour.TITLE; - final Long teamPlaceId = ScheduleFixtures.Schedule1_N_Hour.TEAM_PLACE_ID; - final LocalDateTime startDateTime = ScheduleFixtures.Schedule1_N_Hour.START_DATE_TIME; - final LocalDateTime wrongEndDateTime = ScheduleFixtures.Schedule1_N_Hour.START_DATE_TIME.minusDays(1); + final Long id = 1L; + final String title = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_TITLE; + final Long teamPlaceId = 1L; + final LocalDateTime startDateTime = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(teamPlaceId).getSpan().getStartDateTime(); + final LocalDateTime wrongEndDateTime = startDateTime.minusDays(1); final ScheduleUpdateRequest request = new ScheduleUpdateRequest(title, startDateTime, wrongEndDateTime); willThrow(new ScheduleException.SpanWrongOrderException()) @@ -394,8 +401,8 @@ void failSpanWrongOrder() throws Exception { void failNotExistScheduleId() throws Exception { // given final Long notExistScheduleId = -1L; - final Long teamPlaceId = Schedule1_N_Hour.TEAM_PLACE_ID; - ScheduleRegisterRequest request = Schedule1_N_Hour.REQUEST; + final Long teamPlaceId = 1L; + final ScheduleRegisterRequest request = MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE_REGISTER_REQUEST; willThrow(new ScheduleException.ScheduleNotFoundException()) .given(teamCalendarScheduleService) .update(any(), eq(teamPlaceId), eq(notExistScheduleId)); diff --git a/backend/src/test/java/team/teamby/teambyteam/schedule/domain/ScheduleRepositoryTest.java b/backend/src/test/java/team/teamby/teambyteam/schedule/domain/ScheduleRepositoryTest.java index 14556b1c1..4d76f84cf 100644 --- a/backend/src/test/java/team/teamby/teambyteam/schedule/domain/ScheduleRepositoryTest.java +++ b/backend/src/test/java/team/teamby/teambyteam/schedule/domain/ScheduleRepositoryTest.java @@ -1,19 +1,21 @@ package team.teamby.teambyteam.schedule.domain; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import team.teamby.teambyteam.common.RepositoryTest; -import team.teamby.teambyteam.fixtures.ScheduleFixtures; -import team.teamby.teambyteam.schedule.domain.vo.Title; +import team.teamby.teambyteam.teamplace.domain.TeamPlace; import java.time.LocalDateTime; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static team.teamby.teambyteam.common.fixtures.ScheduleFixtures.*; +import static team.teamby.teambyteam.common.fixtures.TeamPlaceFixtures.ENGLISH_TEAM_PLACE; +import static team.teamby.teambyteam.common.fixtures.TeamPlaceFixtures.JAPANESE_TEAM_PLACE; public class ScheduleRepositoryTest extends RepositoryTest { @@ -24,68 +26,78 @@ public class ScheduleRepositoryTest extends RepositoryTest { @DisplayName("특정 기간 내 팀플레이스 일정을 조회한다.") void findTeamPlaceScheduleInRange() { // given - final Long teamPlaceId = 3L; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final List schedulesToSave = List.of(MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE(ENGLISH_TEAM_PLACE_ID), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + final List expectedSchedule = testFixtureBuilder.buildSchedules(schedulesToSave); + final LocalDateTime firstDateTime = LocalDateTime.of(2023, 7, 1, 0, 0); final LocalDateTime endDateTime = LocalDateTime.of(2023, 8, 1, 0, 0); // when - final List schedules = scheduleRepository.findAllByTeamPlaceIdAndPeriod(teamPlaceId, firstDateTime, endDateTime); + final List actualSchedules = scheduleRepository.findAllByTeamPlaceIdAndPeriod(ENGLISH_TEAM_PLACE_ID, firstDateTime, endDateTime); //then - assertSoftly(softly -> { - softly.assertThat(schedules).hasSize(4); - softly.assertThat(schedules.get(0).getTitle().getValue()).isEqualTo("3번 팀플 B"); - softly.assertThat(schedules.get(1).getTitle().getValue()).isEqualTo("3번 팀플 C"); - softly.assertThat(schedules.get(2).getTitle().getValue()).isEqualTo("3번 팀플 E"); - softly.assertThat(schedules.get(3).getTitle().getValue()).isEqualTo("3번 팀플 D"); - }); + Assertions.assertThat(actualSchedules).usingRecursiveFieldByFieldElementComparator() + .isEqualTo(expectedSchedule); } @Test @DisplayName("특정 기간 내 팀플레이스 일정을 조회한다.") void findMultipleTeamPlaceScheduleInRange() { // given - final List teamPlaceId = List.of(2L, 3L); - final LocalDateTime firstDateTime = LocalDateTime.of(2023, 6, 1, 0, 0); - final LocalDateTime endDateTime = LocalDateTime.of(2023, 7, 1, 0, 0); + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final TeamPlace JAPANESE_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(JAPANESE_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final Long JAPANESE_TEAM_PLACE_ID = JAPANESE_TEAM_PLACE.getId(); + + List schedulesToSave = List.of( + MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE(ENGLISH_TEAM_PLACE_ID), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID), + MONTH_7_DAY_28_AND_MONTH_8_SCHEDULE(JAPANESE_TEAM_PLACE_ID), MONTH_7_DAY_29_AND_MONTH_8_SCHEDULE(JAPANESE_TEAM_PLACE_ID) + ); + List expectedSchedules = testFixtureBuilder.buildSchedules(schedulesToSave); + + final List teamPlaceId = List.of(ENGLISH_TEAM_PLACE_ID, JAPANESE_TEAM_PLACE_ID); + final LocalDateTime firstDateTime = LocalDateTime.of(2023, 7, 1, 0, 0); + final LocalDateTime endDateTime = LocalDateTime.of(2023, 8, 1, 0, 0); // when - final List schedules = scheduleRepository.findAllByTeamPlaceIdAndPeriod(teamPlaceId, firstDateTime, endDateTime); + final List actualSchedules = scheduleRepository.findAllByTeamPlaceIdAndPeriod(teamPlaceId, firstDateTime, endDateTime); //then - assertSoftly(softly -> { - softly.assertThat(schedules).hasSize(5); - softly.assertThat(schedules.get(0).getTitle().getValue()).isEqualTo("3번 팀플 6월 첫날"); - softly.assertThat(schedules.get(1).getTitle().getValue()).isEqualTo("2번 팀플 6월 첫날"); - softly.assertThat(schedules.get(2).getTitle().getValue()).isEqualTo("3번 팀플 A"); - softly.assertThat(schedules.get(3).getTitle().getValue()).isEqualTo("2번 팀플 6월 어느날"); - softly.assertThat(schedules.get(4).getTitle().getValue()).isEqualTo("3번 팀플 B"); - }); + assertThat(actualSchedules).usingRecursiveFieldByFieldElementComparator() + .isEqualTo(expectedSchedules); } @Test @DisplayName("팀 캘린더 하루 일정을 조회한다.") void findDailyTeamCalendarSchedule() { // given - final Long teamPlaceId = ScheduleFixtures.Schedule1_N_Hour.TEAM_PLACE_ID; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + final List schedulesToSave = List.of(MONTH_7_AND_DAY_12_ALL_DAY_SCHEDULE(ENGLISH_TEAM_PLACE_ID), MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + final List expectedSchedule = testFixtureBuilder.buildSchedules(schedulesToSave); + final LocalDateTime startDateTime = LocalDateTime.of(2023, 7, 12, 0, 0, 0); final LocalDateTime endDateTime = LocalDateTime.of(2023, 7, 12, 23, 59, 59); // when - final List schedules = scheduleRepository.findAllByTeamPlaceIdAndDailyPeriod(teamPlaceId, startDateTime, endDateTime); + final List actualSchedules = scheduleRepository.findAllByTeamPlaceIdAndDailyPeriod(ENGLISH_TEAM_PLACE_ID, startDateTime, endDateTime); // then - assertSoftly(softly -> { - softly.assertThat(schedules).hasSize(2); - softly.assertThat(schedules.stream().map(Schedule::getTitle).map(Title::getValue)) - .containsExactly("1번 팀플 종일 일정", "1번 팀플 N시간 일정"); - }); + Assertions.assertThat(actualSchedules).usingRecursiveFieldByFieldElementComparator() + .isEqualTo(expectedSchedule); } @ParameterizedTest @CsvSource(value = {"-1:false", "1:true"}, delimiter = ':') @DisplayName("일정이 존재하면 true, 존재하지 않으면 false를 반환한다.") void isExistById(Long scheduleId, boolean expected) { + // given + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); + // when final boolean actual = scheduleRepository.existsById(scheduleId); @@ -97,12 +109,14 @@ void isExistById(Long scheduleId, boolean expected) { @DisplayName("일정이 있는 경우에 삭제가 되는지 확인한다.") void deleteById() { //given - final long id = 1L; + final TeamPlace ENGLISH_TEAM_PLACE = testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + final Long ENGLISH_TEAM_PLACE_ID = ENGLISH_TEAM_PLACE.getId(); + testFixtureBuilder.buildSchedule(MONTH_7_AND_DAY_12_N_HOUR_SCHEDULE(ENGLISH_TEAM_PLACE_ID)); // when - final boolean before = scheduleRepository.existsById(id); - scheduleRepository.deleteById(id); - final boolean after = scheduleRepository.existsById(id); + final boolean before = scheduleRepository.existsById(ENGLISH_TEAM_PLACE_ID); + scheduleRepository.deleteById(ENGLISH_TEAM_PLACE_ID); + final boolean after = scheduleRepository.existsById(ENGLISH_TEAM_PLACE_ID); // then assertThat(before).isTrue(); diff --git a/backend/src/test/java/team/teamby/teambyteam/teamplace/domain/TeamPlaceRepositoryTest.java b/backend/src/test/java/team/teamby/teambyteam/teamplace/domain/TeamPlaceRepositoryTest.java index 469f157b7..f716a289a 100644 --- a/backend/src/test/java/team/teamby/teambyteam/teamplace/domain/TeamPlaceRepositoryTest.java +++ b/backend/src/test/java/team/teamby/teambyteam/teamplace/domain/TeamPlaceRepositoryTest.java @@ -7,6 +7,7 @@ import team.teamby.teambyteam.common.RepositoryTest; import static org.assertj.core.api.Assertions.assertThat; +import static team.teamby.teambyteam.common.fixtures.TeamPlaceFixtures.ENGLISH_TEAM_PLACE; class TeamPlaceRepositoryTest extends RepositoryTest { @@ -17,6 +18,9 @@ class TeamPlaceRepositoryTest extends RepositoryTest { @CsvSource(value = {"-1:false", "1:true"}, delimiter = ':') @DisplayName("id에 해당하는 팀 플레이스가 존재하면 true, 존재하지 않으면 false를 반환한다.") void isExistById(Long teamPlaceId, boolean expected) { + // given + testFixtureBuilder.buildTeamPlace(ENGLISH_TEAM_PLACE()); + // when final boolean actual = teamPlaceRepository.existsById(teamPlaceId); diff --git a/backend/src/test/resources/h2-data.sql b/backend/src/test/resources/h2-data.sql deleted file mode 100644 index 230552db9..000000000 --- a/backend/src/test/resources/h2-data.sql +++ /dev/null @@ -1,60 +0,0 @@ -INSERT INTO member (name, email, profile_image_url, created_at, updated_at) VALUES ('james', 'abcd@gmail.com', './test.jpg', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member (name, email, profile_image_url, created_at, updated_at) VALUES ('andy', 'aaa23213@gmail.com', './test.jpg', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member (name, email, profile_image_url, created_at, updated_at) VALUES ('philip', 'sdf3244@gmail.com', './test.jpg', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member (name, email, profile_image_url, created_at, updated_at) VALUES ('seongha', 'safd234@gmail.com', './test.jpg', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member (name, email, profile_image_url, created_at, updated_at) VALUES ('rulu', 'dfg345@gmail.com', './test.jpg', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member (name, email, profile_image_url, created_at, updated_at) VALUES ('tomas', 'htr35@gmail.com', './test.jpg', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member (name, email, profile_image_url, created_at, updated_at) VALUES ('youth', 'sag345@gmail.com', './test.jpg', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); - -INSERT INTO team_place (name, created_at, updated_at) VALUES ('대한 팀플', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO team_place (name, created_at, updated_at) VALUES ('동서 문명의 교류 팀플', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO team_place (name, created_at, updated_at) VALUES ('건축공학설계 팀플', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO team_place (name, created_at, updated_at) VALUES ('유체역학 팀플', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); - -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (1, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (2, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (3, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (3, 2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (4, 2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (5, 2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (6, 2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (1, 3, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (2, 3, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (3, 3, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (5, 3, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (7, 3, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO member_team_place (member_id, team_place_id, created_at, updated_at) VALUES (7, 4, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); - --- 테스트 케이스 --- 1. 당일 N 시간 --- 2. 하루 종일 --- 3. N일 --- 4. 현재보다 과거의 일정 --- 5. 현재보다 미래의 일정 --- 서로 다른 팀플레이스 - -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('1번 팀플 N시간 일정', 1, '2023-07-12 10:00:00' ,'2023-07-12 18:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('1번 팀플 종일 일정', 1, '2023-07-12 00:00:00' ,'2023-07-12 23:59:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('1번 팀플 N일 일정', 1, '2023-07-12 10:00:00' ,'2023-07-15 12:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('1번 팀플 과거 일정', 1, TIMESTAMPADD(DAY, -2, CURRENT_TIMESTAMP()), TIMESTAMPADD(DAY, -1, CURRENT_TIMESTAMP()), CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('1번 팀플 미래 일정', 1, TIMESTAMPADD(DAY, 3, CURRENT_TIMESTAMP()), TIMESTAMPADD(DAY, 5, CURRENT_TIMESTAMP()), CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('2번 팀플 N시간 일정', 2, '2023-07-12 20:00:00' ,'2023-07-12 21:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('2번 팀플 종일 일정', 2, '2023-07-13 00:00:00' ,'2023-07-13 23:59:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('2번 팀플 N일 일정', 2, '2023-07-14 10:00:00' ,'2023-07-17 12:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('2번 팀플 과거 일정', 2, TIMESTAMPADD(DAY, -2, CURRENT_TIMESTAMP()), TIMESTAMPADD(DAY, -1, CURRENT_TIMESTAMP()), CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('2번 팀플 미래 일정', 2, TIMESTAMPADD(DAY, 3, CURRENT_TIMESTAMP()), TIMESTAMPADD(DAY, 5, CURRENT_TIMESTAMP()), CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('2번 팀플 6월 첫날', 2, '2023-06-01 10:00:00' ,'2023-06-01 20:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('2번 팀플 6월 어느날', 2, '2023-06-24 10:00:00' ,'2023-06-26 12:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); - -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('3번 팀플 A', 3, '2023-06-14 10:00:00' ,'2023-06-17 12:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('3번 팀플 B', 3, '2023-06-25 10:00:00' ,'2023-07-02 12:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('3번 팀플 C', 3, '2023-07-01 10:00:00' ,'2023-07-01 12:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('3번 팀플 D', 3, '2023-07-29 10:00:00' ,'2023-08-30 12:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('3번 팀플 E', 3, '2023-07-28 10:00:00' ,'2023-08-30 12:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('3번 팀플 F', 3, '2023-08-14 10:00:00' ,'2023-08-17 12:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('3번 팀플 5월 첫날', 3, '2023-05-01 00:00:00' ,'2023-05-01 12:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('3번 팀플 5월 마지막날', 3, '2023-05-31 00:00:00' ,'2023-05-31 23:59:59', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('3번 팀플 6월 첫날', 3, '2023-06-01 00:00:00' ,'2023-06-01 12:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); - -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('1번 팀플 6월 일정', 1, '2023-06-12 10:00:00' ,'2023-06-12 18:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); -INSERT INTO schedule (title, team_place_id, start_date_time, end_date_time, created_at, updated_at) VALUES ('1번 팀플 장기 일정', 1, '2023-06-22 10:00:00' ,'2023-08-12 18:00:00', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); diff --git a/backend/src/test/resources/h2-reset-pk.sql b/backend/src/test/resources/h2-reset-pk.sql deleted file mode 100644 index 71a189fce..000000000 --- a/backend/src/test/resources/h2-reset-pk.sql +++ /dev/null @@ -1,5 +0,0 @@ --- reset PK of the table before input test data -ALTER TABLE member_team_place ALTER COLUMN id RESTART WITH 1; -ALTER TABLE member ALTER COLUMN id RESTART WITH 1; -ALTER TABLE team_place ALTER COLUMN id RESTART WITH 1; -ALTER TABLE schedule ALTER COLUMN id RESTART WITH 1;