@Test
public void 계좌출금_test() throws Exception {
Long amount = 1000L;
Long password = 1234L;
Long userId = 1L;
User ssar = newMockUser(1L, "ssar", "쌀");
Account ssarAccount = newMockAccount(1L, 1111L, 1000L, ssar);
if (amount <= 0L) {
throw new CustomApiException("0원 이하의 금액을 입금할 수 없습니다.");
}
ssarAccount.checkOwner(userId);
ssarAccount.checkSamePassword(password);
ssarAccount.withdraw(amount);
assertThat(ssarAccount.getBalance()).isEqualTo(0L);
}
@WithUserDetails(value = "ssar", setupBefore = TestExecutionEvent.TEST_EXECUTION)
@Test
public void withdrawAccount_test() throws Exception {
AccountWithdrawRequestDto accountWithdrawRequestDto = new AccountWithdrawRequestDto();
accountWithdrawRequestDto.setNumber(1111L);
accountWithdrawRequestDto.setPassword(1234L);
accountWithdrawRequestDto.setAmount(100L);
accountWithdrawRequestDto.setGubun("WITHDRAW");
String requestBody = om.writeValueAsString(accountWithdrawRequestDto);
System.out.println("테스트 : " + requestBody);
ResultActions resultActions = mvc
.perform(post("/api/s/account/withdraw").content(requestBody)
.contentType(MediaType.APPLICATION_JSON));
String responseBody = resultActions.andReturn().getResponse().getContentAsString();
System.out.println("테스트 : " + responseBody);
resultActions.andExpect(status().isCreated());
}
