Skip to content

Commit

Permalink
Merge pull request #68 from HongDam-org/feat/auth-test
Browse files Browse the repository at this point in the history
[FEAT] Feat/auth test
  • Loading branch information
jinjoo-lab authored Nov 23, 2023
2 parents acbed14 + 65bd663 commit e560788
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;
import java.util.UUID;
Expand All @@ -17,5 +18,6 @@ public interface MemberRepository extends JpaRepository<Member, UUID> {
@Query(
"SELECT m FROM Member m WHERE m.oauthInfo.clientId = :oAuthId AND"
+ " m.oauthInfo.authType = :authType")
Optional<Member> findByOAuthIdAndAuthType(String oAuthId, AuthType authType);
Optional<Member> findByOAuthIdAndAuthType(
@Param("oAuthId") String oAuthId, @Param("authType") AuthType authType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@NoArgsConstructor
@AllArgsConstructor
public class Position {
Double x;
Double y;
private Double x;
private Double y;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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;
import com.twtw.backend.domain.member.entity.AuthStatus;
import com.twtw.backend.domain.member.entity.AuthType;
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.domain.member.repository.MemberRepository;
import com.twtw.backend.domain.member.repository.RefreshTokenRepository;
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;

@DatabaseTest
@DisplayName("AuthService의 ")
public class AuthServiceTest extends ExcludeTest {

@Autowired private AuthService authService;

@Autowired private MemberRepository memberRepository;

@Autowired private RefreshTokenRepository refreshTokenRepository;

@Test
@DisplayName("Kakao 회원 가입이 수행되는가")
void saveMemberKakao() {
// given
MemberSaveRequest kakaoRequest =
new MemberSaveRequest(
"JinJooWon_Kakao",
"TEST_PROFILE_IMAGE",
new OAuthRequest("TEST_KAKAO_TOKEN", AuthType.KAKAO));

// when
AfterLoginResponse response = authService.saveMember(kakaoRequest);

// then
assertThat(response.getStatus().equals(AuthStatus.SIGNIN)).isTrue();
}

@Test
@DisplayName("Apple 회원 가입이 수행되는가")
void saveMemberApple() {
// given
MemberSaveRequest appleRequest =
new MemberSaveRequest(
"JinJooWon_Apple",
"TEST_PROFILE_IMAGE",
new OAuthRequest("TEST_APPLE_TOKEN", AuthType.APPLE));

// when
AfterLoginResponse response = authService.saveMember(appleRequest);

// then
assertThat(response.getStatus().equals(AuthStatus.SIGNIN)).isTrue();
}

@Test
@DisplayName("로그인 후 회원에 대해 토큰이 재발급되는가")
void getTokenByOAuthSuccess() {
// given
final Member member = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity());

final OAuthRequest request =
new OAuthRequest(
member.getOauthInfo().getClientId(), member.getOauthInfo().getAuthType());

// when
AfterLoginResponse response = authService.getTokenByOAuth(request);

// then
assertThat(response.getStatus().equals(AuthStatus.SIGNIN)).isTrue();
}
}

0 comments on commit e560788

Please sign in to comment.