Skip to content

Commit

Permalink
fix: event 조회 시, 은행 이름과 계좌 번호가 분리되어 반환 (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
3Juhwan authored Sep 24, 2024
1 parent 0290f46 commit e0b5080
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

public record EventDetailAppResponse(
String eventName,
String account
String bankName,
String accountNumber
) {

public static EventDetailAppResponse of(Event event) {
return new EventDetailAppResponse(event.getName(), event.getAccount());
return new EventDetailAppResponse(event.getName(), event.getBankName(), event.getAccountNumber());
}
}
19 changes: 18 additions & 1 deletion server/src/main/java/server/haengdong/domain/event/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.util.Arrays;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -92,7 +93,23 @@ private void validateAccountNumber(String accountNumber) {
int accountLength = accountNumber.trim().length();
if (accountLength < MIN_ACCOUNT_NUMBER_LENGTH || MAX_ACCOUNT_NUMBER_LENGTH < accountLength) {
throw new HaengdongException(
HaengdongErrorCode.ACCOUNT_LENGTH_INVALID, MIN_ACCOUNT_NUMBER_LENGTH, MAX_ACCOUNT_NUMBER_LENGTH);
HaengdongErrorCode.ACCOUNT_LENGTH_INVALID, MIN_ACCOUNT_NUMBER_LENGTH, MAX_ACCOUNT_NUMBER_LENGTH);
}
}

public String getBankName() {
String[] bankNameAndAccountNumber = account.split(" ");
if (bankNameAndAccountNumber.length > 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 "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

public record EventDetailResponse(
String eventName,
String account
String bankName,
String accountNumber
) {

public static EventDetailResponse of(EventDetailAppResponse response) {
return new EventDetailResponse(response.eventName(), response.account());
return new EventDetailResponse(response.eventName(), response.bankName(), response.accountNumber());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ void updateEventTest() {
Event updateEvent = eventRepository.findByToken(event.getToken()).get();
assertAll(
() -> assertThat(updateEvent.getName()).isEqualTo("새로운 행사 이름"),
() -> assertThat(updateEvent.getAccount()).isEqualTo("토스뱅크 12345678")
() -> assertThat(updateEvent.getBankName()).isEqualTo("토스뱅크"),
() -> assertThat(updateEvent.getAccountNumber()).isEqualTo("12345678")
);
}

Expand All @@ -92,7 +93,8 @@ void updateEventTest1() {
Event updateEvent = eventRepository.findByToken(event.getToken()).get();
assertAll(
() -> assertThat(updateEvent.getName()).isEqualTo("행동대장 비대위"),
() -> assertThat(updateEvent.getAccount()).isEqualTo("토스뱅크 12345678")
() -> assertThat(updateEvent.getBankName()).isEqualTo("토스뱅크"),
() -> assertThat(updateEvent.getAccountNumber()).isEqualTo("12345678")
);
}

Expand All @@ -108,7 +110,8 @@ void updateEventTest2() {
Event updateEvent = eventRepository.findByToken(event.getToken()).get();
assertAll(
() -> assertThat(updateEvent.getName()).isEqualTo("행동대장 정상 영업"),
() -> assertThat(updateEvent.getAccount()).isEqualTo("")
() -> assertThat(updateEvent.getBankName()).isEqualTo(""),
() -> assertThat(updateEvent.getAccountNumber()).isEqualTo("")
);
}

Expand All @@ -124,7 +127,8 @@ void updateEventTest3() {
Event updateEvent = eventRepository.findByToken(event.getToken()).get();
assertAll(
() -> assertThat(updateEvent.getName()).isEqualTo("행동대장 비대위"),
() -> assertThat(updateEvent.getAccount()).isEqualTo("")
() -> assertThat(updateEvent.getBankName()).isEqualTo(""),
() -> assertThat(updateEvent.getAccountNumber()).isEqualTo("")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected Object initController() {
@Test
void findEventTest() throws Exception {
String eventId = "망쵸토큰";
EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스 12312455");
EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스뱅크", "12312455");
given(eventService.findEvent(eventId)).willReturn(eventDetailAppResponse);

mockMvc.perform(get("/api/events/{eventId}", eventId))
Expand All @@ -73,7 +73,8 @@ void findEventTest() throws Exception {
),
responseFields(
fieldWithPath("eventName").type(JsonFieldType.STRING).description("행사 이름"),
fieldWithPath("account").type(JsonFieldType.STRING).description("행사 계좌")
fieldWithPath("bankName").type(JsonFieldType.STRING).description("토스뱅크"),
fieldWithPath("accountNumber").type(JsonFieldType.STRING).description("12312455")
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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 org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -81,7 +82,10 @@ void changeAccountTest() {

event.changeAccount("토스뱅크", "12345678");

assertThat(event.getAccount()).isEqualTo("토스뱅크 12345678");
assertAll(
() -> assertThat(event.getBankName()).isEqualTo("토스뱅크"),
() -> assertThat(event.getAccountNumber()).isEqualTo("12345678")
);
}

@DisplayName("계좌 정보에 은행 이름과 계좌 번호가 모두 포함되지 않으면 예외가 발생한다.")
Expand Down Expand Up @@ -132,4 +136,30 @@ void changeAccountTest5(String accountNumber) {
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")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EventControllerTest extends ControllerTestSupport {
@Test
void findEventTest() throws Exception {
String eventId = "망쵸토큰";
EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스 1231245");
EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("행동대장 회식", "토스뱅크", "1231245");
given(eventService.findEvent(eventId)).willReturn(eventDetailAppResponse);

mockMvc.perform(get("/api/events/{eventId}", eventId))
Expand Down

0 comments on commit e0b5080

Please sign in to comment.