diff --git a/server/src/main/java/haengdong/common/exception/HaengdongErrorCode.java b/server/src/main/java/haengdong/common/exception/HaengdongErrorCode.java index 68d0f4db..751a8616 100644 --- a/server/src/main/java/haengdong/common/exception/HaengdongErrorCode.java +++ b/server/src/main/java/haengdong/common/exception/HaengdongErrorCode.java @@ -32,6 +32,7 @@ public enum HaengdongErrorCode { IMAGE_NOT_FOUND("존재하지 않는 이미지 입니다."), IMAGE_COUNT_INVALID("이미지 수량은 %d개 까지 업로드할 수 있습니다."), + USER_NICK_NAME_LENGTH_INVALID("유저의 닉네임은 %d자 이상 %d자 이하만 입력 가능합니다."), /* Authentication */ diff --git a/server/src/main/java/haengdong/event/application/EventService.java b/server/src/main/java/haengdong/event/application/EventService.java index 45fce389..7794e72c 100644 --- a/server/src/main/java/haengdong/event/application/EventService.java +++ b/server/src/main/java/haengdong/event/application/EventService.java @@ -1,12 +1,8 @@ package haengdong.event.application; -import java.time.Instant; -import java.util.List; -import java.util.Map.Entry; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; +import haengdong.common.exception.AuthenticationException; +import haengdong.common.exception.HaengdongErrorCode; +import haengdong.common.exception.HaengdongException; import haengdong.event.application.request.EventAppRequest; import haengdong.event.application.request.EventGuestAppRequest; import haengdong.event.application.request.EventLoginAppRequest; @@ -16,20 +12,24 @@ import haengdong.event.application.response.EventImageAppResponse; import haengdong.event.application.response.EventImageSaveAppResponse; import haengdong.event.application.response.MemberBillReportAppResponse; +import haengdong.event.application.response.UserAppResponse; import haengdong.event.domain.RandomValueProvider; import haengdong.event.domain.bill.Bill; import haengdong.event.domain.bill.BillRepository; import haengdong.event.domain.bill.MemberBillReport; import haengdong.event.domain.event.Event; +import haengdong.event.domain.event.EventRepository; import haengdong.event.domain.event.image.EventImage; import haengdong.event.domain.event.image.EventImageRepository; -import haengdong.event.domain.event.EventRepository; import haengdong.event.domain.event.member.EventMember; import haengdong.event.domain.event.member.EventMemberRepository; -import haengdong.common.exception.AuthenticationException; -import haengdong.common.exception.HaengdongErrorCode; -import haengdong.common.exception.HaengdongException; import haengdong.user.application.UserService; +import java.time.Instant; +import java.util.List; +import java.util.Map.Entry; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor @Transactional(readOnly = true) @@ -45,9 +45,6 @@ public class EventService { private final EventMemberRepository eventMemberRepository; private final UserService userService; - @Value("${image.base-url}") - private String baseUrl; - @Transactional public EventAppResponse saveEventGuest(EventGuestAppRequest request) { Long userId = userService.joinGuest(request.toUserRequest()); @@ -73,8 +70,10 @@ public EventAppResponse saveEvent(EventAppRequest request) { public EventDetailAppResponse findEvent(String token) { Event event = getEvent(token); + Long userId = event.getUserId(); + UserAppResponse user = userService.findById(userId); - return EventDetailAppResponse.of(event); + return EventDetailAppResponse.of(event, user); } public EventAppResponse findByGuestPassword(EventLoginAppRequest request) { @@ -107,14 +106,9 @@ private MemberBillReportAppResponse createMemberBillReportResponse(Entry 0) { - return bankNameAndAccountNumber[0]; - } - return ""; - } - - public String getAccountNumber() { - String[] bankNameAndAccountNumber = account.split(" "); - if (bankNameAndAccountNumber.length > 1) { - return String.join(" ", Arrays.copyOfRange(bankNameAndAccountNumber, 1, bankNameAndAccountNumber.length)); - } - return ""; - } } diff --git a/server/src/main/java/haengdong/event/presentation/admin/AdminEventController.java b/server/src/main/java/haengdong/event/presentation/admin/AdminEventController.java index 83e6f3d9..d1175716 100644 --- a/server/src/main/java/haengdong/event/presentation/admin/AdminEventController.java +++ b/server/src/main/java/haengdong/event/presentation/admin/AdminEventController.java @@ -45,8 +45,7 @@ public ResponseEntity updateEvent( @PathVariable("eventId") String token, @Valid @RequestBody EventUpdateRequest request ) { - eventService.updateEvent(token, request.toAppRequest()); - + eventService.updateEventName(token, request.toAppRequest()); return ResponseEntity.ok().build(); } diff --git a/server/src/main/java/haengdong/event/presentation/request/EventUpdateRequest.java b/server/src/main/java/haengdong/event/presentation/request/EventUpdateRequest.java index 980809a2..37db577f 100644 --- a/server/src/main/java/haengdong/event/presentation/request/EventUpdateRequest.java +++ b/server/src/main/java/haengdong/event/presentation/request/EventUpdateRequest.java @@ -1,14 +1,14 @@ package haengdong.event.presentation.request; import haengdong.event.application.request.EventUpdateAppRequest; +import jakarta.validation.constraints.NotBlank; public record EventUpdateRequest( - String eventName, - String bankName, - String accountNumber + @NotBlank + String eventName ) { public EventUpdateAppRequest toAppRequest() { - return new EventUpdateAppRequest(eventName, bankName, accountNumber); + return new EventUpdateAppRequest(eventName); } } diff --git a/server/src/main/java/haengdong/event/presentation/response/EventDetailResponse.java b/server/src/main/java/haengdong/event/presentation/response/EventDetailResponse.java index 567528e3..8f7a1a4a 100644 --- a/server/src/main/java/haengdong/event/presentation/response/EventDetailResponse.java +++ b/server/src/main/java/haengdong/event/presentation/response/EventDetailResponse.java @@ -5,10 +5,11 @@ public record EventDetailResponse( String eventName, String bankName, - String accountNumber + String accountNumber, + Boolean createdByGuest ) { public static EventDetailResponse of(EventDetailAppResponse response) { - return new EventDetailResponse(response.eventName(), response.bankName(), response.accountNumber()); + return new EventDetailResponse(response.eventName(), response.bankName(), response.accountNumber(), response.createdByGuest()); } } diff --git a/server/src/main/java/haengdong/user/application/UserService.java b/server/src/main/java/haengdong/user/application/UserService.java index 411ed8f0..0e12f97c 100644 --- a/server/src/main/java/haengdong/user/application/UserService.java +++ b/server/src/main/java/haengdong/user/application/UserService.java @@ -3,6 +3,7 @@ import haengdong.common.exception.AuthenticationException; import haengdong.common.exception.HaengdongErrorCode; import haengdong.common.exception.HaengdongException; +import haengdong.event.application.response.UserAppResponse; import haengdong.user.application.request.UserGuestSaveAppRequest; import haengdong.user.application.request.UserUpdateAppRequest; import haengdong.user.domain.User; @@ -14,8 +15,8 @@ @RequiredArgsConstructor @Service public class UserService { - private final UserRepository userRepository; + private final KakaoClient kakaoClient; @Transactional @@ -66,6 +67,12 @@ public void withdraw(Long id) { userRepository.deleteById(id); } + public UserAppResponse findById(Long id) { + User user = getUser(id); + + return UserAppResponse.of(user); + } + private User getUser(Long id) { return userRepository.findById(id) .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.PASSWORD_INVALID)); diff --git a/server/src/main/java/haengdong/user/domain/User.java b/server/src/main/java/haengdong/user/domain/User.java index 438482d2..3173877f 100644 --- a/server/src/main/java/haengdong/user/domain/User.java +++ b/server/src/main/java/haengdong/user/domain/User.java @@ -1,6 +1,9 @@ package haengdong.user.domain; +import haengdong.event.domain.event.Password; +import jakarta.persistence.AttributeOverride; import jakarta.persistence.Column; +import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -21,6 +24,8 @@ public class User extends BaseEntity { private static final int MIN_ACCOUNT_NUMBER_LENGTH = 8; private static final int MAX_ACCOUNT_NUMBER_LENGTH = 30; + private static final int MIN_NICK_NAME_LENGTH = 1; + private static final int MAX_NICK_NAME_LENGTH = 8; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -29,7 +34,9 @@ public class User extends BaseEntity { @Column(nullable = false) private String nickname; - private String password; + @Embedded + @AttributeOverride(name = "value", column = @Column(name = "password")) + private Password password; private String bank; @@ -41,27 +48,38 @@ public class User extends BaseEntity { private User(String nickname, String password, String bank, String accountNumber, String memberNumber) { this.nickname = nickname; - this.password = password; + this.password = new Password(password); this.bank = bank; this.accountNumber = accountNumber; this.memberNumber = memberNumber; } public static User createGuest(String nickName, String password) { - return new User(nickName, password, null, null, null); + return new User(nickName, password, "", "", ""); } public static User createMember(String nickName, String memberNumber) { - return new User(nickName, null, null, null, memberNumber); + return new User(nickName, "0000", "", "", memberNumber); } public void changeNickname(String nickname) { + validateNickname(nickname); this.nickname = nickname; } + private void validateNickname(String nickname) { + int nicknameLength = nickname.trim().length(); + if (nicknameLength < MIN_NICK_NAME_LENGTH || MAX_NICK_NAME_LENGTH < nicknameLength) { + throw new HaengdongException( + HaengdongErrorCode.USER_NICK_NAME_LENGTH_INVALID, MIN_NICK_NAME_LENGTH, MAX_NICK_NAME_LENGTH); + } + } + public void changeAccount(String bankName, String accountNumber) { validateBankName(bankName); validateAccountNumber(accountNumber); + this.bank = bankName; + this.accountNumber = accountNumber; } private void validateBankName(String bankName) { @@ -79,4 +97,8 @@ private void validateAccountNumber(String accountNumber) { public boolean isPasswordMismatch(String rawPassword) { return !password.matches(rawPassword); } + + public boolean isGuest() { + return memberNumber == null || memberNumber.isBlank(); + } } diff --git a/server/src/test/java/haengdong/application/EventServiceTest.java b/server/src/test/java/haengdong/application/EventServiceTest.java index eb82a6b9..c59760e7 100644 --- a/server/src/test/java/haengdong/application/EventServiceTest.java +++ b/server/src/test/java/haengdong/application/EventServiceTest.java @@ -65,80 +65,29 @@ void saveEventGuestTest() { @DisplayName("토큰으로 행사를 조회한다.") @Test void findEventTest() { - Event event = Fixture.EVENT1; - eventRepository.save(event); - - EventDetailAppResponse eventDetailAppResponse = eventService.findEvent(event.getToken()); - - assertThat(eventDetailAppResponse.eventName()).isEqualTo(event.getName()); - } - - @DisplayName("행사 정보를 수정한다.") - @Test - void updateEventTest() { - Event event = new Event("행동대장 비대위", "1234", "token"); - eventRepository.save(event); - - EventUpdateAppRequest eventUpdateAppRequest = new EventUpdateAppRequest("새로운 행사 이름", "토스뱅크", "12345678"); - eventService.updateEvent(event.getToken(), eventUpdateAppRequest); - - Event updateEvent = eventRepository.findByToken(event.getToken()).get(); - assertAll( - () -> assertThat(updateEvent.getName()).isEqualTo("새로운 행사 이름"), - () -> assertThat(updateEvent.getBankName()).isEqualTo("토스뱅크"), - () -> assertThat(updateEvent.getAccountNumber()).isEqualTo("12345678") - ); - } - - @DisplayName("행사의 은행 정보만 수정한다.") - @Test - void updateEventTest1() { - Event event = new Event("행동대장 비대위", "1234", "token"); - eventRepository.save(event); - - EventUpdateAppRequest eventUpdateAppRequest = new EventUpdateAppRequest(null, "토스뱅크", "12345678"); - eventService.updateEvent(event.getToken(), eventUpdateAppRequest); - - Event updateEvent = eventRepository.findByToken(event.getToken()).get(); - assertAll( - () -> assertThat(updateEvent.getName()).isEqualTo("행동대장 비대위"), - () -> assertThat(updateEvent.getBankName()).isEqualTo("토스뱅크"), - () -> assertThat(updateEvent.getAccountNumber()).isEqualTo("12345678") - ); - } - - @DisplayName("행사의 이름만 수정한다.") - @Test - void updateEventTest2() { - Event event = new Event("행동대장 비대위", "1234", "token"); - eventRepository.save(event); + EventGuestAppRequest request = new EventGuestAppRequest("test", "nickname", "1234"); + given(randomValueProvider.createRandomValue()).willReturn("TOKEN"); + EventAppResponse response = eventService.saveEventGuest(request); - EventUpdateAppRequest eventUpdateAppRequest = new EventUpdateAppRequest("행동대장 정상 영업", null, null); - eventService.updateEvent(event.getToken(), eventUpdateAppRequest); + EventDetailAppResponse eventDetailAppResponse = eventService.findEvent("TOKEN"); - Event updateEvent = eventRepository.findByToken(event.getToken()).get(); assertAll( - () -> assertThat(updateEvent.getName()).isEqualTo("행동대장 정상 영업"), - () -> assertThat(updateEvent.getBankName()).isEqualTo(""), - () -> assertThat(updateEvent.getAccountNumber()).isEqualTo("") + () -> assertThat(eventDetailAppResponse.eventName()).isEqualTo("test"), + () -> assertThat(eventDetailAppResponse.createdByGuest()).isEqualTo(true) ); } - @DisplayName("행사의 계좌 정보 일부가 누락되면 변경하지 않는다.") + @DisplayName("행사 정보를 수정한다.") @Test - void updateEventTest3() { - Event event = new Event("행동대장 비대위", "1234", "token"); + void updateEventNameTest() { + Event event = new Event("행동대장 비대위", 1L, "token"); eventRepository.save(event); - EventUpdateAppRequest eventUpdateAppRequest = new EventUpdateAppRequest(null, "망쵸뱅크", null); - eventService.updateEvent(event.getToken(), eventUpdateAppRequest); + EventUpdateAppRequest eventUpdateAppRequest = new EventUpdateAppRequest("새로운 행사 이름"); + eventService.updateEventName(event.getToken(), eventUpdateAppRequest); Event updateEvent = eventRepository.findByToken(event.getToken()).get(); - assertAll( - () -> assertThat(updateEvent.getName()).isEqualTo("행동대장 비대위"), - () -> assertThat(updateEvent.getBankName()).isEqualTo(""), - () -> assertThat(updateEvent.getAccountNumber()).isEqualTo("") - ); + assertThat(updateEvent.getName()).isEqualTo("새로운 행사 이름"); } @DisplayName("참여자별 정산 현황을 조회한다.") diff --git a/server/src/test/java/haengdong/docs/AdminEventControllerDocsTest.java b/server/src/test/java/haengdong/docs/AdminEventControllerDocsTest.java index 0c70615c..8a8e73d9 100644 --- a/server/src/test/java/haengdong/docs/AdminEventControllerDocsTest.java +++ b/server/src/test/java/haengdong/docs/AdminEventControllerDocsTest.java @@ -75,7 +75,7 @@ void authenticateTest() throws Exception { @Test void updateEventTest() throws Exception { String token = "TOKEN"; - EventUpdateRequest eventUpdateRequest = new EventUpdateRequest("행동대장 비대위", "행대뱅크", "12345678"); + EventUpdateRequest eventUpdateRequest = new EventUpdateRequest("행동대장 비대위"); String requestBody = objectMapper.writeValueAsString(eventUpdateRequest); @@ -97,11 +97,7 @@ void updateEventTest() throws Exception { ), requestFields( fieldWithPath("eventName").type(JsonFieldType.STRING) - .description("수정할 이벤트 이름").optional(), - fieldWithPath("bankName").type(JsonFieldType.STRING) - .description("은행 이름").optional(), - fieldWithPath("accountNumber").type(JsonFieldType.STRING) - .description("계좌 번호").optional() + .description("수정할 이벤트 이름").optional() ) ) ); diff --git a/server/src/test/java/haengdong/docs/EventControllerDocsTest.java b/server/src/test/java/haengdong/docs/EventControllerDocsTest.java index 6087648a..bb22a382 100644 --- a/server/src/test/java/haengdong/docs/EventControllerDocsTest.java +++ b/server/src/test/java/haengdong/docs/EventControllerDocsTest.java @@ -60,7 +60,7 @@ protected Object initController() { @Test void findEventTest() throws Exception { String eventId = "망쵸토큰"; - EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스뱅크", "12312455"); + EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스뱅크", "12312455", true); given(eventService.findEvent(eventId)).willReturn(eventDetailAppResponse); mockMvc.perform(get("/api/events/{eventId}", eventId)) @@ -77,7 +77,8 @@ void findEventTest() throws Exception { responseFields( fieldWithPath("eventName").type(JsonFieldType.STRING).description("행사 이름"), fieldWithPath("bankName").type(JsonFieldType.STRING).description("토스뱅크"), - fieldWithPath("accountNumber").type(JsonFieldType.STRING).description("12312455") + fieldWithPath("accountNumber").type(JsonFieldType.STRING).description("12312455"), + fieldWithPath("createdByGuest").type(JsonFieldType.BOOLEAN).description(true) ) ) ); diff --git a/server/src/test/java/haengdong/domain/event/EventTest.java b/server/src/test/java/haengdong/domain/event/EventTest.java index dc981049..c0d607da 100644 --- a/server/src/test/java/haengdong/domain/event/EventTest.java +++ b/server/src/test/java/haengdong/domain/event/EventTest.java @@ -2,15 +2,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertAll; +import haengdong.common.exception.HaengdongException; +import haengdong.event.domain.event.Event; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import haengdong.event.domain.event.Event; -import haengdong.common.exception.HaengdongException; class EventTest { @@ -18,7 +16,7 @@ class EventTest { @ParameterizedTest @ValueSource(strings = {"12", "12345678901234567890", "공 백", " 공백", "공백 ", " 공 백 "}) void createSuccessTest(String eventName) { - assertThatCode(() -> new Event(eventName, "1234", "TEST_TOKEN")) + assertThatCode(() -> new Event(eventName, 1L, "TEST_TOKEN")) .doesNotThrowAnyException(); } @@ -26,7 +24,7 @@ void createSuccessTest(String eventName) { @ParameterizedTest @ValueSource(strings = {" 공백", "공백 ", "공백 연속", "공 백"}) void createFailTest1(String eventName) { - assertThatCode(() -> new Event(eventName, "1234", "TEST_TOKEN")) + assertThatCode(() -> new Event(eventName, 1L, "TEST_TOKEN")) .isInstanceOf(HaengdongException.class) .hasMessage("행사 이름에는 공백 문자가 연속될 수 없습니다."); } @@ -35,132 +33,18 @@ void createFailTest1(String eventName) { @ParameterizedTest @ValueSource(strings = {"", " ", "123456789012345678901"}) void createFilTest2(String eventName) { - assertThatCode(() -> new Event(eventName, "1234", "TEST_TOKEN")) + assertThatCode(() -> new Event(eventName, 1L, "TEST_TOKEN")) .isInstanceOf(HaengdongException.class) .hasMessage("행사 이름은 1자 이상 20자 이하만 입력 가능합니다."); } - @DisplayName("비밀번호는 4자리 숫자 입니다.") - @ParameterizedTest - @ValueSource(strings = {"1", "12", "123", "12345", "adgd"}) - void validatePassword(String password) { - assertThatCode(() -> new Event("이름", password, "TEST_TOKEN")) - .isInstanceOf(HaengdongException.class); - } - - @DisplayName("비밀번호가 다른지 검증한다.") - @Test - void isNotSamePassword() { - String rawPassword = "1234"; - Event event = new Event("이름", rawPassword, "TEST_TOKEN"); - - assertThat(event.isPasswordMismatch(rawPassword)).isFalse(); - } - - @DisplayName("비밀번호가 다른지 검증한다.") - @Test - void isNotSamePassword1() { - String rawPassword = "1234"; - Event event = new Event("이름", "5678", "TEST_TOKEN"); - - assertThat(event.isPasswordMismatch(rawPassword)).isTrue(); - } - @DisplayName("이름을 수정한다.") @Test void renameTest() { - Event event = new Event("이름", "1234", "TEST_TOKEN"); + Event event = new Event("이름", 1L, "TEST_TOKEN"); event.rename("새로운 이름"); assertThat(event.getName()).isEqualTo("새로운 이름"); } - - @DisplayName("계좌 정보에 은행 이름과 계좌 번호가 모두 포함된다.") - @Test - void changeAccountTest() { - Event event = new Event("이름", "1234", "TEST_TOKEN"); - - event.changeAccount("토스뱅크", "12345678"); - - assertAll( - () -> assertThat(event.getBankName()).isEqualTo("토스뱅크"), - () -> assertThat(event.getAccountNumber()).isEqualTo("12345678") - ); - } - - @DisplayName("계좌 정보에 은행 이름과 계좌 번호가 모두 포함되지 않으면 예외가 발생한다.") - @Test - void changeAccountTest1() { - Event event = new Event("이름", "1234", "TEST_TOKEN"); - - assertThatThrownBy(() -> event.changeAccount("행대뱅크", "")) - .isInstanceOf(HaengdongException.class); - } - - @DisplayName("지원하는 은행이면 예외가 발생하지 않는다.") - @ParameterizedTest - @ValueSource(strings = {"토스뱅크", "KB국민은행"}) - void changeAccountTest2(String bankName) { - Event event = new Event("이름", "1234", "TEST_TOKEN"); - - assertThatCode(() -> event.changeAccount(bankName, "12345678")) - .doesNotThrowAnyException(); - } - - @DisplayName("지원하지 않는 은행이면 예외가 발생한다.") - @ParameterizedTest - @ValueSource(strings = {"행대뱅크", "토스 뱅크", "망쵸뱅크", "KB 국민은행"}) - void changeAccountTest3(String bankName) { - Event event = new Event("이름", "1234", "TEST_TOKEN"); - - assertThatThrownBy(() -> event.changeAccount(bankName, "12345678")) - .isInstanceOf(HaengdongException.class); - } - - @DisplayName("계좌 번호가 8자 이상 30자 이하면 예외가 발생하지 않는다.") - @ParameterizedTest - @ValueSource(strings = {"12345678", "123456789012345678901234567890"}) - void changeAccountTest4(String accountNumber) { - Event event = new Event("이름", "1234", "TEST_TOKEN"); - - assertThatCode(() -> event.changeAccount("토스뱅크", accountNumber)) - .doesNotThrowAnyException(); - } - - @DisplayName("계좌 번호가 8자 미만 30자 초과면 예외가 발생한다.") - @ParameterizedTest - @ValueSource(strings = {"", " ", "1234567", "1234567890123456789012345678901"}) - void changeAccountTest5(String accountNumber) { - Event event = new Event("이름", "1234", "TEST_TOKEN"); - - assertThatThrownBy(() -> event.changeAccount("토스뱅크", accountNumber)) - .isInstanceOf(HaengdongException.class); - } - - @DisplayName("계좌 정보를 조회한다.") - @Test - void getBankNameTest() { - Event event = new Event("이름", "1234", "TEST_TOKEN"); - - event.changeAccount("토스뱅크", "12345678"); - - assertAll( - () -> assertThat(event.getBankName()).isEqualTo("토스뱅크"), - () -> assertThat(event.getAccountNumber()).isEqualTo("12345678") - ); - } - - @DisplayName("계좌 번호에 공백이 있어도 계좌 정보를 정상적으로 조회한다.") - @Test - void getBankNameTest1() { - Event event = new Event("이름", "1234", "TEST_TOKEN"); - - event.changeAccount("토스뱅크", "1234 5678 9012"); - - assertAll( - () -> assertThat(event.getBankName()).isEqualTo("토스뱅크"), - () -> assertThat(event.getAccountNumber()).isEqualTo("1234 5678 9012") - ); - } } diff --git a/server/src/test/java/haengdong/domain/eventmember/UpdatedMembersTest.java b/server/src/test/java/haengdong/domain/eventmember/UpdatedMembersTest.java index 3979d02a..0c87c372 100644 --- a/server/src/test/java/haengdong/domain/eventmember/UpdatedMembersTest.java +++ b/server/src/test/java/haengdong/domain/eventmember/UpdatedMembersTest.java @@ -17,7 +17,7 @@ class UpdatedMembersTest { @DisplayName("이벤트 이름들은 중복될 수 없다.") @Test void validateNameUnique() { - Event event = new Event("행동대장 회식", "1234", "1231415jaksdf"); + Event event = new Event("행동대장 회식", 1L, "1231415jaksdf"); List eventMembers = List.of( new EventMember(1L, event, "고구마", false), new EventMember(2L, event, "감자", false), @@ -32,7 +32,7 @@ void validateNameUnique() { @DisplayName("이벤트 회원들은 중복될 수 없다.") @Test void validateMemberUnique() { - Event event = new Event("행동대장 회식", "1234", "1231415jaksdf"); + Event event = new Event("행동대장 회식", 1L, "1231415jaksdf"); EventMember eventMember1 = new EventMember(1L, event, "고구마", false); EventMember eventMember2 = new EventMember(2L, event, "감자", false); List eventMembers = List.of(eventMember1, eventMember2, eventMember2); @@ -46,7 +46,7 @@ void validateMemberUnique() { @DisplayName("이벤트 이름들로 이벤트 참여자들을 생성한다.") @Test void create() { - Event event = new Event("행동대장 회식", "1234", "1231415jaksdf"); + Event event = new Event("행동대장 회식", 1L, "1231415jaksdf"); EventMember eventMember1 = new EventMember(1L, event, "고구마", false); EventMember eventMember2 = new EventMember(2L, event, "감자", false); EventMember eventMember3 = new EventMember(3L, event, "당근", false); @@ -60,7 +60,7 @@ void create() { @DisplayName("이벤트의 참여자들 전체가 존재하지 않으면 업데이트할 수 없다.") @Test void validateUpdatedMembersExist() { - Event event = new Event("행동대장 회식", "1234", "1231415jaksdf"); + Event event = new Event("행동대장 회식", 1L, "1231415jaksdf"); EventMember eventMember1 = new EventMember(1L, event, "고구마", false); EventMember eventMember2 = new EventMember(2L, event, "감자", false); EventMember eventMember3 = new EventMember(3L, event, "당근", false); @@ -81,7 +81,7 @@ void validateUpdatedMembersExist() { @DisplayName("업데이트할 이름 중에 기존 이벤트의 참여자들의 이름과 중복되면 업데이트할 수 없다.") @Test void validateUpdatedNamesUnique() { - Event event = new Event("행동대장 회식", "1234", "1231415jaksdf"); + Event event = new Event("행동대장 회식", 1L, "1231415jaksdf"); EventMember eventMember1 = new EventMember(1L, event, "고구마", false); EventMember eventMember2 = new EventMember(2L, event, "감자", false); EventMember eventMember3 = new EventMember(3L, event, "당근", false); @@ -103,7 +103,7 @@ void validateUpdatedNamesUnique() { @DisplayName("이벤트의 참여자들 전체를 업데이트 검증한다.") @Test void validateUpdatable() { - Event event = new Event("행동대장 회식", "1234", "1231415jaksdf"); + Event event = new Event("행동대장 회식", 1L, "1231415jaksdf"); EventMember eventMember1 = new EventMember(1L, event, "고구마", false); EventMember eventMember2 = new EventMember(2L, event, "감자", false); EventMember eventMember3 = new EventMember(3L, event, "당근", false); diff --git a/server/src/test/java/haengdong/presentation/EventControllerTest.java b/server/src/test/java/haengdong/presentation/EventControllerTest.java index 056a5b5b..50abe361 100644 --- a/server/src/test/java/haengdong/presentation/EventControllerTest.java +++ b/server/src/test/java/haengdong/presentation/EventControllerTest.java @@ -30,7 +30,7 @@ class EventControllerTest extends ControllerTestSupport { @Test void findEventTest() throws Exception { String eventId = "망쵸토큰"; - EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스뱅크", "1231245"); + EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스뱅크", "1231245", true); given(eventService.findEvent(eventId)).willReturn(eventDetailAppResponse); mockMvc.perform(get("/api/events/{eventId}", eventId)) diff --git a/server/src/test/java/haengdong/presentation/admin/AdminEventControllerTest.java b/server/src/test/java/haengdong/presentation/admin/AdminEventControllerTest.java index b36476e0..cb13b1ad 100644 --- a/server/src/test/java/haengdong/presentation/admin/AdminEventControllerTest.java +++ b/server/src/test/java/haengdong/presentation/admin/AdminEventControllerTest.java @@ -20,7 +20,7 @@ class AdminEventControllerTest extends ControllerTestSupport { @Test void updateEventTest() throws Exception { String token = "TOKEN"; - EventUpdateRequest eventUpdateRequest = new EventUpdateRequest("행동대장 비대위", "행대뱅크", "12345678"); + EventUpdateRequest eventUpdateRequest = new EventUpdateRequest("행동대장 비대위"); String requestBody = objectMapper.writeValueAsString(eventUpdateRequest); diff --git a/server/src/test/java/haengdong/support/fixture/Fixture.java b/server/src/test/java/haengdong/support/fixture/Fixture.java index 93ed52ad..97ea6c1e 100644 --- a/server/src/test/java/haengdong/support/fixture/Fixture.java +++ b/server/src/test/java/haengdong/support/fixture/Fixture.java @@ -7,8 +7,8 @@ public class Fixture { - public static final Event EVENT1 = new Event("쿠키", "1234", "TOKEN1"); - public static final Event EVENT2 = new Event("웨디", "1234", "TOKEN2"); + public static final Event EVENT1 = new Event("쿠키", 1L, "TOKEN1"); + public static final Event EVENT2 = new Event("웨디", 1L, "TOKEN2"); public static final Cookie EVENT_COOKIE = new Cookie("accessToken", "토큰토큰"); public static final EventMember EVENT_MEMBER_1 = new EventMember(EVENT1, "토다리"); public static final EventMember EVENT_MEMBER_2 = new EventMember(EVENT1, "쿠키"); diff --git a/server/src/test/java/haengdong/user/domain/UserTest.java b/server/src/test/java/haengdong/user/domain/UserTest.java new file mode 100644 index 00000000..c739df0e --- /dev/null +++ b/server/src/test/java/haengdong/user/domain/UserTest.java @@ -0,0 +1,103 @@ +package haengdong.user.domain; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; + +import haengdong.common.exception.HaengdongException; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +class UserTest { + + @DisplayName("계좌 정보에 은행 이름과 계좌 번호가 모두 포함된다.") + @Test + void changeAccountTest() { + User user = User.createGuest("이름", "1234"); + + user.changeAccount("토스뱅크", "12345678"); + + assertAll( + () -> assertThat(user.getBank()).isEqualTo("토스뱅크"), + () -> assertThat(user.getAccountNumber()).isEqualTo("12345678") + ); + } + + @DisplayName("계좌 정보에 은행 이름과 계좌 번호가 모두 포함되지 않으면 예외가 발생한다.") + @Test + void changeAccountTest1() { + User user = User.createGuest("이름", "1234"); + + assertThatThrownBy(() -> user.changeAccount("행대뱅크", "")) + .isInstanceOf(HaengdongException.class); + } + + @DisplayName("지원하는 은행이면 예외가 발생하지 않는다.") + @ParameterizedTest + @ValueSource(strings = {"토스뱅크", "KB국민은행"}) + void changeAccountTest2(String bankName) { + User user = User.createGuest("이름", "1234"); + + assertThatCode(() -> user.changeAccount(bankName, "12345678")) + .doesNotThrowAnyException(); + } + + @DisplayName("지원하지 않는 은행이면 예외가 발생한다.") + @ParameterizedTest + @ValueSource(strings = {"행대뱅크", "토스 뱅크", "망쵸뱅크", "KB 국민은행"}) + void changeAccountTest3(String bankName) { + User user = User.createGuest("이름", "1234"); + + assertThatThrownBy(() -> user.changeAccount(bankName, "12345678")) + .isInstanceOf(HaengdongException.class); + } + + @DisplayName("계좌 번호가 8자 이상 30자 이하면 예외가 발생하지 않는다.") + @ParameterizedTest + @ValueSource(strings = {"12345678", "123456789012345678901234567890"}) + void changeAccountTest4(String accountNumber) { + User user = User.createGuest("이름", "1234"); + + assertThatCode(() -> user.changeAccount("토스뱅크", accountNumber)) + .doesNotThrowAnyException(); + } + + @DisplayName("계좌 번호가 8자 미만 30자 초과면 예외가 발생한다.") + @ParameterizedTest + @ValueSource(strings = {"", " ", "1234567", "1234567890123456789012345678901"}) + void changeAccountTest5(String accountNumber) { + User user = User.createGuest("이름", "1234"); + + assertThatThrownBy(() -> user.changeAccount("토스뱅크", accountNumber)) + .isInstanceOf(HaengdongException.class); + } + + @DisplayName("계좌 정보를 조회한다.") + @Test + void getBankNameTest() { + User user = User.createGuest("이름", "1234"); + + user.changeAccount("토스뱅크", "12345678"); + + assertAll( + () -> assertThat(user.getBank()).isEqualTo("토스뱅크"), + () -> assertThat(user.getAccountNumber()).isEqualTo("12345678") + ); + } + + @DisplayName("계좌 번호에 공백이 있어도 계좌 정보를 정상적으로 조회한다.") + @Test + void getBankNameTest1() { + User user = User.createGuest("이름", "1234"); + + user.changeAccount("토스뱅크", "1234 5678 9012"); + + assertAll( + () -> assertThat(user.getBank()).isEqualTo("토스뱅크"), + () -> assertThat(user.getAccountNumber()).isEqualTo("1234 5678 9012") + ); + } +}