Skip to content

Commit

Permalink
[test] PayAccountApiController의 충전 로직에 대한 테스트코드 추가
Browse files Browse the repository at this point in the history
- 일일 한도 100만원을 초과할 시 bad request를 응답하는것을 검증하는 테스트코드 추가
  • Loading branch information
Hyeon-Uk committed Aug 12, 2024
1 parent 3b4bf54 commit d73de81
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import camp.woowak.lab.payaccount.domain.PayAccount;
import camp.woowak.lab.payaccount.repository.PayAccountRepository;
import camp.woowak.lab.payaccount.service.PayAccountChargeService;
import camp.woowak.lab.payaccount.service.command.AccountTransactionCommand;
import camp.woowak.lab.web.dto.request.payaccount.PayAccountChargeRequest;
import jakarta.persistence.EntityManager;

Expand All @@ -32,6 +34,8 @@ class PayAccountApiControllerTest {
private MockMvc mvc;
@Autowired
private PayAccountRepository payAccountRepository;
@Autowired
private PayAccountChargeService payAccountChargeService;

@Autowired
private EntityManager em;
Expand Down Expand Up @@ -61,6 +65,8 @@ private void verificationPersistedBalance(Long payAccountId, long amount) {
@Nested
@DisplayName("충전 요청은")
class PayAccountChargeAPITest {
private final long DAILY_LIMIT = 1_000_000L;

@Test
@DisplayName("존재하는 계정 ID에 정상범위의 금액을 입력하면 충전된다.")
void successTest() throws Exception {
Expand All @@ -78,6 +84,21 @@ void successTest() throws Exception {
verificationPersistedBalance(payAccount.getId(), amount + originBalance);
}

@Test
@DisplayName("일일 한도(100만원) 이상인 경우, 400을 return한다.")
void dailyLimitExceededTest() throws Exception {
//given
long amount = 1000L;
payAccountChargeService.chargeAccount(new AccountTransactionCommand(payAccount.getId(), DAILY_LIMIT));
PayAccountChargeRequest command = new PayAccountChargeRequest(amount);

//when & then
mvc.perform(post(BASE_URL + payAccount.getId() + "/charge")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsBytes(command)))
.andExpect(status().isBadRequest());
}

//TODO : 아직 API Response Format이 정해지지 않았으므로, 논의 후 추가
@Test
@DisplayName("존재하지 않는 계정 ID를 입력하면 404를 return한다.")
Expand Down

0 comments on commit d73de81

Please sign in to comment.