diff --git a/backend/src/main/java/hanglog/listener/DeleteEventListener.java b/backend/src/main/java/hanglog/listener/DeleteEventListener.java index 2566e8755..74fb311a3 100644 --- a/backend/src/main/java/hanglog/listener/DeleteEventListener.java +++ b/backend/src/main/java/hanglog/listener/DeleteEventListener.java @@ -50,7 +50,6 @@ public void deleteMember(final MemberDeleteEvent event) { dayLogRepository.deleteByIds(dayLogIds); tripRepository.deleteByMemberId(event.getMemberId()); - refreshTokenRepository.deleteByMemberId(event.getMemberId()); } @Async diff --git a/backend/src/main/java/hanglog/login/domain/RefreshToken.java b/backend/src/main/java/hanglog/login/domain/RefreshToken.java index 9bad8c43f..c0bdc246e 100644 --- a/backend/src/main/java/hanglog/login/domain/RefreshToken.java +++ b/backend/src/main/java/hanglog/login/domain/RefreshToken.java @@ -1,26 +1,17 @@ package hanglog.login.domain; -import static lombok.AccessLevel.PROTECTED; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; -@Entity @Getter -@NoArgsConstructor(access = PROTECTED) +@AllArgsConstructor +@RedisHash(value = "refreshToken", timeToLive = 604800) public class RefreshToken { @Id private String token; - @Column(nullable = false) private Long memberId; - - public RefreshToken(final String token, final Long memberId) { - this.token = token; - this.memberId = memberId; - } } diff --git a/backend/src/main/java/hanglog/login/domain/repository/RefreshTokenRepository.java b/backend/src/main/java/hanglog/login/domain/repository/RefreshTokenRepository.java index db6d72b81..4c278cc1d 100644 --- a/backend/src/main/java/hanglog/login/domain/repository/RefreshTokenRepository.java +++ b/backend/src/main/java/hanglog/login/domain/repository/RefreshTokenRepository.java @@ -3,13 +3,10 @@ import hanglog.login.domain.RefreshToken; import java.util.Optional; import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.query.Param; public interface RefreshTokenRepository extends CrudRepository { Optional findByToken(final String token); boolean existsByToken(final String token); - - void deleteByMemberId(@Param("memberId") final Long memberId); } diff --git a/backend/src/test/java/hanglog/integration/service/LoginServiceIntegrationTest.java b/backend/src/test/java/hanglog/integration/service/LoginServiceIntegrationTest.java index d2a773bea..ba39d4155 100644 --- a/backend/src/test/java/hanglog/integration/service/LoginServiceIntegrationTest.java +++ b/backend/src/test/java/hanglog/integration/service/LoginServiceIntegrationTest.java @@ -1,66 +1,40 @@ package hanglog.integration.service; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import hanglog.community.domain.repository.PublishedTripRepository; -import hanglog.login.domain.OauthProviders; -import hanglog.login.domain.repository.RefreshTokenRepository; -import hanglog.login.infrastructure.BearerAuthorizationExtractor; -import hanglog.login.infrastructure.JwtProvider; import hanglog.login.service.LoginService; +import hanglog.member.domain.Member; import hanglog.member.domain.repository.MemberRepository; -import hanglog.trip.domain.repository.SharedTripRepository; -import hanglog.trip.domain.repository.TripRepository; -import hanglog.trip.infrastructure.CustomTripRepositoryImpl; -import jakarta.persistence.EntityManager; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.annotation.Import; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; -@Import({ - LoginService.class, - OauthProviders.class, - JwtProvider.class, - BearerAuthorizationExtractor.class, - CustomTripRepositoryImpl.class -}) -class LoginServiceIntegrationTest extends ServiceIntegrationTest { +@SpringBootTest +@Sql(value = {"classpath:data/truncate.sql"}) +class LoginServiceIntegrationTest { - @Autowired - private OauthProviders oauthProviders; - @Autowired - private RefreshTokenRepository refreshTokenRepository; - @Autowired - private TripRepository tripRepository; - @Autowired - private JwtProvider jwtProvider; - @Autowired - private BearerAuthorizationExtractor bearerExtractor; @Autowired private LoginService loginService; @Autowired - private PublishedTripRepository publishedTripRepository; - @Autowired private MemberRepository memberRepository; - @Autowired - private SharedTripRepository sharedTripRepository; - @Autowired - private ApplicationEventPublisher publisher; - @Autowired - private EntityManager entityManager; @DisplayName("멤버를 삭제한다.") @Test void deleteAccount() { - // when & then + // given + final Member member = memberRepository.save(new Member( + "socialLoginId", + "name", + "https://hanglog.com/img/imageName.png" + )); assertThat(memberRepository.findById(member.getId())).isPresent(); - assertDoesNotThrow(() -> loginService.deleteAccount(member.getId())); - entityManager.flush(); - entityManager.clear(); + // when + loginService.deleteAccount(member.getId()); + + // then assertThat(memberRepository.findById(member.getId())).isEmpty(); } } diff --git a/backend/src/test/java/hanglog/member/event/DeleteEventListenerTest.java b/backend/src/test/java/hanglog/member/event/DeleteEventListenerTest.java index c2ad68496..d26f2a1b7 100644 --- a/backend/src/test/java/hanglog/member/event/DeleteEventListenerTest.java +++ b/backend/src/test/java/hanglog/member/event/DeleteEventListenerTest.java @@ -69,7 +69,6 @@ void deleteMember() { doNothing().when(itemRepository).deleteByIds(anyList()); doNothing().when(dayLogRepository).deleteByIds(anyList()); doNothing().when(tripRepository).deleteByMemberId(anyLong()); - doNothing().when(refreshTokenRepository).deleteByMemberId(anyLong()); // when listener.deleteMember(event); @@ -83,7 +82,6 @@ void deleteMember() { verify(itemRepository, times(1)).deleteByIds(anyList()); verify(dayLogRepository, times(1)).deleteByIds(anyList()); verify(tripRepository, times(1)).deleteByMemberId(anyLong()); - verify(refreshTokenRepository, times(1)).deleteByMemberId(anyLong()); } @DisplayName("deleteTrip 메서드에서 올바르게 레포지토리의 메서드를 호출한다.") diff --git a/backend/src/test/resources/data/truncate.sql b/backend/src/test/resources/data/truncate.sql index ac8d9ec66..c7fe2de16 100644 --- a/backend/src/test/resources/data/truncate.sql +++ b/backend/src/test/resources/data/truncate.sql @@ -10,5 +10,4 @@ TRUNCATE TABLE currency RESTART IDENTITY; TRUNCATE TABLE city RESTART IDENTITY; TRUNCATE TABLE category RESTART IDENTITY; TRUNCATE TABLE member RESTART IDENTITY; -TRUNCATE TABLE refresh_token RESTART IDENTITY; SET referential_integrity TRUE;