diff --git a/backend/src/main/java/com/twtw/backend/config/rabbitmq/RabbitMQConfig.java b/backend/src/main/java/com/twtw/backend/config/rabbitmq/RabbitMQConfig.java index 5eff0f38..07e3b5be 100644 --- a/backend/src/main/java/com/twtw/backend/config/rabbitmq/RabbitMQConfig.java +++ b/backend/src/main/java/com/twtw/backend/config/rabbitmq/RabbitMQConfig.java @@ -18,7 +18,9 @@ import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +@Profile("!test") @EnableRabbit @Configuration @RequiredArgsConstructor diff --git a/backend/src/test/java/com/twtw/backend/domain/friend/repository/FriendRepositoryTest.java b/backend/src/test/java/com/twtw/backend/domain/friend/repository/FriendRepositoryTest.java index 6ff545d2..8e2dac00 100644 --- a/backend/src/test/java/com/twtw/backend/domain/friend/repository/FriendRepositoryTest.java +++ b/backend/src/test/java/com/twtw/backend/domain/friend/repository/FriendRepositoryTest.java @@ -1,7 +1,5 @@ package com.twtw.backend.domain.friend.repository; -import static org.assertj.core.api.Assertions.assertThat; - import com.twtw.backend.domain.friend.entity.Friend; import com.twtw.backend.domain.friend.entity.FriendStatus; import com.twtw.backend.domain.member.entity.AuthType; @@ -9,7 +7,6 @@ import com.twtw.backend.domain.member.entity.OAuth2Info; import com.twtw.backend.domain.member.repository.MemberRepository; import com.twtw.backend.support.repository.RepositoryTest; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -17,6 +14,8 @@ import java.util.List; import java.util.UUID; +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("FriendRepository에") class FriendRepositoryTest extends RepositoryTest { @@ -29,10 +28,10 @@ void save() { // given final Member from = memberRepository.save( - new Member("1", "123", new OAuth2Info("321", AuthType.APPLE))); + new Member("1", "123", new OAuth2Info("321", AuthType.APPLE), "test")); final Member to = memberRepository.save( - new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO))); + new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO), "deviceToken")); final Friend friend = new Friend(from, to); // when @@ -48,10 +47,10 @@ void findByTwoMemberId() { // given final Member from = memberRepository.save( - new Member("1", "123", new OAuth2Info("321", AuthType.APPLE))); + new Member("1", "123", new OAuth2Info("321", AuthType.APPLE), "deviceToken1")); final Member to = memberRepository.save( - new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO))); + new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO), "deviceToken2")); final Friend friend = new Friend(from, to); final Friend expected = friendRepository.save(friend); @@ -69,10 +68,10 @@ void findByMember() { // given final Member from = memberRepository.save( - new Member("1", "123", new OAuth2Info("321", AuthType.APPLE))); + new Member("1", "123", new OAuth2Info("321", AuthType.APPLE), "deviceToken1")); final Member to = memberRepository.save( - new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO))); + new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO), "deviceToken2")); final Friend friend = new Friend(from, to); final Friend expected = friendRepository.save(friend); expected.updateStatus(FriendStatus.ACCEPTED); @@ -90,10 +89,10 @@ void findByMemberAndFriendStatus() { // given final Member from = memberRepository.save( - new Member("1", "123", new OAuth2Info("321", AuthType.APPLE))); + new Member("1", "123", new OAuth2Info("321", AuthType.APPLE), "deviceToken1")); final Member to = memberRepository.save( - new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO))); + new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO), "deviceToken2")); final Friend friend = new Friend(from, to); friendRepository.save(friend); @@ -111,11 +110,11 @@ void findByMemberAndMemberNickname() { // given final Member from = memberRepository.save( - new Member("1", "123", new OAuth2Info("321", AuthType.APPLE))); + new Member("1", "123", new OAuth2Info("321", AuthType.APPLE), "deviceToken1")); final String friendNickname = "2"; final Member to = memberRepository.save( - new Member(friendNickname, "1234", new OAuth2Info("123", AuthType.KAKAO))); + new Member(friendNickname, "1234", new OAuth2Info("123", AuthType.KAKAO), "deviceToken2")); final Friend friend = new Friend(from, to); final Friend expected = friendRepository.save(friend); expected.updateStatus(FriendStatus.ACCEPTED); diff --git a/backend/src/test/java/com/twtw/backend/domain/friend/service/FriendServiceTest.java b/backend/src/test/java/com/twtw/backend/domain/friend/service/FriendServiceTest.java index 970cf8ed..149e1bb0 100644 --- a/backend/src/test/java/com/twtw/backend/domain/friend/service/FriendServiceTest.java +++ b/backend/src/test/java/com/twtw/backend/domain/friend/service/FriendServiceTest.java @@ -1,7 +1,5 @@ package com.twtw.backend.domain.friend.service; -import static org.assertj.core.api.Assertions.assertThat; - import com.twtw.backend.domain.friend.dto.request.FriendRequest; import com.twtw.backend.domain.friend.dto.request.FriendUpdateRequest; import com.twtw.backend.domain.friend.dto.response.FriendResponse; @@ -12,7 +10,6 @@ import com.twtw.backend.domain.member.entity.Member; import com.twtw.backend.domain.member.entity.OAuth2Info; import com.twtw.backend.support.service.LoginTest; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -20,6 +17,8 @@ import java.util.List; import java.util.UUID; +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("FriendService의") class FriendServiceTest extends LoginTest { @@ -32,7 +31,7 @@ void addRequest() { // given final UUID id = memberRepository - .save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE))) + .save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE), "deviceToken")) .getId(); // when @@ -49,7 +48,7 @@ void addRequest() { void updateStatus() { // given final Member toMember = - memberRepository.save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE))); + memberRepository.save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE), "deviceToken")); final Friend friend = friendRepository.save(new Friend(loginUser, toMember)); // when @@ -66,7 +65,7 @@ void updateStatus() { void getFriends() { // given final Member toMember = - memberRepository.save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE))); + memberRepository.save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE), "deviceToken")); friendRepository.save(new Friend(loginUser, toMember)); friendService.updateStatus( new FriendUpdateRequest(toMember.getId(), FriendStatus.ACCEPTED)); @@ -83,7 +82,7 @@ void getFriends() { void getFriendsByStatus() { // given final Member toMember = - memberRepository.save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE))); + memberRepository.save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE), "deviceToken")); friendRepository.save(new Friend(loginUser, toMember)); // when @@ -101,7 +100,7 @@ void getFriendByNickname() { final String nickname = "1"; final Member toMember = memberRepository.save( - new Member(nickname, "12", new OAuth2Info("123", AuthType.APPLE))); + new Member(nickname, "12", new OAuth2Info("123", AuthType.APPLE), "deviceToken")); final Friend expected = friendRepository.save(new Friend(loginUser, toMember)); expected.updateStatus(FriendStatus.ACCEPTED); diff --git a/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java b/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java index 5df773ca..b0e8ac65 100644 --- a/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java +++ b/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java @@ -1,17 +1,5 @@ package com.twtw.backend.domain.member.controller; -import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentRequest; -import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentResponse; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - import com.twtw.backend.domain.member.dto.request.DeviceTokenRequest; import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; import com.twtw.backend.domain.member.dto.request.OAuthRequest; @@ -22,7 +10,6 @@ import com.twtw.backend.domain.member.entity.AuthType; import com.twtw.backend.domain.member.service.AuthService; import com.twtw.backend.support.docs.RestDocsTest; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -30,6 +17,17 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.ResultActions; +import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentRequest; +import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentResponse; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + @DisplayName("AuthController의") @WebMvcTest(AuthController.class) class AuthControllerTest extends RestDocsTest { @@ -102,6 +100,7 @@ void saveMember() throws Exception { new MemberSaveRequest( "정해진", "http://some-url-to-profile-image", + "DEVICE_TOKEN", new OAuthRequest( "client-id", AuthType.APPLE)))) .contentType(MediaType.APPLICATION_JSON)); diff --git a/backend/src/test/java/com/twtw/backend/domain/member/repository/MemberRepositoryTest.java b/backend/src/test/java/com/twtw/backend/domain/member/repository/MemberRepositoryTest.java index 61a5f28c..70a792c9 100644 --- a/backend/src/test/java/com/twtw/backend/domain/member/repository/MemberRepositoryTest.java +++ b/backend/src/test/java/com/twtw/backend/domain/member/repository/MemberRepositoryTest.java @@ -1,28 +1,24 @@ package com.twtw.backend.domain.member.repository; -import static org.assertj.core.api.Assertions.assertThat; - import com.twtw.backend.domain.member.dto.request.DeviceTokenRequest; import com.twtw.backend.domain.member.entity.DeviceToken; import com.twtw.backend.domain.member.entity.Member; import com.twtw.backend.fixture.member.MemberEntityFixture; import com.twtw.backend.support.repository.RepositoryTest; - import jakarta.persistence.EntityManager; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.UUID; +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("MemberRepository의") -public class MemberRepositoryTest extends RepositoryTest { +class MemberRepositoryTest extends RepositoryTest { @Autowired private MemberRepository memberRepository; - @Autowired private DeviceTokenRepository deviceTokenRepository; - @Autowired private EntityManager em; @Test @@ -65,7 +61,6 @@ void saveDeivceToken() { // when DeviceToken deviceToken = new DeviceToken(deviceTokenRequest.getDeviceToken()); member.updateDeviceToken(deviceToken); - deviceTokenRepository.save(deviceToken); // then assertThat(member.getDeviceToken().getDeviceToken().equals("THIS_IS_TEST_TOKEN")); diff --git a/backend/src/test/java/com/twtw/backend/domain/member/service/AuthServiceTest.java b/backend/src/test/java/com/twtw/backend/domain/member/service/AuthServiceTest.java index c5ce7d0c..055bd441 100644 --- a/backend/src/test/java/com/twtw/backend/domain/member/service/AuthServiceTest.java +++ b/backend/src/test/java/com/twtw/backend/domain/member/service/AuthServiceTest.java @@ -1,7 +1,5 @@ package com.twtw.backend.domain.member.service; -import static org.assertj.core.api.Assertions.assertThat; - import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; import com.twtw.backend.domain.member.dto.request.OAuthRequest; import com.twtw.backend.domain.member.dto.response.AfterLoginResponse; @@ -13,11 +11,12 @@ import com.twtw.backend.fixture.member.MemberEntityFixture; import com.twtw.backend.support.database.DatabaseTest; import com.twtw.backend.support.exclude.ExcludeTest; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import static org.assertj.core.api.Assertions.assertThat; + @DatabaseTest @DisplayName("AuthService의 ") public class AuthServiceTest extends ExcludeTest { @@ -36,6 +35,7 @@ void saveMemberKakao() { new MemberSaveRequest( "JinJooWon_Kakao", "TEST_PROFILE_IMAGE", + "deviceToken", new OAuthRequest("TEST_KAKAO_TOKEN", AuthType.KAKAO)); // when @@ -53,13 +53,14 @@ void saveMemberApple() { new MemberSaveRequest( "JinJooWon_Apple", "TEST_PROFILE_IMAGE", + "deviceToken", new OAuthRequest("TEST_APPLE_TOKEN", AuthType.APPLE)); // when AfterLoginResponse response = authService.saveMember(appleRequest); // then - assertThat(response.getStatus().equals(AuthStatus.SIGNIN)).isTrue(); + assertThat(response.getStatus()).isEqualTo(AuthStatus.SIGNIN); } @Test @@ -76,6 +77,6 @@ void getTokenByOAuthSuccess() { AfterLoginResponse response = authService.getTokenByOAuth(request); // then - assertThat(response.getStatus().equals(AuthStatus.SIGNIN)).isTrue(); + assertThat(response.getStatus()).isEqualTo(AuthStatus.SIGNIN); } } diff --git a/backend/src/test/java/com/twtw/backend/fixture/member/MemberEntityFixture.java b/backend/src/test/java/com/twtw/backend/fixture/member/MemberEntityFixture.java index 28fb4c06..61128512 100644 --- a/backend/src/test/java/com/twtw/backend/fixture/member/MemberEntityFixture.java +++ b/backend/src/test/java/com/twtw/backend/fixture/member/MemberEntityFixture.java @@ -3,21 +3,21 @@ import com.twtw.backend.domain.member.entity.AuthType; import com.twtw.backend.domain.member.entity.Member; import com.twtw.backend.domain.member.entity.OAuth2Info; - import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public enum MemberEntityFixture { - LOGIN_MEMBER("호즨이", "http://someUrlToS3", "12345", AuthType.APPLE), - FIRST_MEMBER("담이와써요", "http://myPictureIsExpensive", "777", AuthType.APPLE), - SECOND_MEMBER("홍담진", "http://fighting", "1234567", AuthType.KAKAO); + LOGIN_MEMBER("호즨이", "http://someUrlToS3", "12345", "device", AuthType.APPLE), + FIRST_MEMBER("담이와써요", "http://myPictureIsExpensive", "777", "deviceToken", AuthType.APPLE), + SECOND_MEMBER("홍담진", "http://fighting", "1234567", "DeviceToken!", AuthType.KAKAO); private final String name; private final String profileImage; private final String clientId; + private final String deviceToken; private final AuthType authType; public Member toEntity() { - return new Member(name, profileImage, new OAuth2Info(clientId, authType)); + return new Member(name, profileImage, new OAuth2Info(clientId, authType), deviceToken); } } diff --git a/backend/src/test/java/com/twtw/backend/support/exclude/ExcludeTest.java b/backend/src/test/java/com/twtw/backend/support/exclude/ExcludeTest.java index de03bfa2..be2aa697 100644 --- a/backend/src/test/java/com/twtw/backend/support/exclude/ExcludeTest.java +++ b/backend/src/test/java/com/twtw/backend/support/exclude/ExcludeTest.java @@ -2,13 +2,17 @@ import com.twtw.backend.config.rabbitmq.RabbitMQConfig; import com.twtw.backend.domain.location.controller.LocationController; - +import com.twtw.backend.domain.notification.messagequeue.FcmProducer; +import org.junit.jupiter.api.BeforeEach; import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.boot.actuate.autoconfigure.amqp.RabbitHealthContributorAutoConfiguration; import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; + @ActiveProfiles("test") public abstract class ExcludeTest { @@ -22,4 +26,11 @@ public abstract class ExcludeTest { private RabbitHealthContributorAutoConfiguration rabbitHealthContributorAutoConfiguration; @MockBean private LocationController locationController; + + @MockBean private FcmProducer fcmProducer; + + @BeforeEach + void setUp() { + doNothing().when(fcmProducer).sendNotification(any()); + } }