Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: 공통 인증 부분, 카테고리 생성/조회 API, 사용자 생성 문제 CRUD, 사용자 생성 요약 CRUD에 대한 테스트 작성 #66

Merged
merged 26 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8d32b1c
Update README.md
googoo9918 Jun 4, 2024
b6df367
Update README.md
googoo9918 Jun 4, 2024
5e5e33d
Update README.md
googoo9918 Jun 4, 2024
b9640da
test: 테스트 환경에서의 인증(JWT 토큰 발급)을 위한 fake 엔드포인트 구성
yujamint Jun 15, 2024
2bf66f6
test: 카테고리 생성/조회 테스트 작성
yujamint Jun 15, 2024
629abc8
chore: github actions test workflow 추가
yujamint Jun 1, 2024
5660bec
test: 실패 테스트 임시 주석 처리
yujamint Jun 1, 2024
e4d5ad0
Update test.yaml
yujamint Jun 1, 2024
16839f8
chore: 테스트 환경에서의 환경 변수 설정
yujamint Jun 1, 2024
0caa370
test: 사용하지 않는 테스트 파일 삭제
yujamint Jun 1, 2024
6566d8c
chore: github actions deploy workflow 추가
yujamint Jun 1, 2024
6a08d40
fix: region 문자열로 처리
yujamint Jun 1, 2024
1fc9a89
fix: env 제거
yujamint Jun 1, 2024
a694832
fix: yaml multiline strings 문법 적용
yujamint Jun 1, 2024
f6823c5
fix: remove space
yujamint Jun 1, 2024
1ff0b54
fix: 잘못된 code deploy 옵션 수정
yujamint Jun 1, 2024
c87b1f9
fix: 잘못된 code deploy 옵션 수정
yujamint Jun 1, 2024
f1e7929
fix: codedeploy hooks lifecycle 변경
yujamint Jun 1, 2024
de24032
fix: codedeploy hooks lifecycle 변경
yujamint Jun 1, 2024
55fd1c9
fix: script가 종료되지 않는 문제점 해결
yujamint Jun 1, 2024
f249a3e
fix: script가 종료되지 않는 문제점 해결
yujamint Jun 1, 2024
116b447
chore: cd 대상으로 불필요한 브랜치 제거
yujamint Jun 15, 2024
5af41ee
fix: test profile 추가
yujamint Jun 16, 2024
518d028
Feat: "사용자 생성 문제 CRUD 테스트 작성"
googoo9918 Jun 16, 2024
1307004
Feat: "사용자 생성 요약 문제 CRUD 테스트 작성"
googoo9918 Jun 16, 2024
8bc1902
Merge branch 'dev' into test/authentication
googoo9918 Jun 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ dependencies {
testImplementation 'com.theokanning.openai-gpt3-java:service:0.18.2'
testImplementation 'com.knuddels:jtokkit:1.0.0'
testImplementation 'com.fasterxml.jackson.module:jackson-module-jsonSchema-jakarta:2.15.0'

// Rest Assured
testImplementation 'io.rest-assured:rest-assured:4.5.1'
}

dependencyManagement {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/app/domain/category/dto/CategoryDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class CategoryDto {

@Getter
@AllArgsConstructor
@Schema(name = "CategoryRequestDto", description = "카테고리 요청 DTO")
public static class RequestDto {
@NotBlank
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class MemberSavedProblemDto {

@Getter
@Schema(name = "MemberSavedProblemPost", description = "새 문제 생성 요청 DTO")
@AllArgsConstructor
public static class Post {

@NotBlank
Expand All @@ -34,6 +35,7 @@ public static class Post {

@Getter
@Schema(name = "MemberSavedProblemPatch", description = "문제 수정 요청 DTO")
@AllArgsConstructor
public static class Patch {
@Schema(description = "문제의 이름", example = "수정된 문제 이름")
private String problemName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class MemberSavedSummaryDto {

@Getter
@Schema(name = "MemberSavedSummaryPostDto", description = "새 요약 생성 요청 DTO")
@AllArgsConstructor
public static class Post {
@NotBlank(message = "제목을 입력해주세요")
@Schema(description = "요약 제목", example = "요약 제목")
Expand All @@ -23,6 +24,7 @@ public static class Post {

@Getter
@Schema(name = "MemberSavedSummaryPatchDto", description = "요약 수정 요청 DTO")
@AllArgsConstructor
public static class Patch {
@Schema(description = "요약 제목", example = "새로운 요약 제목")
private String summaryTitle;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/app/global/config/web/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ public void addInterceptors(InterceptorRegistry registry) {
"/oauth/kakao/callback",
"/api/problem/getFileProblems",
"/api/summary/getSummary",
"/api/member-saved-problem/{memberSavedProblemId}",
"/api/member-saved-summary/{memberSavedSummaryID}",
"/api/member-saved-problem/{problemId}",
"/api/member-saved-summary/{summaryId}",
"/api/category/list",
"/api/category/{categoryId}",
"/api/categorized-problem/{categorizedProblemId}",
"/api/categorized-summary/{categorizedSummaryID}",
"/api/problem/getFileProblems/{fileId}",
"/api/summary/getSummary/{fileId}"
"/api/summary/getSummary/{fileId}",
"/api/fake/**"
); // 인증 인터셉터를 동작시키지 않을 예외적인 uri 작성

registry.addInterceptor(adminAuthorizationInterceptor) //인증 인터셉터 다음 인가 인터셉터 실행
Expand All @@ -65,4 +66,4 @@ public void addInterceptors(InterceptorRegistry registry) {
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.app.integration.category;

import static org.assertj.core.api.Assertions.assertThat;

import com.app.domain.category.contsant.CategoryType;
import com.app.domain.category.dto.CategoryDto;
import com.app.domain.category.dto.CategoryDto.RequestDto;
import com.app.integration.dto.FakeSignUpRequest;
import io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class CategoryIntegrationTest {

@LocalServerPort
int port;

@BeforeEach
void setUp() {
RestAssured.port = port;
}

@Test
void 카테고리를_생성한다() {
// given
String jwtToken = memberSignUpRequest("닉네임", "[email protected]");

// when
ExtractableResponse<Response> categoryCreateResponse = categoryCreateRequest(
"카테고리1",
CategoryType.PROBLEM,
jwtToken
);
CategoryDto.Response body = categoryCreateResponse.as(CategoryDto.Response.class);

// then
assertThat(categoryCreateResponse.statusCode()).isEqualTo(HttpStatus.OK.value());
assertThat(body.getCategoryName()).isEqualTo("카테고리1");
assertThat(body.getCategoryType()).isEqualTo(CategoryType.PROBLEM);
}

@Test
void 생성한_카테고리를_단건_조회한다() {
// given
String jwtToken = memberSignUpRequest("닉네임", "[email protected]");
ExtractableResponse<Response> categoryCreateResponse = categoryCreateRequest(
"카테고리2",
CategoryType.PROBLEM,
jwtToken
);
Long categoryId = categoryCreateResponse.as(CategoryDto.Response.class).getCategoryId();

// when
ExtractableResponse<Response> categoryFindResponse = RestAssured.given().log().all()
.when().get("/api/category/{categoryId}", categoryId)
.then().log().all()
.extract();

// then
assertThat(categoryFindResponse.statusCode()).isEqualTo(HttpStatus.OK.value());
}

private ExtractableResponse<Response> categoryCreateRequest(
String categoryName,
CategoryType categoryType,
String jwtToken
) {
RequestDto categoryCreateRequest = new RequestDto(categoryName, categoryType);
ExtractableResponse<Response> categoryCreateResponse = RestAssured.given().log().all()
.header(HttpHeaders.AUTHORIZATION, "Bearer " + jwtToken)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body(categoryCreateRequest)
.when().post("/api/category/new")
.then().log().all()
.extract();
return categoryCreateResponse;
}

private String memberSignUpRequest(String ninckname, String email) {
FakeSignUpRequest signUpRequest = new FakeSignUpRequest(ninckname, email);
ExtractableResponse<Response> signUpResponse = RestAssured.given().log().all()
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body(signUpRequest)
.when().post("/api/fake/login")
.then().log().all()
.extract();
return signUpResponse.asString();
}
}
17 changes: 17 additions & 0 deletions src/test/java/com/app/integration/dto/FakeSignUpRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.app.integration.dto;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class FakeSignUpRequest {

private String nickname;
private String email;

public FakeSignUpRequest(String nickname, String email) {
this.nickname = nickname;
this.email = email;
}
}
40 changes: 40 additions & 0 deletions src/test/java/com/app/integration/fake/FakeSignUpController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.app.integration.fake;

import com.app.domain.member.constant.MemberType;
import com.app.domain.member.constant.Role;
import com.app.domain.member.entity.Member;
import com.app.domain.member.service.MemberService;
import com.app.global.jwt.dto.JwtTokenDto;
import com.app.global.jwt.service.TokenManager;
import com.app.integration.dto.FakeSignUpRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@Profile(value = {"local", "test"})
@RestController
public class FakeSignUpController {

private final MemberService memberService;
private final TokenManager tokenManager;

@PostMapping("/api/fake/login")
public ResponseEntity<String> fakeSignUp(@RequestBody FakeSignUpRequest request) {
Member member = memberService.findMemberByEmail(request.getEmail()).orElseGet(
() -> memberService.registerMember(Member.builder()
.nickName(request.getNickname())
.email(request.getEmail())
.memberType(MemberType.KAKAO)
.role(Role.USER)
.build())
);

JwtTokenDto jwtTokenDto = tokenManager.createJwtTokenDto(member.getMemberId(), member.getRole());
member.updateRefreshToken(jwtTokenDto);
return ResponseEntity.ok(jwtTokenDto.getAccessToken());
}
}
Loading