-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#97 - Test the definition of Kakao authentication information
Represent the result of the Kakao authentication API as a Java record for efficient use, and write tests to verify its functionality.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/test/java/com/laphayen/projectboard/dto/security/KakaoOAuth2ResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.laphayen.projectboard.dto.security; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.ZoneId; | ||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DisplayName("DTO - Kakao OAuth 2.0 인증 응답 데이터 테스트") | ||
class KakaoOAuth2ResponseTest { | ||
|
||
private final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
@DisplayName("인증 결과를 Map(deserialized json)으로 받으면, 카카오 인증 응답 객체로 변환한다.") | ||
@Test | ||
void givenMapFromJson_whenInstantiating_thenReturnsKakaoResponseObject() throws Exception { | ||
// Given | ||
String serializedResponse = """ | ||
{ | ||
"id": 1234567890, | ||
"connected_at": "2022-01-02T00:12:34Z", | ||
"properties": { | ||
"nickname": "홍길동" | ||
}, | ||
"kakao_account": { | ||
"profile_nickname_needs_agreement": false, | ||
"profile": { | ||
"nickname": "홍길동" | ||
}, | ||
"has_email": true, | ||
"email_needs_agreement": false, | ||
"is_email_valid": true, | ||
"is_email_verified": true, | ||
"email": "[email protected]" | ||
} | ||
} | ||
"""; | ||
Map<String, Object> attributes = mapper.readValue(serializedResponse, new TypeReference<>() {}); | ||
|
||
// When | ||
KakaoOAuth2Response result = KakaoOAuth2Response.from(attributes); | ||
|
||
// Then | ||
assertThat(result) | ||
.hasFieldOrPropertyWithValue("id", 1234567890L) | ||
.hasFieldOrPropertyWithValue("connectedAt", ZonedDateTime.of(2022, 1, 2, 0, 12, 34, 0, ZoneOffset.UTC) | ||
.withZoneSameInstant(ZoneId.systemDefault()) | ||
.toLocalDateTime() | ||
) | ||
.hasFieldOrPropertyWithValue("kakaoAccount.profile.nickname", "홍길동") | ||
.hasFieldOrPropertyWithValue("kakaoAccount.email", "[email protected]"); | ||
} | ||
|
||
} |