-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
121 additions
and
6 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: 2 additions & 0 deletions
2
backend/src/main/java/shook/shook/my_part/domain/repository/MemberPartRepository.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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package shook.shook.my_part.domain.repository; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import shook.shook.my_part.domain.MemberPart; | ||
|
||
public interface MemberPartRepository extends JpaRepository<MemberPart, Long> { | ||
|
||
Optional<MemberPart> findByMemberIdAndId(final Long memberId, final Long memberPartId); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
|
@@ -13,7 +15,11 @@ | |
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import shook.shook.auth.application.TokenProvider; | ||
import shook.shook.member.domain.Member; | ||
import shook.shook.member.domain.repository.MemberRepository; | ||
import shook.shook.my_part.application.dto.MemberPartRegisterRequest; | ||
import shook.shook.my_part.domain.MemberPart; | ||
import shook.shook.my_part.domain.repository.MemberPartRepository; | ||
import shook.shook.song.domain.Song; | ||
import shook.shook.song.domain.repository.SongRepository; | ||
|
||
|
@@ -35,13 +41,20 @@ void setUp() { | |
@Autowired | ||
private SongRepository songRepository; | ||
|
||
@Autowired | ||
private MemberPartRepository memberPartRepository; | ||
|
||
@Autowired | ||
private MemberRepository memberRepository; | ||
|
||
@DisplayName("멤버의 파트를 등록 성공 시 201 상태 코드를 반환한다.") | ||
@Test | ||
void registerMemberPart() { | ||
// given | ||
final Song song = songRepository.findById(1L).get(); | ||
final Member member = memberRepository.findById(1L).get(); | ||
final MemberPartRegisterRequest request = new MemberPartRegisterRequest(5, 10); | ||
final String accessToken = tokenProvider.createAccessToken(1L, "nickname"); | ||
final String accessToken = tokenProvider.createAccessToken(member.getId(), member.getNickname()); | ||
|
||
// when | ||
// then | ||
|
@@ -52,4 +65,60 @@ void registerMemberPart() { | |
.when().log().all().post("/songs/{songId}/member-parts", song.getId()) | ||
.then().statusCode(HttpStatus.CREATED.value()); | ||
} | ||
|
||
@DisplayName("잘못된 정보로 파트를 등록 시 400 상태 코드를 반환한다.") | ||
@CsvSource({"-1, 10", "190, 15", "5, 25"}) | ||
@ParameterizedTest | ||
void register_failBadRequest(final int startSecond, final int length) { | ||
// given | ||
final Song song = songRepository.findById(1L).get(); | ||
final Member member = memberRepository.findById(1L).get(); | ||
final MemberPartRegisterRequest request = new MemberPartRegisterRequest(startSecond, length); | ||
final String accessToken = tokenProvider.createAccessToken(member.getId(), member.getNickname()); | ||
|
||
// when | ||
// then | ||
RestAssured.given().log().all() | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken) | ||
.body(request) | ||
.contentType(ContentType.JSON) | ||
.when().log().all().post("/songs/{songId}/member-parts", song.getId()) | ||
.then().statusCode(HttpStatus.BAD_REQUEST.value()); | ||
} | ||
|
||
@DisplayName("멤버 파트 삭제 성공 시 204 상태 코드를 반환한다.") | ||
@Test | ||
void delete() { | ||
// given | ||
final Song song = songRepository.findById(1L).get(); | ||
final Member member = memberRepository.findById(1L).get(); | ||
final String accessToken = tokenProvider.createAccessToken(member.getId(), member.getNickname()); | ||
final MemberPart memberPart = memberPartRepository.save(MemberPart.forSave(5, 10, song, member)); | ||
|
||
// when | ||
// then | ||
RestAssured.given().log().all() | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken) | ||
.when().log().all().delete("/member-parts/{memberPartId}", memberPart.getId()) | ||
.then().statusCode(HttpStatus.NO_CONTENT.value()); | ||
} | ||
|
||
@DisplayName("자신의 파트가 아닌 파트를 삭제하려고 시도할 시 403 상태 코드를 반환한다.") | ||
@Test | ||
void delete_failUnauthorizedMember() { | ||
// given | ||
final Song song = songRepository.findById(1L).get(); | ||
final Member member = memberRepository.findById(1L).get(); | ||
final MemberPart memberPart = memberPartRepository.save(MemberPart.forSave(5, 10, song, member)); | ||
final Member otherMember = memberRepository.save(new Member("[email protected]", "nickname")); | ||
final String otherMemberAccessToken = tokenProvider.createAccessToken(otherMember.getId(), | ||
otherMember.getNickname()); | ||
|
||
// when | ||
// then | ||
RestAssured.given().log().all() | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + otherMemberAccessToken) | ||
.when().log().all().delete("/member-parts/{memberPartId}", memberPart.getId()) | ||
.then().statusCode(HttpStatus.FORBIDDEN.value()); | ||
} | ||
} |