Добавил HTTP-тесты остатка на дату и обработки некорректных запросов
This commit is contained in:
1 parent
d6a548c7b7
commit
03004276af
1 file changed
+47
@@ -133,4 +133,51 @@ class AccountControllerTest {
|
|||||||
BigDecimal.class);
|
BigDecimal.class);
|
||||||
assertEquals(0, response.compareTo(new BigDecimal(15000)));
|
assertEquals(0, response.compareTo(new BigDecimal(15000)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void gettingAccountBalanceExcludesMovementsAfterRequestedDate() throws Exception {
|
||||||
|
// Given
|
||||||
|
LocalDate date = LocalDate.of(2026, 10, 25);
|
||||||
|
LocalDate dateAfter = LocalDate.of(2026, 10, 26);
|
||||||
|
Account account = accountService.create("Карта");
|
||||||
|
Operation openingBalance = operationService.createOpeningBalance(date, account, new BigDecimal(15000));
|
||||||
|
operationService.post(openingBalance.getId());
|
||||||
|
Operation openingBalanceLater = operationService.createOpeningBalance(dateAfter, account, new BigDecimal(10000));
|
||||||
|
operationService.post(openingBalanceLater.getId());
|
||||||
|
|
||||||
|
// When / Then
|
||||||
|
MvcResult result = mockMvc.perform(get("/api/accounts/{id}/balance", account.getId())
|
||||||
|
.param("date", date.toString()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andReturn();
|
||||||
|
|
||||||
|
BigDecimal response = objectMapper.readValue(result.getResponse().getContentAsString(),
|
||||||
|
BigDecimal.class);
|
||||||
|
assertEquals(0, response.compareTo(new BigDecimal(15000)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void gettingAccountBalanceByUnknownAccountReturnsNotFound() throws Exception {
|
||||||
|
// When / Then
|
||||||
|
mockMvc.perform(get("/api/accounts/{id}/balance", 999L)
|
||||||
|
.param("date", LocalDate.of(2026, 10, 28).toString()))
|
||||||
|
.andExpect(status().isNotFound())
|
||||||
|
.andExpect(jsonPath("$.status").value(404))
|
||||||
|
.andExpect(jsonPath("$.detail").value("Счет не найден: 999"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void gettingAccountBalanceWithInvalidDateFormatReturnsBadRequest() throws Exception {
|
||||||
|
// When / Then
|
||||||
|
mockMvc.perform(get("/api/accounts/{id}/balance", 1L)
|
||||||
|
.param("date", "28-10-2026"))
|
||||||
|
.andExpect(status().isBadRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void gettingAccountBalanceWithoutDateReturnsBadRequest() throws Exception {
|
||||||
|
// When / Then
|
||||||
|
mockMvc.perform(get("/api/accounts/{id}/balance", 1L))
|
||||||
|
.andExpect(status().isBadRequest());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user