Skip to content

Commit

Permalink
Test: OauthServiceTest에 비동기 변경사항 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
WonSteps committed Sep 25, 2024
1 parent cbaf392 commit b161eaa
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/test/java/com/dnd/runus/application/oauth/OauthServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dnd.runus.application.oauth;

import com.dnd.runus.auth.exception.AuthException;
import com.dnd.runus.auth.oidc.provider.OidcProvider;
import com.dnd.runus.auth.oidc.provider.OidcProviderRegistry;
import com.dnd.runus.auth.token.TokenProviderModule;
Expand All @@ -10,11 +11,7 @@
import com.dnd.runus.domain.common.Coordinate;
import com.dnd.runus.domain.common.Pace;
import com.dnd.runus.domain.goalAchievement.GoalAchievementRepository;
import com.dnd.runus.domain.member.Member;
import com.dnd.runus.domain.member.MemberLevelRepository;
import com.dnd.runus.domain.member.MemberRepository;
import com.dnd.runus.domain.member.SocialProfile;
import com.dnd.runus.domain.member.SocialProfileRepository;
import com.dnd.runus.domain.member.*;
import com.dnd.runus.domain.running.RunningRecord;
import com.dnd.runus.domain.running.RunningRecordRepository;
import com.dnd.runus.domain.scale.ScaleAchievementRepository;
Expand Down Expand Up @@ -43,7 +40,9 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.BDDMockito.*;

Expand Down Expand Up @@ -220,7 +219,7 @@ void socialProfile_not_exist_then_signUp_save_social_profile() {

@DisplayName("소셜 로그인 연동 해제: 성공")
@Test
void revokeOauth_Success() {
void revokeOauth_Success() throws InterruptedException {

// given
WithdrawRequest request = new WithdrawRequest(socialType, authorizationCode, idToken);
Expand All @@ -233,14 +232,27 @@ void revokeOauth_Success() {
given(socialProfileRepository.findBySocialTypeAndOauthId(request.socialType(), oauthId))
.willReturn(Optional.of(socialProfileMock));

CountDownLatch latch = new CountDownLatch(2);

String accessToken = "accessToken";
given(oidcProvider.getAccessToken(request.authorizationCode())).willReturn(accessToken);
given(oidcProvider.getAccessToken(request.authorizationCode())).willAnswer(invocation -> {
latch.countDown();
return accessToken;
});

will(invocation -> {
latch.countDown();
return null;
})
.given(oidcProvider)
.revoke(accessToken);

// when
oauthService.revokeOauth(member.memberId(), request);

// then
then(oidcProvider).should().revoke(accessToken);
boolean completed = latch.await(100, MILLISECONDS);
assertTrue(completed);
}

@DisplayName("소셜 로그인 연동 해제: member_id가 없을 경우 NotFoundException을 발생한다.")
Expand All @@ -254,7 +266,7 @@ void revokeOauth_NotFound_MemberID() {
assertThrows(NotFoundException.class, () -> oauthService.revokeOauth(member.memberId(), request));
}

@DisplayName("소셜 로그인 연동 해제: oauthId와 socialType에 해당하는 socialProfile 없을 경우 NotFoundException을 발생한다.")
@DisplayName("소셜 로그인 연동 해제: oauthId와 socialType에 해당하는 socialProfile 없을 경우 AuthException을 발생한다.")
@Test
void revokeOauth_NotFound_SocialProfile() {
// given
Expand All @@ -267,10 +279,10 @@ void revokeOauth_NotFound_SocialProfile() {
.willReturn(Optional.empty());

// when, then
assertThrows(NotFoundException.class, () -> oauthService.revokeOauth(member.memberId(), request));
assertThrows(AuthException.class, () -> oauthService.revokeOauth(member.memberId(), request));
}

@DisplayName("소셜 로그인 연동 해제: socialProfile의 memberId와 member의 id가 다를 경우 NotFoundException을 발생한다.")
@DisplayName("소셜 로그인 연동 해제: socialProfile의 memberId와 member의 id가 다를 경우 AuthException을 발생한다.")
@Test
void revokeOauth_MissMatch_socialProfileAndMemberId() {
// given
Expand All @@ -290,7 +302,7 @@ void revokeOauth_MissMatch_socialProfileAndMemberId() {
.willReturn(Optional.of(socialProfileMock));

// when, then
assertThrows(NotFoundException.class, () -> oauthService.revokeOauth(member.memberId(), request));
assertThrows(AuthException.class, () -> oauthService.revokeOauth(member.memberId(), request));
}
}

Expand Down

0 comments on commit b161eaa

Please sign in to comment.