From 111ae511e3cede837ccd1ea35721c5834b54dabe Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Wed, 2 Oct 2024 16:06:51 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=EC=A4=91=EB=B3=B5=20=ED=88=AC?= =?UTF-8?q?=ED=91=9C=20=EC=A1=B0=ED=9A=8C=20=EC=97=AC=EB=B6=80=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20=ED=95=98=EB=82=98?= =?UTF-8?q?=EC=9D=98=20=EC=98=88=EC=99=B8=EB=A1=9C=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?#314?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../balance/roomvote/RoomBalanceVoteService.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java b/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java index 49cb930ce..ef0020535 100644 --- a/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java +++ b/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java @@ -11,6 +11,7 @@ import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,16 +24,11 @@ public class RoomBalanceVoteService { @Transactional public RoomBalanceVote createVote(Member member, BalanceOptions balanceOptions, Long votedOptionId) { - for (BalanceOption option : balanceOptions.getOptions()) { - validDuplicatedVote(member, option); - } BalanceOption votedOption = balanceOptions.getOptionById(votedOptionId); - return roomVoteRepository.save(new RoomBalanceVote(member, votedOption)); - } - - private void validDuplicatedVote(Member member, BalanceOption balanceOption) { - if (roomVoteRepository.existsByMemberAndBalanceOption(member, balanceOption)) { - throw new AlreadyVotedException(member.getNickname(), balanceOption.getName()); + try { + return roomVoteRepository.save(new RoomBalanceVote(member, votedOption)); + } catch (DataIntegrityViolationException e) { + throw new AlreadyVotedException(member.getNickname(), votedOption.getName()); } } From 063a656f87abc27c1a3ebcb9fb29f7329df54959 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Sat, 5 Oct 2024 18:56:14 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20=EC=A4=91=EB=B3=B5=20=ED=88=AC?= =?UTF-8?q?=ED=91=9C=20=EC=A1=B0=ED=9A=8C=20=EC=97=AC=EB=B6=80=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=8B=A4=EC=8B=9C=20=EC=B6=94=EA=B0=80=20=EB=B0=8F?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81=20#314=20-=20=EA=B0=99?= =?UTF-8?q?=EC=9D=80=20=EC=82=AC=EB=9E=8C=EC=9D=B4=202=EA=B0=80=EC=A7=80?= =?UTF-8?q?=20=EC=98=B5=EC=85=98=EC=9D=84=20=ED=88=AC=ED=91=9C=ED=95=9C=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=EC=97=90=EB=8A=94=20DataIntegrityViolationEx?= =?UTF-8?q?ception=20=EA=B0=80=20=EB=B0=9C=EC=83=9D=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EC=95=84=20=EB=8B=A4=EC=8B=9C=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../room/balance/roomvote/RoomBalanceVoteService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java b/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java index ef0020535..939443321 100644 --- a/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java +++ b/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java @@ -24,6 +24,7 @@ public class RoomBalanceVoteService { @Transactional public RoomBalanceVote createVote(Member member, BalanceOptions balanceOptions, Long votedOptionId) { + validDuplicatedVotes(member, balanceOptions); BalanceOption votedOption = balanceOptions.getOptionById(votedOptionId); try { return roomVoteRepository.save(new RoomBalanceVote(member, votedOption)); @@ -31,6 +32,16 @@ public RoomBalanceVote createVote(Member member, BalanceOptions balanceOptions, throw new AlreadyVotedException(member.getNickname(), votedOption.getName()); } } + private void validDuplicatedVotes(Member member, BalanceOptions balanceOptions) { + balanceOptions.getOptions() + .forEach(balanceOption -> validDuplicatedVote(member, balanceOption)); + } + + private void validDuplicatedVote(Member member, BalanceOption balanceOption) { + if (roomVoteRepository.existsByMemberAndBalanceOption(member, balanceOption)) { + throw new AlreadyVotedException(member.getNickname(), balanceOption.getName()); + } + } @Transactional(readOnly = true) public boolean isAllMemberVoted(RoomMembers roomMembers, BalanceOptions balanceOptions) { From 0d52b67365eed1e0a2f2b5bf6d16efe75ed9c8d9 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Sat, 5 Oct 2024 19:58:53 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EA=B8=B8=EC=9D=B4=20=EA=B2=80=EC=A6=9D=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?#314?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facade/room/dto/RoomJoinRequest.java | 4 +- .../roomvote/RoomBalanceVoteService.java | 1 + .../controller/room/RoomControllerTest.java | 59 ++++++++++++++++++- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java b/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java index c2295930a..3e2e39358 100644 --- a/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java +++ b/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java @@ -1,9 +1,11 @@ package ddangkong.facade.room.dto; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; public record RoomJoinRequest( @NotBlank + @Size(min = 2, max = 12) String nickname -) { // todo validation 닉네임 정책 +) { } diff --git a/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java b/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java index 939443321..39c1ca8dd 100644 --- a/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java +++ b/backend/src/main/java/ddangkong/service/room/balance/roomvote/RoomBalanceVoteService.java @@ -32,6 +32,7 @@ public RoomBalanceVote createVote(Member member, BalanceOptions balanceOptions, throw new AlreadyVotedException(member.getNickname(), votedOption.getName()); } } + private void validDuplicatedVotes(Member member, BalanceOptions balanceOptions) { balanceOptions.getOptions() .forEach(balanceOption -> validDuplicatedVote(member, balanceOption)); diff --git a/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java b/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java index 725f881ed..b8bc8b977 100644 --- a/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java +++ b/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; import ddangkong.controller.BaseControllerTest; +import ddangkong.controller.exception.ErrorResponse; import ddangkong.domain.balance.content.BalanceContent; import ddangkong.domain.balance.content.Category; import ddangkong.domain.room.Room; @@ -12,12 +13,13 @@ import ddangkong.domain.room.RoomStatus; import ddangkong.domain.room.balance.roomcontent.RoomContent; import ddangkong.domain.room.member.Member; +import ddangkong.exception.ClientErrorCode; import ddangkong.facade.room.dto.InitialRoomResponse; import ddangkong.facade.room.dto.RoomInfoResponse; import ddangkong.facade.room.dto.RoomJoinRequest; import ddangkong.facade.room.dto.RoomJoinResponse; -import ddangkong.facade.room.dto.RoomStatusResponse; import ddangkong.facade.room.dto.RoomSettingRequest; +import ddangkong.facade.room.dto.RoomStatusResponse; import ddangkong.facade.room.dto.RoundFinishedResponse; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -25,6 +27,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.http.HttpStatus; class RoomControllerTest extends BaseControllerTest { @@ -364,4 +368,57 @@ void setUp() { ); } } + + @Nested + class 닉네임_검증 { + + @Test + void 닉네임의_길이가_최대_길이_보다_길면_예외가_발생한다() { + // given + RoomJoinRequest request = new RoomJoinRequest("1234567890123"); + + // when + ErrorResponse errorResponse = RestAssured.given().log().all() + .body(request) + .contentType(ContentType.JSON) + .when().post("/api/balances/rooms") + .then().log().all() + .extract().as(ErrorResponse.class); + + // then + assertThat(errorResponse.errorCode()).isEqualTo(ClientErrorCode.FIELD_ERROR.name()); + } + + @Test + void 닉네임의_길이가_최소_길이_보다_작으면_예외가_발생한다() { + // given + RoomJoinRequest request = new RoomJoinRequest("1"); + + // when + ErrorResponse errorResponse = RestAssured.given().log().all() + .body(request) + .contentType(ContentType.JSON) + .when().post("/api/balances/rooms") + .then().log().all() + .extract().as(ErrorResponse.class); + + // then + assertThat(errorResponse.errorCode()).isEqualTo(ClientErrorCode.FIELD_ERROR.name()); + } + + @ParameterizedTest + @ValueSource(strings = {"12", "123", "1234567890", "123456789012"}) + void 닉네임의_길이가_기준_범위_안이면_예외가_발생하지_않는다(String name) { + // given + RoomJoinRequest request = new RoomJoinRequest(name); + + // when & then + RestAssured.given().log().all() + .body(request) + .contentType(ContentType.JSON) + .when().post("/api/balances/rooms") + .then().log().all() + .statusCode(HttpStatus.CREATED.value()); + } + } } From 7a4dc1399267b88a602df622a943a2e8e3775444 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Mon, 7 Oct 2024 19:37:37 +0900 Subject: [PATCH 4/6] =?UTF-8?q?test:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=20#314?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/room/RoomControllerTest.java | 86 ------------------- .../RoomContentControllerTest.java | 10 --- .../RoomBalanceVoteControllerTest.java | 38 -------- 3 files changed, 134 deletions(-) diff --git a/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java b/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java index b8bc8b977..a13abb5bc 100644 --- a/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java +++ b/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java @@ -214,38 +214,6 @@ class 방_나가기 { .then().log().all() .statusCode(204); } - - @Test - void 방_식별자가_0이하인_경우_예외를_발생한다() { - // given - Long roomId = 0L; - Long memberId = 1L; - - // when & then - RestAssured.given().log().all() - .contentType(ContentType.JSON) - .pathParam("roomId", roomId) - .pathParam("memberId", memberId) - .when().delete(ENDPOINT) - .then().log().all() - .statusCode(400); - } - - @Test - void 멤버_식별자가_0이하인_경우_예외를_발생한다() { - // given - Long roomId = 0L; - Long memberId = 1L; - - // when & then - RestAssured.given().log().all() - .contentType(ContentType.JSON) - .pathParam("roomId", roomId) - .pathParam("memberId", memberId) - .when().delete(ENDPOINT) - .then().log().all() - .statusCode(400); - } } @Nested @@ -262,16 +230,6 @@ class 게임_시작 { .then().log().all() .statusCode(204); } - - @Test - void 방의_식별자가_음수인_경우_예외를_던진다() { - // when & then - RestAssured.given().log().all() - .pathParam("roomId", -1L) - .when().patch("/api/balances/rooms/{roomId}/start") - .then().log().all() - .statusCode(400); - } } @Nested @@ -286,16 +244,6 @@ class 다음_라운드_진행 { .then().log().all() .statusCode(204); } - - @Test - void 방의_식별자가_음수인_경우_예외를_던진다() { - // when & then - RestAssured.given().log().all() - .pathParam("roomId", -1L) - .when().patch("/api/balances/rooms/{roomId}/next-round") - .then().log().all() - .statusCode(400); - } } @Nested @@ -372,40 +320,6 @@ void setUp() { @Nested class 닉네임_검증 { - @Test - void 닉네임의_길이가_최대_길이_보다_길면_예외가_발생한다() { - // given - RoomJoinRequest request = new RoomJoinRequest("1234567890123"); - - // when - ErrorResponse errorResponse = RestAssured.given().log().all() - .body(request) - .contentType(ContentType.JSON) - .when().post("/api/balances/rooms") - .then().log().all() - .extract().as(ErrorResponse.class); - - // then - assertThat(errorResponse.errorCode()).isEqualTo(ClientErrorCode.FIELD_ERROR.name()); - } - - @Test - void 닉네임의_길이가_최소_길이_보다_작으면_예외가_발생한다() { - // given - RoomJoinRequest request = new RoomJoinRequest("1"); - - // when - ErrorResponse errorResponse = RestAssured.given().log().all() - .body(request) - .contentType(ContentType.JSON) - .when().post("/api/balances/rooms") - .then().log().all() - .extract().as(ErrorResponse.class); - - // then - assertThat(errorResponse.errorCode()).isEqualTo(ClientErrorCode.FIELD_ERROR.name()); - } - @ParameterizedTest @ValueSource(strings = {"12", "123", "1234567890", "123456789012"}) void 닉네임의_길이가_기준_범위_안이면_예외가_발생하지_않는다(String name) { diff --git a/backend/src/test/java/ddangkong/controller/room/balance/roomcontent/RoomContentControllerTest.java b/backend/src/test/java/ddangkong/controller/room/balance/roomcontent/RoomContentControllerTest.java index 5149d8c89..4d1c8a5fa 100644 --- a/backend/src/test/java/ddangkong/controller/room/balance/roomcontent/RoomContentControllerTest.java +++ b/backend/src/test/java/ddangkong/controller/room/balance/roomcontent/RoomContentControllerTest.java @@ -38,15 +38,5 @@ class 현재_방의_내용_조회 { // then assertThat(actual).isEqualTo(EXPECTED_RESPONSE); } - - @Test - void 방의_식별자가_음수인_경우_예외를_던진다() { - // when & then - RestAssured.given().log().all() - .pathParam("roomId", -1L) - .when().get("/api/balances/rooms/{roomId}/content") - .then().log().all() - .statusCode(400); - } } } diff --git a/backend/src/test/java/ddangkong/controller/room/balance/roomvote/RoomBalanceVoteControllerTest.java b/backend/src/test/java/ddangkong/controller/room/balance/roomvote/RoomBalanceVoteControllerTest.java index f890dc893..e4aef0714 100644 --- a/backend/src/test/java/ddangkong/controller/room/balance/roomvote/RoomBalanceVoteControllerTest.java +++ b/backend/src/test/java/ddangkong/controller/room/balance/roomvote/RoomBalanceVoteControllerTest.java @@ -88,44 +88,6 @@ class 투표_생성 { // then assertThat(actual.optionId()).isEqualTo(optionA.getId()); } - - @Test - void 요청_경로의_아이디가_양수가_아닌_경우_400_에러로_응답한다() { - // given - RoomBalanceVoteRequest request = new RoomBalanceVoteRequest(keochan.getId(), optionA.getId()); - Long roomId = 0L; - - // when & then - assertThatCreateVoteIsBadRequest(roomId, balanceContent.getId(), request); - } - - @Test - void 요청_바디의_아이디가_양수가_아닌_경우_400_에러로_응답한다() { - // given - RoomBalanceVoteRequest request = new RoomBalanceVoteRequest(0L, optionA.getId()); - - // when & then - assertThatCreateVoteIsBadRequest(room.getId(), balanceContent.getId(), request); - } - - @Test - void 요청_바디의_아이디가_null인_경우_400_에러로_응답한다() { - // given - RoomBalanceVoteRequest request = new RoomBalanceVoteRequest(null, optionA.getId()); - - // when & then - assertThatCreateVoteIsBadRequest(room.getId(), balanceContent.getId(), request); - } - - void assertThatCreateVoteIsBadRequest(Long roomId, Long contentId, RoomBalanceVoteRequest request) { - RestAssured.given().log().all() - .body(request).contentType(ContentType.JSON) - .pathParam("roomId", roomId) - .pathParam("contentId", contentId) - .when().post("/api/balances/rooms/{roomId}/contents/{contentId}/votes") - .then().log().all() - .statusCode(400); - } } @Nested From d39dd9d61b9c09795fa583eef07b25e06c2adc3f Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Mon, 7 Oct 2024 21:03:58 +0900 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EA=B8=B8=EC=9D=B4=20=EA=B2=80=EC=A6=9D=EC=9D=84=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=EC=97=90=EC=84=9C=20=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=B6=94=EA=B0=80=20=20#314?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ddangkong/domain/room/member/Member.java | 11 +++++++++ .../ddangkong/exception/ClientErrorCode.java | 1 + .../room/member/InvalidNicknameException.java | 17 +++++++++++++ .../facade/room/dto/RoomJoinRequest.java | 2 +- .../controller/room/RoomControllerTest.java | 19 --------------- .../domain/room/member/MemberTest.java | 24 ++++++++++++++++++- 6 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 backend/src/main/java/ddangkong/exception/room/member/InvalidNicknameException.java diff --git a/backend/src/main/java/ddangkong/domain/room/member/Member.java b/backend/src/main/java/ddangkong/domain/room/member/Member.java index 3b0021b95..67496e63d 100644 --- a/backend/src/main/java/ddangkong/domain/room/member/Member.java +++ b/backend/src/main/java/ddangkong/domain/room/member/Member.java @@ -2,6 +2,7 @@ import ddangkong.domain.room.Room; import ddangkong.exception.room.member.AlreadyMasterException; +import ddangkong.exception.room.member.InvalidNicknameException; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -20,6 +21,9 @@ @Getter public class Member { + private static final int NICKNAME_MIN_LENGTH = 2; + private static final int NICKNAME_MAX_LENGTH = 12; + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -35,11 +39,18 @@ public class Member { private boolean isMaster; private Member(String nickname, Room room, boolean isMaster) { + validateNickname(nickname); this.nickname = nickname; this.room = room; this.isMaster = isMaster; } + private void validateNickname(String nickname) { + if (nickname.length() < NICKNAME_MIN_LENGTH || nickname.length() > NICKNAME_MAX_LENGTH) { + throw new InvalidNicknameException(NICKNAME_MIN_LENGTH, NICKNAME_MAX_LENGTH); + } + } + public static Member createMaster(String nickname, Room room) { return new Member(nickname, room, true); } diff --git a/backend/src/main/java/ddangkong/exception/ClientErrorCode.java b/backend/src/main/java/ddangkong/exception/ClientErrorCode.java index 951be2b92..ed13349cf 100644 --- a/backend/src/main/java/ddangkong/exception/ClientErrorCode.java +++ b/backend/src/main/java/ddangkong/exception/ClientErrorCode.java @@ -35,6 +35,7 @@ public enum ClientErrorCode { NOT_EXIST_COMMON("일반 멤버가 존재하지 않습니다."), EXCEED_MAX_MEMBER_COUNT("방의 최대 인원을 초과했습니다. 현재 멤버 수: %d"), NOT_ROOM_MEMBER("방에 존재하지 않는 멤버입니다."), + INVALID_NICKNAME("닉네임은 최소 %d글자, 최대 %d글자여야 합니다."), // RoomContent NOT_FOUND_ROOM_CONTENT("방에 존재하지 않는 컨텐츠입니다."), diff --git a/backend/src/main/java/ddangkong/exception/room/member/InvalidNicknameException.java b/backend/src/main/java/ddangkong/exception/room/member/InvalidNicknameException.java new file mode 100644 index 000000000..8cf27bc15 --- /dev/null +++ b/backend/src/main/java/ddangkong/exception/room/member/InvalidNicknameException.java @@ -0,0 +1,17 @@ +package ddangkong.exception.room.member; + +import static ddangkong.exception.ClientErrorCode.INVALID_NICKNAME; + +import ddangkong.exception.BadRequestException; + +public class InvalidNicknameException extends BadRequestException { + + public InvalidNicknameException(int minLength, int maxLength) { + super(INVALID_NICKNAME.getMessage().formatted(minLength, maxLength)); + } + + @Override + public String getErrorCode() { + return INVALID_NICKNAME.name(); + } +} diff --git a/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java b/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java index 3e2e39358..f8663038c 100644 --- a/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java +++ b/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java @@ -5,7 +5,7 @@ public record RoomJoinRequest( @NotBlank - @Size(min = 2, max = 12) + @Size(max = 255) String nickname ) { } diff --git a/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java b/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java index a13abb5bc..a372e5eb5 100644 --- a/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java +++ b/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java @@ -316,23 +316,4 @@ void setUp() { ); } } - - @Nested - class 닉네임_검증 { - - @ParameterizedTest - @ValueSource(strings = {"12", "123", "1234567890", "123456789012"}) - void 닉네임의_길이가_기준_범위_안이면_예외가_발생하지_않는다(String name) { - // given - RoomJoinRequest request = new RoomJoinRequest(name); - - // when & then - RestAssured.given().log().all() - .body(request) - .contentType(ContentType.JSON) - .when().post("/api/balances/rooms") - .then().log().all() - .statusCode(HttpStatus.CREATED.value()); - } - } } diff --git a/backend/src/test/java/ddangkong/domain/room/member/MemberTest.java b/backend/src/test/java/ddangkong/domain/room/member/MemberTest.java index 753fd01bf..7b96e43f3 100644 --- a/backend/src/test/java/ddangkong/domain/room/member/MemberTest.java +++ b/backend/src/test/java/ddangkong/domain/room/member/MemberTest.java @@ -1,14 +1,17 @@ package ddangkong.domain.room.member; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; import ddangkong.domain.room.Room; import ddangkong.domain.support.EntityTestUtils; -import ddangkong.exception.BadRequestException; import ddangkong.exception.room.member.AlreadyMasterException; +import ddangkong.exception.room.member.InvalidNicknameException; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; class MemberTest { @@ -63,4 +66,23 @@ class 일반_유저인지_확인 { assertThat(actual).isFalse(); } } + + @Nested + class 닉네임_검증 { + + @ParameterizedTest + @ValueSource(strings = {"01", "012345678912"}) + void 닉네임_길이가_유효한_경우_예외가_발생하지_않는다(String name) { + // when & then + assertThatNoException().isThrownBy(() -> Member.createMaster(name, ROOM)); + } + + @ParameterizedTest + @ValueSource(strings = {"0", "", "0123456789123"}) + void 닉네임_길이가_유효하지_않는_경우_예외를_발생시킨다(String name) { + // when & then + assertThatThrownBy(() -> Member.createMaster(name, ROOM)) + .isExactlyInstanceOf(InvalidNicknameException.class); + } + } } From ce5c1e7ef7cb21b17340a0e26327ecbbd7b7bab6 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Thu, 10 Oct 2024 10:58:10 +0900 Subject: [PATCH 6/6] =?UTF-8?q?feat:=20DTO=20=EC=B5=9C=EB=8C=80=20?= =?UTF-8?q?=EB=AC=B8=EC=9E=90=EC=97=B4=20=EA=B8=B8=EC=9D=B4=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EC=82=AD=EC=A0=9C=20#314?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/ddangkong/facade/room/dto/RoomJoinRequest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java b/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java index f8663038c..9de2647e6 100644 --- a/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java +++ b/backend/src/main/java/ddangkong/facade/room/dto/RoomJoinRequest.java @@ -1,11 +1,9 @@ package ddangkong.facade.room.dto; import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; public record RoomJoinRequest( @NotBlank - @Size(max = 255) String nickname ) { }