Skip to content

Commit

Permalink
test: 사용자 전환 기능을 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingyum-Kim committed Oct 20, 2024
1 parent 292c373 commit 043d5a9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Objects;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
Expand All @@ -15,7 +14,6 @@ public class LoginDetail {
@Enumerated(EnumType.STRING)
private OauthType oauthType;

@Column(unique = true)
private String identifier;

protected LoginDetail() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Member> kakaoMember = memberRepository.findByLoginDetail_Identifier(kakaoIdentifier);
assertThat(kakaoMember.isEmpty()).isTrue();
Optional<Member> appleMember = memberRepository.findByLoginDetail_Identifier(appleIdentifier);
assertThat(appleMember.isPresent()).isTrue();
assertThat(appleMember.get().getName()).isEqualTo(anna.getName());
assertThat(appleMember.get().getLoginDetail()).isEqualTo(alternation.getLoginDetail());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 043d5a9

Please sign in to comment.