diff --git a/backend/src/main/java/mouda/backend/member/domain/LoginDetail.java b/backend/src/main/java/mouda/backend/member/domain/LoginDetail.java index 91c33190..2b09c786 100644 --- a/backend/src/main/java/mouda/backend/member/domain/LoginDetail.java +++ b/backend/src/main/java/mouda/backend/member/domain/LoginDetail.java @@ -2,7 +2,6 @@ import java.util.Objects; -import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; @@ -15,7 +14,6 @@ public class LoginDetail { @Enumerated(EnumType.STRING) private OauthType oauthType; - @Column(unique = true) private String identifier; protected LoginDetail() { diff --git a/backend/src/test/java/mouda/backend/auth/business/KakaoAuthServiceTest.java b/backend/src/test/java/mouda/backend/auth/business/KakaoAuthServiceTest.java new file mode 100644 index 00000000..a4dc208e --- /dev/null +++ b/backend/src/test/java/mouda/backend/auth/business/KakaoAuthServiceTest.java @@ -0,0 +1,57 @@ +package mouda.backend.auth.business; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.util.Optional; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +import mouda.backend.auth.implement.KakaoUserInfoProvider; +import mouda.backend.auth.presentation.request.KakaoConvertRequest; +import mouda.backend.common.fixture.MemberFixture; +import mouda.backend.member.domain.Member; +import mouda.backend.member.domain.OauthType; +import mouda.backend.member.infrastructure.MemberRepository; + +@SpringBootTest +class KakaoAuthServiceTest { + + @Autowired + private KakaoAuthService kakaoAuthService; + + @Autowired + private MemberRepository memberRepository; + + @MockBean + private KakaoUserInfoProvider userInfoProvider; + + @DisplayName("카카오 회원 정보를 애플 회원으로 변경한다.") + @Test + void convert() { + // given + String kakaoIdentifier = "kakaoIdentifier"; + Member anna = MemberFixture.getAnna(kakaoIdentifier); + memberRepository.save(anna); + + String appleIdentifier = "appleIdentifier"; + Member alternation = MemberFixture.getAnna(OauthType.APPLE, appleIdentifier); + memberRepository.save(alternation); + when(userInfoProvider.getIdentifier(anyString())).thenReturn(kakaoIdentifier); + + // when + kakaoAuthService.convert(alternation, new KakaoConvertRequest("code")); + + // then + Optional kakaoMember = memberRepository.findByLoginDetail_Identifier(kakaoIdentifier); + assertThat(kakaoMember.isEmpty()).isTrue(); + Optional appleMember = memberRepository.findByLoginDetail_Identifier(appleIdentifier); + assertThat(appleMember.isPresent()).isTrue(); + assertThat(appleMember.get().getName()).isEqualTo(anna.getName()); + assertThat(appleMember.get().getLoginDetail()).isEqualTo(alternation.getLoginDetail()); + } +} diff --git a/backend/src/test/java/mouda/backend/common/fixture/MemberFixture.java b/backend/src/test/java/mouda/backend/common/fixture/MemberFixture.java index 811ee9da..4e98d769 100644 --- a/backend/src/test/java/mouda/backend/common/fixture/MemberFixture.java +++ b/backend/src/test/java/mouda/backend/common/fixture/MemberFixture.java @@ -27,6 +27,13 @@ public static Member getAnna(String identifier) { .build(); } + public static Member getAnna(OauthType oauthType, String identifier) { + return Member.builder() + .name("anna") + .loginDetail(new LoginDetail(oauthType, identifier)) + .build(); + } + public static Member getChico() { return Member.builder() .name("chico")