-
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.
feat Privacy API Controller 작성 (#59)
* modify Privacy Agreed Column 추가, Converter, Dto 수정 * feat Member Privacy Not Agreed Role 추가 /privacy/agree API 추가 Spring Security Config, TokenProvider 등 수정 * fix Test 코드 Filter에서 에러 발생해서 403 발생하는 것 확인 * modify Privacy API User 권한도 접근 가능하게 변경 * feat Privacy API Controller 작성, BaseIntegrationTest에서 Transactional 옵션 제거 * modify workflow --warning-mode all 추가 #51 * config Test Junit Dependency 추가 참조 이슈 : spring-io/initializr#1476 * modify Test -i 옵션으로 Test 실패 원인 파악 시도 #51 * modify Privacy Controller 삭제 및 MatchUserService 이동
- Loading branch information
1 parent
509bf27
commit 501e379
Showing
13 changed files
with
141 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
2 changes: 1 addition & 1 deletion
2
...va/com/gamemoonchul/MatchUserService.java → ...oonchul/application/MatchUserService.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
2 changes: 1 addition & 1 deletion
2
...frastructure/MemberPrivacyController.java → ...tructure/web/MemberPrivacyController.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
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
1 change: 0 additions & 1 deletion
1
src/test/java/com/gamemoonchul/application/BoardServiceTest.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
1 change: 0 additions & 1 deletion
1
src/test/java/com/gamemoonchul/application/MatchGameServiceTest.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
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 |
---|---|---|
|
@@ -16,4 +16,18 @@ public static Member create() { | |
.role(MemberRole.USER) | ||
.build(); | ||
} | ||
|
||
public static Member createPrivacyRole() { | ||
return Member.builder() | ||
.provider(OAuth2Provider.GOOGLE) | ||
.email("[email protected]") | ||
.nickname("홍길동") | ||
.identifier("test1") | ||
.name("홍길동") | ||
.picture("https://www.naver.com") | ||
.score(0.0) | ||
.role(MemberRole.PRIVACY_NOT_AGREED) | ||
.build(); | ||
} | ||
|
||
} |
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
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
114 changes: 114 additions & 0 deletions
114
src/test/java/com/gamemoonchul/infrastructure/web/MemberPrivacyControllerTest.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,114 @@ | ||
package com.gamemoonchul.infrastructure.web; | ||
|
||
import com.gamemoonchul.config.jwt.TokenDto; | ||
import com.gamemoonchul.config.jwt.TokenHelper; | ||
import com.gamemoonchul.config.jwt.TokenInfo; | ||
import com.gamemoonchul.config.jwt.TokenType; | ||
import com.gamemoonchul.domain.entity.Member; | ||
import com.gamemoonchul.domain.entity.MemberDummy; | ||
import com.gamemoonchul.infrastructure.repository.MemberRepository; | ||
import com.gamemoonchul.infrastructure.web.common.BaseIntegrationTest; | ||
import jakarta.transaction.Transactional; | ||
import org.aspectj.lang.annotation.Before; | ||
import org.junit.jupiter.api.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
@TestPropertySource(locations = "classpath:application.yaml") | ||
class MemberPrivacyControllerTest extends BaseIntegrationTest { | ||
|
||
@Autowired | ||
private MemberRepository memberRepository; | ||
|
||
@Autowired | ||
private TokenHelper tokenHelper; | ||
|
||
Member member; | ||
|
||
TokenDto tokenDto; | ||
|
||
@Test | ||
@Order(1) | ||
void setUp() { | ||
member = MemberDummy.createPrivacyRole(); | ||
memberRepository.save(member); | ||
} | ||
|
||
void getTokenDto() { | ||
member = MemberDummy.createPrivacyRole(); | ||
TokenInfo tokenInfo = TokenInfo.builder() | ||
.email(member.getEmail()) | ||
.provider(member.getProvider().toString()) | ||
.identifier(member.getIdentifier()) | ||
.tokenType(TokenType.ACCESS) | ||
.build(); | ||
tokenDto = tokenHelper.generateToken(tokenInfo); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
@DisplayName("privacy 동의 안된 경우 테스트") | ||
void notAgreed() throws Exception { | ||
// given | ||
getTokenDto(); | ||
// when | ||
ResultActions resultActions = super.mvc.perform(get("/privacy/is-agreed") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("Authorization", "Bearer " + tokenDto.getAccessToken())); | ||
|
||
// then | ||
resultActions.andExpect(jsonPath("$.data").value(false)); | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
@DisplayName("privacy 동의 api 호출") | ||
void agreePrivcayTest() throws Exception { | ||
// given | ||
getTokenDto(); | ||
// when | ||
ResultActions resultActions = super.mvc.perform(MockMvcRequestBuilders.patch("/privacy/agree") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("Authorization", "Bearer " + tokenDto.getAccessToken())); | ||
|
||
// then | ||
resultActions.andExpect(status().isOk()); | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
@DisplayName("privacy 동의 후 동의가 됐음을 확인") | ||
void agreed() throws Exception { | ||
// given | ||
getTokenDto(); | ||
// when | ||
ResultActions resultActions = super.mvc.perform(get("/privacy/is-agreed") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("Authorization", "Bearer " + tokenDto.getAccessToken())); | ||
|
||
// then | ||
resultActions.andExpect(jsonPath("$.data").value(true)); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
@DisplayName("토큰 없이 호출하면 401에러 발생") | ||
void notAuthorized() throws Exception { | ||
// given // when | ||
ResultActions resultActions = super.mvc.perform(get("/privacy/is-agreed") | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
resultActions.andExpect(status().isUnauthorized()); | ||
} | ||
} |
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