Skip to content

Commit

Permalink
Merge pull request #136 from grida-diary/main
Browse files Browse the repository at this point in the history
prod
  • Loading branch information
wwan13 authored Aug 28, 2024
2 parents 833e8dc + 6becdaf commit 936ae3a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ import io.wwan13.api.document.snippets.STRING
import io.wwan13.api.document.snippets.isTypeOf
import io.wwan13.api.document.snippets.moreAbout
import io.wwan13.api.document.snippets.whichMeans
import io.wwan13.wintersecurity.jwt.TokenGenerator
import org.grida.auth.KakaoAuthClient
import org.grida.auth.KakaoAuthToken
import org.grida.auth.AuthProcessorSelector
import org.grida.docs.ApiDocsTest
import org.grida.domain.user.LoginOption
import org.grida.domain.user.LoginPlatform
import org.grida.domain.user.User
import org.grida.domain.user.UserService
import org.grida.docs.auth.stub.StubAuthProcessor
import org.grida.presentation.v1.auth.AuthController
import org.grida.user.KakaoUserClient
import org.grida.user.KakaoUserProfile
import org.junit.jupiter.api.Test
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest

Expand All @@ -29,42 +22,22 @@ class AuthApiDocsTest(
) {

@MockkBean
private lateinit var userService: UserService

@MockkBean
private lateinit var tokenGenerator: TokenGenerator

@MockkBean
private lateinit var kakaoAuthClient: KakaoAuthClient

@MockkBean
private lateinit var kakaoUserClient: KakaoUserClient
private lateinit var authProcessorSelector: AuthProcessorSelector

@Test
fun `카카오 로그인 API`() {
fun `인증 토큰 발급 API`() {

val user = User(
id = 1L, name = "김태완", loginOption = LoginOption(LoginPlatform.KAKAO, "123123")
)
every { authProcessorSelector.select(any()) } returns StubAuthProcessor()

every { userService.readUserByLoginOption(any()) } returns user

every { tokenGenerator.accessToken(any()) } returns "accessToken"
every { tokenGenerator.refreshToken(any()) } returns "refreshToken"

val kakaoAuthToken = KakaoAuthToken("kakaoAccessToken", "kakaoRefreshToken")
every { kakaoAuthClient.provideAuthToken(any()) } returns kakaoAuthToken

val kakaoUserProfile = KakaoUserProfile("123123", "김태완")
every { kakaoUserClient.readUserProfile(any()) } returns kakaoUserProfile

val api = api.get("/api/v1/auth/kakao") {
val api = api.get("/api/v1/auth") {
queryParam("platform", "oauth2 platform")
queryParam("code", "kakao authorization code")
}

documentFor(api, "kakao-login") {
documentFor(api, "provide-auth-token") {
summary(
"카카오 로그인 API" moreAbout """
"인증 토큰 발급 API" moreAbout """
kakao <br/>
** local : https://kauth.kakao.com/oauth/authorize?client_id=e32f0cc35368a69966b54698b193a794&
redirect_uri=http://localhost:8080/api/v1/auth/login/kakao&response_type=code <br/>
** live : https://kauth.kakao.com/oauth/authorize?client_id=e32f0cc35368a69966b54698b193a794&
Expand All @@ -74,7 +47,10 @@ class AuthApiDocsTest(
.map { it.trimEnd() }
.joinToString("")
)
queryParameters("code" whichMeans "카카오 인증 토큰")
queryParameters(
"platform" whichMeans "oauth2 플랫폼 [kakao/**]",
"code" whichMeans "인증 토큰"
)
responseFields(
"data.accessToken" isTypeOf STRING whichMeans "인증 토큰",
"data.refreshToken" isTypeOf STRING whichMeans "재발급 토큰",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.grida.docs.auth.stub

import org.grida.auth.AuthProcessor
import org.grida.auth.AuthToken

class StubAuthProcessor : AuthProcessor {
override fun process(code: String): AuthToken {
return AuthToken("access token", "refresh token")
}
}

0 comments on commit 936ae3a

Please sign in to comment.