diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepository.java index a2c804ff..f752ffe1 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepository.java @@ -8,6 +8,6 @@ public interface MajorLectureRepository extends JpaRepository { - @Query("select m from MajorLectureJpaEntity m join fetch m.lectureJpaEntity where m.major = :major") + @Query("select m from MajorLectureJpaEntity m join fetch m.lectureJpaEntity where m.major = :major or m.major = '실습'") List findAllByMajor(@Param("major") String major); } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepositoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepositoryTest.java index 67a08d3c..b8a3db7e 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepositoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepositoryTest.java @@ -12,40 +12,44 @@ class MajorLectureRepositoryTest extends PersistenceTestSupport { - @Autowired - private LectureRepository lectureRepository; - @Autowired - private MajorLectureRepository majorLectureRepository; - - - @DisplayName("유저의 전공에 해당하는 전공 과목을 조회한다.") - @Test - void findAllByMajor() { - //given - LectureJpaEntity lectureJpaEntity = LectureJpaEntity.builder() - .id("TEST") - .build(); - lectureRepository.save(lectureJpaEntity); - - MajorLectureJpaEntity majorLectureJpaEntityA = MajorLectureJpaEntity.builder() - .lectureJpaEntity(lectureJpaEntity) - .major("응용소프트웨어") - .build(); - MajorLectureJpaEntity majorLectureJpaEntityB = MajorLectureJpaEntity.builder() - .lectureJpaEntity(lectureJpaEntity) - .major("데이터테크놀로지") - .build(); - majorLectureRepository.saveAll(List.of(majorLectureJpaEntityA, majorLectureJpaEntityB)); - - String major = "응용소프트웨어"; - - //when - List majorLectures = majorLectureRepository.findAllByMajor(major); - - //then - assertThat(majorLectures).hasSize(1) - .extracting("major") - .contains(major); - } + @Autowired + private LectureRepository lectureRepository; + @Autowired + private MajorLectureRepository majorLectureRepository; + + + @DisplayName("유저의 전공에 해당하는 전공 과목을 조회한다.") + @Test + void findAllByMajor() { + //given + LectureJpaEntity lectureJpaEntity = LectureJpaEntity.builder() + .id("TEST") + .build(); + lectureRepository.save(lectureJpaEntity); + + MajorLectureJpaEntity majorLectureJpaEntityA = MajorLectureJpaEntity.builder() + .lectureJpaEntity(lectureJpaEntity) + .major("응용소프트웨어") + .build(); + MajorLectureJpaEntity majorLectureJpaEntityB = MajorLectureJpaEntity.builder() + .lectureJpaEntity(lectureJpaEntity) + .major("데이터테크놀로지") + .build(); + MajorLectureJpaEntity majorLectureJpaEntityC = MajorLectureJpaEntity.builder() + .lectureJpaEntity(lectureJpaEntity) + .major("실습") + .build(); + majorLectureRepository.saveAll(List.of(majorLectureJpaEntityA, majorLectureJpaEntityB, majorLectureJpaEntityC)); + + String major = "응용소프트웨어"; + + //when + List majorLectures = majorLectureRepository.findAllByMajor(major); + + //then + assertThat(majorLectures).hasSize(2) + .extracting("major") + .containsExactlyInAnyOrder(major, "실습"); + } }