-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: 인수 테스트 작성 * feat: 레포지토리 구현 * feat: 서비스 구현 * test: API 문서 작성 * test: 인수 테스트 수정 * refactor: 코드 리뷰 반영 * refactor: 충돌 해결 * refactor: 포매팅 * refactor: 코드 리뷰 반영
- Loading branch information
Showing
16 changed files
with
369 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
ifndef::snippets[] | ||
:snippets: ../../../build/generated-snippets | ||
endif::[] | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlight.js | ||
:toc: left | ||
:toclevels: 3 | ||
:sectlinks: | ||
:operation-http-request-title: Example Request | ||
:operation-http-response-title: Example Response | ||
|
||
=== *러너 게시글 삭제* | ||
|
||
==== *러너 게시글 삭제 API* | ||
|
||
===== *Http Request* | ||
|
||
include::{snippets}/../../build/generated-snippets/runner-post-delete-api-test/delete-by-runner-post-id/http-request.adoc[] | ||
|
||
===== *Http Request Path Parameters* | ||
|
||
include::{snippets}/../../build/generated-snippets/runner-post-delete-api-test/delete-by-runner-post-id/path-parameters.adoc[] | ||
|
||
===== *Http Response* | ||
|
||
include::{snippets}/../../build/generated-snippets/runner-post-delete-api-test/delete-by-runner-post-id/http-response.adoc[] |
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
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
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
52 changes: 0 additions & 52 deletions
52
backend/baton/src/test/java/touch/baton/assure/runnerpost/RunnerPostAssuredDeleteTest.java
This file was deleted.
Oops, something went wrong.
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
115 changes: 115 additions & 0 deletions
115
backend/baton/src/test/java/touch/baton/assure/runnerpost/RunnerPostDeleteAssuredTest.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,115 @@ | ||
package touch.baton.assure.runnerpost; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import touch.baton.config.AssuredTestConfig; | ||
import touch.baton.domain.member.Member; | ||
import touch.baton.domain.runner.Runner; | ||
import touch.baton.domain.runnerpost.RunnerPost; | ||
import touch.baton.domain.runnerpost.vo.ReviewStatus; | ||
import touch.baton.domain.supporter.Supporter; | ||
import touch.baton.fixture.domain.MemberFixture; | ||
import touch.baton.fixture.domain.RunnerFixture; | ||
import touch.baton.fixture.domain.RunnerPostFixture; | ||
import touch.baton.fixture.domain.SupporterFixture; | ||
import touch.baton.fixture.domain.SupporterRunnerPostFixture; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; | ||
import static org.springframework.http.HttpStatus.NO_CONTENT; | ||
import static touch.baton.fixture.vo.DeadlineFixture.deadline; | ||
|
||
@SuppressWarnings("NonAsciiCharacters") | ||
class RunnerPostDeleteAssuredTest extends AssuredTestConfig { | ||
|
||
private Runner 러너_디투; | ||
private String 로그인용_토큰; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
final Member 사용자_디투 = memberRepository.save(MemberFixture.createDitoo()); | ||
러너_디투 = runnerRepository.save(RunnerFixture.createRunner(사용자_디투)); | ||
로그인용_토큰 = login(사용자_디투.getSocialId().getValue()); | ||
} | ||
|
||
@Test | ||
void 리뷰가_대기중이고_리뷰_지원자가_없다면_러너의_게시글_식별자값으로_러너_게시글_삭제에_성공한다() { | ||
final RunnerPost 러너_게시글 = runnerPostRepository.save(RunnerPostFixture.create(러너_디투, deadline(LocalDateTime.now().plusHours(100)))); | ||
|
||
RunnerPostAssuredSupport | ||
.클라이언트_요청() | ||
.토큰으로_로그인한다(로그인용_토큰) | ||
.러너_게시글_식별자값으로_러너_게시글을_삭제한다(러너_게시글.getId()) | ||
|
||
.서버_응답() | ||
.러너_게시글_삭제_성공을_검증한다(NO_CONTENT); | ||
} | ||
|
||
@Test | ||
void 러너_게시글이_존재하지_않으면_러너의_게시글_식별자값으로_러너_게시글_삭제에_실패한다() { | ||
final Long 존재하지_않는_러너_게시글의_식별자값 = -1L; | ||
|
||
RunnerPostAssuredSupport | ||
.클라이언트_요청() | ||
.토큰으로_로그인한다(로그인용_토큰) | ||
.러너_게시글_식별자값으로_러너_게시글을_삭제한다(존재하지_않는_러너_게시글의_식별자값) | ||
|
||
.서버_응답() | ||
.러너_게시글_삭제_실패를_검증한다(INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
@Test | ||
void 리뷰가_진행중인_상태라면_러너의_게시글_식별자값으로_러너_게시글_삭제에_실패한다() { | ||
final RunnerPost 러너_게시글 = runnerPostRepository.save(RunnerPostFixture.create( | ||
러너_디투, | ||
deadline(LocalDateTime.now().plusHours(100)), | ||
ReviewStatus.IN_PROGRESS | ||
)); | ||
|
||
RunnerPostAssuredSupport | ||
.클라이언트_요청() | ||
.토큰으로_로그인한다(로그인용_토큰) | ||
.러너_게시글_식별자값으로_러너_게시글을_삭제한다(러너_게시글.getId()) | ||
|
||
.서버_응답() | ||
.러너_게시글_삭제_실패를_검증한다(INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
@Test | ||
void 리뷰가_완료된_상태라면_러너의_게시글_식별자값으로_러너_게시글_삭제에_실패한다() { | ||
final RunnerPost 러너_게시글 = runnerPostRepository.save(RunnerPostFixture.create( | ||
러너_디투, | ||
deadline(LocalDateTime.now().plusHours(100)), | ||
ReviewStatus.DONE | ||
)); | ||
|
||
RunnerPostAssuredSupport | ||
.클라이언트_요청() | ||
.토큰으로_로그인한다(로그인용_토큰) | ||
.러너_게시글_식별자값으로_러너_게시글을_삭제한다(러너_게시글.getId()) | ||
|
||
.서버_응답() | ||
.러너_게시글_삭제_실패를_검증한다(INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
@Test | ||
void 리뷰_요청_대기중인_상태이고_리뷰_지원자가_있는_상태라면_러너의_게시글_식별자값으로_러너_게시글_삭제에_실패한다() { | ||
final RunnerPost 러너_게시글 = runnerPostRepository.save(RunnerPostFixture.create( | ||
러너_디투, | ||
deadline(LocalDateTime.now().plusHours(100)), | ||
ReviewStatus.NOT_STARTED | ||
)); | ||
final Member 지원자_맴버 = memberRepository.save(MemberFixture.createHyena()); | ||
final Supporter 지원자_서포터 = supporterRepository.save(SupporterFixture.create(지원자_맴버)); | ||
supporterRunnerPostRepository.save(SupporterRunnerPostFixture.create(러너_게시글, 지원자_서포터)); | ||
|
||
RunnerPostAssuredSupport | ||
.클라이언트_요청() | ||
.토큰으로_로그인한다(로그인용_토큰) | ||
.러너_게시글_식별자값으로_러너_게시글을_삭제한다(러너_게시글.getId()) | ||
|
||
.서버_응답() | ||
.러너_게시글_삭제_실패를_검증한다(INTERNAL_SERVER_ERROR); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...d/baton/src/test/java/touch/baton/document/runnerpost/delete/RunnerPostDeleteApiTest.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,71 @@ | ||
package touch.baton.document.runnerpost.delete; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import touch.baton.config.RestdocsConfig; | ||
import touch.baton.domain.runner.Runner; | ||
import touch.baton.domain.runnerpost.RunnerPost; | ||
import touch.baton.domain.runnerpost.controller.RunnerPostController; | ||
import touch.baton.domain.runnerpost.service.RunnerPostService; | ||
import touch.baton.fixture.domain.MemberFixture; | ||
import touch.baton.fixture.domain.RunnerFixture; | ||
import touch.baton.fixture.domain.RunnerPostFixture; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.http.HttpHeaders.AUTHORIZATION; | ||
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; | ||
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; | ||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; | ||
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
import static touch.baton.fixture.vo.DeadlineFixture.deadline; | ||
|
||
@WebMvcTest(RunnerPostController.class) | ||
public class RunnerPostDeleteApiTest extends RestdocsConfig { | ||
|
||
@MockBean | ||
private RunnerPostService runnerPostService; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
final RunnerPostController runnerPostController = new RunnerPostController(runnerPostService); | ||
restdocsSetUp(runnerPostController); | ||
} | ||
|
||
@DisplayName("러너 게시글 삭제 API") | ||
@Test | ||
void deleteByRunnerPostId() throws Exception { | ||
// given | ||
final String socialId = "ditooSocialId"; | ||
final Runner runner = RunnerFixture.createRunner(MemberFixture.createWithSocialId(socialId)); | ||
final String token = getAccessTokenBySocialId(socialId); | ||
final RunnerPost runnerPost = RunnerPostFixture.create(runner, deadline(LocalDateTime.now().plusHours(100))); | ||
final RunnerPost spyRunnerPost = spy(runnerPost); | ||
|
||
// when | ||
when(oauthRunnerRepository.joinByMemberSocialId(any())).thenReturn(Optional.ofNullable(runner)); | ||
when(spyRunnerPost.getId()).thenReturn(1L); | ||
|
||
// then | ||
mockMvc.perform(delete("/api/v1/posts/runner/{runnerPostId}", 1L) | ||
.header(AUTHORIZATION, "Bearer " + token)) | ||
.andExpect(status().isNoContent()) | ||
.andDo(restDocs.document( | ||
requestHeaders( | ||
headerWithName(AUTHORIZATION).description("Bearer JWT") | ||
), | ||
pathParameters( | ||
parameterWithName("runnerPostId").description("러너 게시글 식별자값") | ||
) | ||
)); | ||
} | ||
} |
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
Oops, something went wrong.