diff --git a/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/TakeAllTimetableLectureResponse.java b/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/TakeAllTimetableLectureResponse.java index 98ad0574c0..412d84a01c 100644 --- a/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/TakeAllTimetableLectureResponse.java +++ b/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/TakeAllTimetableLectureResponse.java @@ -110,7 +110,8 @@ public static List from(List lecture.getName(), lecture.getLectureClass(), lecture.getTarget(), - firstNonNull(timetableLecture.getProfessor(),lecture.getProfessor()), + timetableLecture.getProfessor() != null + ? timetableLecture.getProfessor() : lecture.getProfessor(), lecture.getDepartment(), getCourseType(timetableLecture), getGeneralEducationArea(timetableLecture) diff --git a/src/test/java/in/koreatech/koin/acceptance/domain/TimetableLectureV3ApiTest.java b/src/test/java/in/koreatech/koin/acceptance/domain/TimetableLectureV3ApiTest.java index 993636b8af..85a1945046 100644 --- a/src/test/java/in/koreatech/koin/acceptance/domain/TimetableLectureV3ApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/domain/TimetableLectureV3ApiTest.java @@ -1,7 +1,9 @@ package in.koreatech.koin.acceptance.domain; +import static org.hamcrest.Matchers.nullValue; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.util.List; @@ -119,6 +121,27 @@ void setup() { """)); } + @Test + void 교수가_미정인_정규강의를_생성한다() throws Exception { + timetableV2Fixture.시간표1(user, semester); + lectureFixture.교수_미정_강의(semester.getSemester()); + + mockMvc.perform( + post("/v3/timetables/lecture/regular") + .header("Authorization", "Bearer " + token) + .content(""" + { + "timetable_frame_id": 1, + "lecture_id": 1 + } + """) + .contentType(MediaType.APPLICATION_JSON) + ) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.timetable[0].class_title").value("교수 미정 강의")) + .andExpect(jsonPath("$.timetable[0].professor").value(nullValue())); + } + @Test void 커스텀강의를_생성한다() throws Exception { timetableV2Fixture.시간표1(user, semester); diff --git a/src/test/java/in/koreatech/koin/acceptance/fixture/LectureAcceptanceFixture.java b/src/test/java/in/koreatech/koin/acceptance/fixture/LectureAcceptanceFixture.java index 5ebcf1b7be..39e124b2e7 100644 --- a/src/test/java/in/koreatech/koin/acceptance/fixture/LectureAcceptanceFixture.java +++ b/src/test/java/in/koreatech/koin/acceptance/fixture/LectureAcceptanceFixture.java @@ -75,6 +75,26 @@ public LectureAcceptanceFixture(LectureRepository lectureRepository) { ); } + public Lecture 교수_미정_강의(String semester) { + return lectureRepository.save( + Lecture.builder() + .code("MEB312") + .semester(semester) + .name("교수 미정 강의") + .grades("3") + .lectureClass("01") + .regularNumber("30") + .department("기계공학부") + .target("기공전체") + .professor(null) + .isEnglish("") + .designScore("0") + .isElearning("") + .classTime("[100, 101, 102, 103]") + .build() + ); + } + public Lecture 영어청해(String semester) { return lectureRepository.save( Lecture.builder() diff --git a/src/test/java/in/koreatech/koin/unit/domain/timetableV3/dto/response/TimetableLectureProfessorResponseTest.java b/src/test/java/in/koreatech/koin/unit/domain/timetableV3/dto/response/TimetableLectureProfessorResponseTest.java new file mode 100644 index 0000000000..551ed5b564 --- /dev/null +++ b/src/test/java/in/koreatech/koin/unit/domain/timetableV3/dto/response/TimetableLectureProfessorResponseTest.java @@ -0,0 +1,94 @@ +package in.koreatech.koin.unit.domain.timetableV3.dto.response; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +import org.junit.jupiter.api.Test; + +import in.koreatech.koin.domain.timetable.model.Lecture; +import in.koreatech.koin.domain.timetableV2.model.TimetableLecture; +import in.koreatech.koin.domain.timetableV3.dto.response.TakeAllTimetableLectureResponse; +import in.koreatech.koin.domain.timetableV3.dto.response.TimetableLectureResponseV3; + +@SuppressWarnings("NonAsciiCharacters") +class TimetableLectureProfessorResponseTest { + + @Test + void 강의와_시간표_강의의_교수가_모두_없어도_교수는_null로_응답한다() { + TimetableLecture timetableLecture = timetableLecture(lecture(null), null); + + var response = TimetableLectureResponseV3.InnerTimetableLectureResponseV3 + .from(List.of(timetableLecture)); + + assertThat(response).hasSize(1); + assertThat(response.get(0).professor()).isNull(); + } + + @Test + void 시간표_강의의_교수가_없으면_강의의_교수로_응답한다() { + TimetableLecture timetableLecture = timetableLecture(lecture("허준기"), null); + + var response = TimetableLectureResponseV3.InnerTimetableLectureResponseV3 + .from(List.of(timetableLecture)); + + assertThat(response.get(0).professor()).isEqualTo("허준기"); + } + + @Test + void 시간표_강의에_교수가_있으면_강의의_교수보다_우선한다() { + TimetableLecture timetableLecture = timetableLecture(lecture("허준기"), "수정된 교수"); + + var response = TimetableLectureResponseV3.InnerTimetableLectureResponseV3 + .from(List.of(timetableLecture)); + + assertThat(response.get(0).professor()).isEqualTo("수정된 교수"); + } + + @Test + void 이수한_전체_수업_응답도_교수가_모두_없으면_null로_응답한다() { + TimetableLecture timetableLecture = timetableLecture(lecture(null), null); + + var response = TakeAllTimetableLectureResponse.InnerTimetableLectureResponseV3 + .from(List.of(timetableLecture)); + + assertThat(response).hasSize(1); + assertThat(response.get(0).professor()).isNull(); + } + + @Test + void 이수한_전체_수업_응답은_시간표_강의의_교수가_없으면_강의의_교수로_응답한다() { + TimetableLecture timetableLecture = timetableLecture(lecture("허준기"), null); + + var response = TakeAllTimetableLectureResponse.InnerTimetableLectureResponseV3 + .from(List.of(timetableLecture)); + + assertThat(response.get(0).professor()).isEqualTo("허준기"); + } + + private Lecture lecture(String professor) { + return Lecture.builder() + .code("MEB311") + .semester("20192") + .name("재료역학") + .grades("3") + .lectureClass("01") + .regularNumber("35") + .department("기계공학부") + .target("기공전체") + .professor(professor) + .isEnglish("") + .designScore("0") + .isElearning("") + .classTime("[100, 101, 102, 103, 308, 309]") + .build(); + } + + private TimetableLecture timetableLecture(Lecture lecture, String professor) { + return TimetableLecture.builder() + .lecture(lecture) + .grades("0") + .professor(professor) + .build(); + } +}