Skip to content

Commit 501e379

Browse files
authored
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 이동
1 parent 509bf27 commit 501e379

File tree

13 files changed

+141
-9
lines changed

13 files changed

+141
-9
lines changed

.github/workflows/cd-wordflow.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ jobs:
4545
- name: Build with Gradle
4646
run: |
4747
chmod +x ./gradlew
48-
./gradlew clean build --warning-mode all
49-
# 전송할 파일을 담을 디렉토리 생성
48+
./gradlew test -i
49+
./gradlew clean build --warning-mode all
5050
51+
52+
# 전송할 파일을 담을 디렉토리 생성
5153
- name: Make Directory for deliver
5254
run: mkdir deploy
5355

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ dependencies {
7474
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
7575
annotationProcessor 'org.projectlombok:lombok'
7676
testImplementation 'org.springframework.boot:spring-boot-starter-test'
77+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
7778
}
7879

7980
tasks.named('test') {

src/main/java/com/gamemoonchul/application/BoardService.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.gamemoonchul.application;
22

3-
import com.gamemoonchul.MatchUserService;
43
import com.gamemoonchul.domain.entity.riot.MatchGame;
54
import com.gamemoonchul.domain.model.vo.riot.MatchRecord;
65
import com.gamemoonchul.infrastructure.adapter.LolSearchAdapter;

src/main/java/com/gamemoonchul/MatchUserService.java renamed to src/main/java/com/gamemoonchul/application/MatchUserService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.gamemoonchul;
1+
package com.gamemoonchul.application;
22

33
import com.gamemoonchul.domain.converter.riot.MatchUserConverter;
44
import com.gamemoonchul.domain.entity.riot.MatchGame;

src/main/java/com/gamemoonchul/infrastructure/MemberPrivacyController.java renamed to src/main/java/com/gamemoonchul/infrastructure/web/MemberPrivacyController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.gamemoonchul.infrastructure;
1+
package com.gamemoonchul.infrastructure.web;
22

33
import com.gamemoonchul.application.MemberService;
44
import com.gamemoonchul.common.annotation.MemberSession;

src/test/java/com/gamemoonchul/MatchUserServiceTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.gamemoonchul;
22

33
import com.gamemoonchul.application.MatchGameService;
4+
import com.gamemoonchul.application.MatchUserService;
45
import com.gamemoonchul.domain.entity.riot.MatchGame;
56
import com.gamemoonchul.domain.entity.riot.MatchUser;
67
import com.gamemoonchul.domain.model.vo.riot.MatchDummy;

src/test/java/com/gamemoonchul/application/BoardServiceTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.gamemoonchul.application;
22

3-
import com.gamemoonchul.MatchUserService;
43
import com.gamemoonchul.domain.entity.riot.MatchGame;
54
import com.gamemoonchul.domain.model.vo.riot.MatchDummy;
65
import com.gamemoonchul.domain.model.vo.riot.MatchRecord;

src/test/java/com/gamemoonchul/application/MatchGameServiceTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.gamemoonchul.application;
22

3-
import com.gamemoonchul.MatchUserService;
43
import com.gamemoonchul.domain.entity.riot.MatchGame;
54
import com.gamemoonchul.domain.entity.riot.MatchUser;
65
import com.gamemoonchul.domain.model.vo.riot.MatchDummy;

src/test/java/com/gamemoonchul/domain/entity/MemberDummy.java

+14
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,18 @@ public static Member create() {
1616
.role(MemberRole.USER)
1717
.build();
1818
}
19+
20+
public static Member createPrivacyRole() {
21+
return Member.builder()
22+
.provider(OAuth2Provider.GOOGLE)
23+
24+
.nickname("홍길동")
25+
.identifier("test1")
26+
.name("홍길동")
27+
.picture("https://www.naver.com")
28+
.score(0.0)
29+
.role(MemberRole.PRIVACY_NOT_AGREED)
30+
.build();
31+
}
32+
1933
}

src/test/java/com/gamemoonchul/infrastructure/web/MemberApiControllerTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.gamemoonchul.domain.status.MemberStatus;
88
import com.gamemoonchul.infrastructure.repository.MemberRepository;
99
import com.gamemoonchul.infrastructure.web.common.BaseIntegrationTest;
10+
import jakarta.transaction.Transactional;
1011
import org.junit.jupiter.api.BeforeEach;
1112
import org.junit.jupiter.api.DisplayName;
1213
import org.junit.jupiter.api.Test;
@@ -23,6 +24,7 @@
2324
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
2425
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
2526

27+
@Transactional
2628
class MemberApiControllerTest extends BaseIntegrationTest {
2729
@Autowired
2830
private TokenHelper tokenHelper;

src/test/java/com/gamemoonchul/infrastructure/web/MemberOpenApiControllerTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.gamemoonchul.config.oauth.user.OAuth2Provider;
55
import com.gamemoonchul.infrastructure.web.common.BaseIntegrationTest;
66
import com.gamemoonchul.infrastructure.web.dto.RenewRequest;
7+
import jakarta.transaction.Transactional;
78
import org.junit.jupiter.api.DisplayName;
89
import org.junit.jupiter.api.Test;
910
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,6 +17,7 @@
1617
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
1718

1819

20+
@Transactional
1921
class MemberOpenApiControllerTest extends BaseIntegrationTest {
2022

2123
@Autowired
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.gamemoonchul.infrastructure.web;
2+
3+
import com.gamemoonchul.config.jwt.TokenDto;
4+
import com.gamemoonchul.config.jwt.TokenHelper;
5+
import com.gamemoonchul.config.jwt.TokenInfo;
6+
import com.gamemoonchul.config.jwt.TokenType;
7+
import com.gamemoonchul.domain.entity.Member;
8+
import com.gamemoonchul.domain.entity.MemberDummy;
9+
import com.gamemoonchul.infrastructure.repository.MemberRepository;
10+
import com.gamemoonchul.infrastructure.web.common.BaseIntegrationTest;
11+
import jakarta.transaction.Transactional;
12+
import org.aspectj.lang.annotation.Before;
13+
import org.junit.jupiter.api.*;
14+
import org.springframework.beans.factory.annotation.Autowired;
15+
import org.springframework.http.MediaType;
16+
import org.springframework.test.context.TestPropertySource;
17+
import org.springframework.test.web.servlet.ResultActions;
18+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
19+
20+
import java.util.Optional;
21+
22+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
23+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
24+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
25+
26+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
27+
@TestPropertySource(locations = "classpath:application.yaml")
28+
class MemberPrivacyControllerTest extends BaseIntegrationTest {
29+
30+
@Autowired
31+
private MemberRepository memberRepository;
32+
33+
@Autowired
34+
private TokenHelper tokenHelper;
35+
36+
Member member;
37+
38+
TokenDto tokenDto;
39+
40+
@Test
41+
@Order(1)
42+
void setUp() {
43+
member = MemberDummy.createPrivacyRole();
44+
memberRepository.save(member);
45+
}
46+
47+
void getTokenDto() {
48+
member = MemberDummy.createPrivacyRole();
49+
TokenInfo tokenInfo = TokenInfo.builder()
50+
.email(member.getEmail())
51+
.provider(member.getProvider().toString())
52+
.identifier(member.getIdentifier())
53+
.tokenType(TokenType.ACCESS)
54+
.build();
55+
tokenDto = tokenHelper.generateToken(tokenInfo);
56+
}
57+
58+
@Test
59+
@Order(2)
60+
@DisplayName("privacy 동의 안된 경우 테스트")
61+
void notAgreed() throws Exception {
62+
// given
63+
getTokenDto();
64+
// when
65+
ResultActions resultActions = super.mvc.perform(get("/privacy/is-agreed")
66+
.contentType(MediaType.APPLICATION_JSON)
67+
.header("Authorization", "Bearer " + tokenDto.getAccessToken()));
68+
69+
// then
70+
resultActions.andExpect(jsonPath("$.data").value(false));
71+
}
72+
73+
@Test
74+
@Order(3)
75+
@DisplayName("privacy 동의 api 호출")
76+
void agreePrivcayTest() throws Exception {
77+
// given
78+
getTokenDto();
79+
// when
80+
ResultActions resultActions = super.mvc.perform(MockMvcRequestBuilders.patch("/privacy/agree")
81+
.contentType(MediaType.APPLICATION_JSON)
82+
.header("Authorization", "Bearer " + tokenDto.getAccessToken()));
83+
84+
// then
85+
resultActions.andExpect(status().isOk());
86+
}
87+
88+
@Test
89+
@Order(4)
90+
@DisplayName("privacy 동의 후 동의가 됐음을 확인")
91+
void agreed() throws Exception {
92+
// given
93+
getTokenDto();
94+
// when
95+
ResultActions resultActions = super.mvc.perform(get("/privacy/is-agreed")
96+
.contentType(MediaType.APPLICATION_JSON)
97+
.header("Authorization", "Bearer " + tokenDto.getAccessToken()));
98+
99+
// then
100+
resultActions.andExpect(jsonPath("$.data").value(true));
101+
}
102+
103+
@Test
104+
@Order(2)
105+
@DisplayName("토큰 없이 호출하면 401에러 발생")
106+
void notAuthorized() throws Exception {
107+
// given // when
108+
ResultActions resultActions = super.mvc.perform(get("/privacy/is-agreed")
109+
.contentType(MediaType.APPLICATION_JSON));
110+
111+
// then
112+
resultActions.andExpect(status().isUnauthorized());
113+
}
114+
}

src/test/java/com/gamemoonchul/infrastructure/web/common/BaseIntegrationTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
88
import org.springframework.boot.test.context.SpringBootTest;
99
import org.springframework.test.web.servlet.MockMvc;
10+
import org.springframework.transaction.annotation.Isolation;
1011

1112
@SpringBootTest
12-
@Disabled
1313
@AutoConfigureMockMvc
14-
@Transactional
1514
public class BaseIntegrationTest {
1615
@Autowired
1716
protected MockMvc mvc;

0 commit comments

Comments
 (0)