Skip to content

Commit

Permalink
feat Privacy API Controller 작성 (#59)
Browse files Browse the repository at this point in the history
* 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
rookedsysc authored Apr 12, 2024
1 parent 509bf27 commit 501e379
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 9 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/cd-wordflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ jobs:
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean build --warning-mode all
# 전송할 파일을 담을 디렉토리 생성
./gradlew test -i
./gradlew clean build --warning-mode all
# 전송할 파일을 담을 디렉토리 생성
- name: Make Directory for deliver
run: mkdir deploy

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dependencies {
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gamemoonchul.application;

import com.gamemoonchul.MatchUserService;
import com.gamemoonchul.domain.entity.riot.MatchGame;
import com.gamemoonchul.domain.model.vo.riot.MatchRecord;
import com.gamemoonchul.infrastructure.adapter.LolSearchAdapter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gamemoonchul;
package com.gamemoonchul.application;

import com.gamemoonchul.domain.converter.riot.MatchUserConverter;
import com.gamemoonchul.domain.entity.riot.MatchGame;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gamemoonchul.infrastructure;
package com.gamemoonchul.infrastructure.web;

import com.gamemoonchul.application.MemberService;
import com.gamemoonchul.common.annotation.MemberSession;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/gamemoonchul/MatchUserServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gamemoonchul;

import com.gamemoonchul.application.MatchGameService;
import com.gamemoonchul.application.MatchUserService;
import com.gamemoonchul.domain.entity.riot.MatchGame;
import com.gamemoonchul.domain.entity.riot.MatchUser;
import com.gamemoonchul.domain.model.vo.riot.MatchDummy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gamemoonchul.application;

import com.gamemoonchul.MatchUserService;
import com.gamemoonchul.domain.entity.riot.MatchGame;
import com.gamemoonchul.domain.model.vo.riot.MatchDummy;
import com.gamemoonchul.domain.model.vo.riot.MatchRecord;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gamemoonchul.application;

import com.gamemoonchul.MatchUserService;
import com.gamemoonchul.domain.entity.riot.MatchGame;
import com.gamemoonchul.domain.entity.riot.MatchUser;
import com.gamemoonchul.domain.model.vo.riot.MatchDummy;
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/gamemoonchul/domain/entity/MemberDummy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.gamemoonchul.domain.status.MemberStatus;
import com.gamemoonchul.infrastructure.repository.MemberRepository;
import com.gamemoonchul.infrastructure.web.common.BaseIntegrationTest;
import jakarta.transaction.Transactional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -23,6 +24,7 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@Transactional
class MemberApiControllerTest extends BaseIntegrationTest {
@Autowired
private TokenHelper tokenHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.gamemoonchul.config.oauth.user.OAuth2Provider;
import com.gamemoonchul.infrastructure.web.common.BaseIntegrationTest;
import com.gamemoonchul.infrastructure.web.dto.RenewRequest;
import jakarta.transaction.Transactional;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -16,6 +17,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


@Transactional
class MemberOpenApiControllerTest extends BaseIntegrationTest {

@Autowired
Expand Down
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Isolation;

@SpringBootTest
@Disabled
@AutoConfigureMockMvc
@Transactional
public class BaseIntegrationTest {
@Autowired
protected MockMvc mvc;
Expand Down

0 comments on commit 501e379

Please sign in to comment.