diff --git a/src/main/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepository.java b/src/main/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepository.java index 7347cefe..e5da6449 100644 --- a/src/main/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepository.java +++ b/src/main/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepository.java @@ -4,6 +4,7 @@ import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -36,6 +37,8 @@ SELECT COUNT(cm) """) List findAllByCrewId(@Param(value = "crewId") Long crewId); - void deleteByUserIdAndCrewId(@Param(value = "userId") Long userId, @Param(value = "crewId") Long crewId); + @Modifying + @Query(value = "DELETE FROM crew_member cm WHERE user_id = :userId AND crew_id = :crewId", nativeQuery = true) + int deleteByUserIdAndCrewId(@Param(value = "userId") Long userId, @Param(value = "crewId") Long crewId); } diff --git a/src/test/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepositoryTest.java b/src/test/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepositoryTest.java index 518dcc8f..50c940af 100644 --- a/src/test/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepositoryTest.java +++ b/src/test/java/com/prgrms/mukvengers/domain/crewmember/repository/CrewMemberRepositoryTest.java @@ -94,11 +94,10 @@ void deleteByUserId_success() { crewMemberRepository.save(crewMember); //when - crewMemberRepository.deleteByUserIdAndCrewId(savedUser1Id, crew.getId()); + int delete = crewMemberRepository.deleteByUserIdAndCrewId(savedUser1Id, crew.getId()); //then - Optional optionalCrewMember = crewMemberRepository.findById(crewMember.getId()); - assertThat(optionalCrewMember).isEmpty(); + assertThat(delete).isEqualTo(1); } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/mukvengers/domain/crewmember/service/CrewMemberServiceImplTest.java b/src/test/java/com/prgrms/mukvengers/domain/crewmember/service/CrewMemberServiceImplTest.java index 1d8463f6..cac47dc7 100644 --- a/src/test/java/com/prgrms/mukvengers/domain/crewmember/service/CrewMemberServiceImplTest.java +++ b/src/test/java/com/prgrms/mukvengers/domain/crewmember/service/CrewMemberServiceImplTest.java @@ -18,7 +18,6 @@ import com.prgrms.mukvengers.domain.crewmember.model.CrewMember; import com.prgrms.mukvengers.domain.crewmember.repository.CrewMemberRepository; import com.prgrms.mukvengers.global.common.dto.IdResponse; -import com.prgrms.mukvengers.utils.CrewMemberObjectProvider; class CrewMemberServiceImplTest extends ServiceTest { @@ -51,7 +50,7 @@ void create_success() { .hasFieldOrPropertyWithValue("crew", crew) .hasFieldOrPropertyWithValue("crewMemberRole", LEADER); } - + @Test @DisplayName("[성공] 사용자 아이디, 강퇴할 사용자 아이디, 모임 아이디로 사용자를 강퇴한다.") void block_success() { @@ -60,7 +59,7 @@ void block_success() { Crew crew = createCrew(savedStore); crewRepository.save(crew); - CrewMember leader = createCrewMember(savedUser1Id, crew, LEADER); + CrewMember leader = createCrewMember(savedUser1Id, crew, LEADER); CrewMember member = createCrewMember(savedUser2Id, crew, MEMBER); crewMemberRepository.save(leader); @@ -109,24 +108,6 @@ void block_fail_NotMember() { assertThatThrownBy( () -> crewMemberService.block(leader.getUserId(), leader.getUserId(), crew.getId())).isInstanceOf( NotMemberException.class); - } - - @Test - @DisplayName("[성공] 모임원 아이디로 모임원을 삭제한다") - void delete_success() { - - //given - Crew crew = createCrew(savedStore); - crewRepository.save(crew); - - CrewMember crewMember = CrewMemberObjectProvider.createCrewMember(savedUser1Id, crew, MEMBER); - crewMemberRepository.save(crewMember); - - //when - crewMemberService.delete(crewMember.getUserId(), crew.getId()); - - //then - Optional optionalCrewMember = crewMemberRepository.findById(crewMember.getId()); - assertThat(optionalCrewMember).isEmpty(); } + } \ No newline at end of file