Skip to content

Commit

Permalink
fix: ๐Ÿ› ๋ชฉํ‘œ ๊ธˆ์•ก DELETE ์œ ์ฆˆ ์ผ€์ด์Šค ์ž˜๋ชป๋œ ํ•„ํ„ฐ๋ง ์ œ๊ฑฐ (#132)
Browse files Browse the repository at this point in the history
* fix: target-amount ์‚ญ์ œ ์š”์ฒญ ์‹œ, amount == -1์ธ ๊ฒฝ์šฐ ํ•„ํ„ฐ๋ง ๋กœ์ง ์ œ๊ฑฐ

* test: target amount์˜ ๊ฐ’์ด -1์ด์–ด๋„ is_read๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ true๋กœ ๋ฐ”๋€Œ์–ด์•ผ ํ•œ๋‹ค
  • Loading branch information
psychology50 authored Jul 15, 2024
1 parent 5c1964a commit 3bc5ea6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class TargetAmountDeleteService {
@Transactional
public void execute(Long targetAmountId) {
TargetAmount targetAmount = targetAmountService.readTargetAmount(targetAmountId)
.filter(TargetAmount::isAllocatedAmount)
.orElseThrow(() -> new TargetAmountErrorException(TargetAmountErrorCode.NOT_FOUND_TARGET_AMOUNT));

if (!targetAmount.isThatMonth()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.time.LocalDateTime;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
Expand Down Expand Up @@ -270,18 +271,21 @@ void deleteTargetAmountNotThatMonth() throws Exception {
}

@Test
@DisplayName("๋‹น์›” ๋ชฉํ‘œ ๊ธˆ์•ก pk์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์ด ์žˆ์ง€๋งŒ, amount๊ฐ€ ์ด๋ฏธ -1์ธ ๊ฒฝ์šฐ 404 Not Found ์—๋Ÿฌ ์‘๋‹ต์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.")
@Transactional
@DisplayName("๋‹น์›” ๋ชฉํ‘œ ๊ธˆ์•ก pk์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์ด ์žˆ์œผ๋ฉฐ, amount == -1์ด์–ด๋„ isRead๊ฐ€ true๋กœ ๋ณ€๊ฒฝ๋œ๋‹ค.")
void deleteTargetAmountNotFound() throws Exception {
// given
User user = userService.createUser(UserFixture.GENERAL_USER.toUser());
TargetAmount targetAmount = targetAmountService.createTargetAmount(TargetAmount.of(-1, user));
Long targetAmountId = targetAmount.getId();

// when
ResultActions result = performDeleteTargetAmount(targetAmount.getId(), user);

// then
result.andDo(print()).andExpect(status().isNotFound());
result.andDo(print()).andExpect(status().isOk());
TargetAmount deletedTargetAmount = targetAmountService.readTargetAmount(targetAmountId).orElseThrow();
assertEquals(-1, deletedTargetAmount.getAmount());
assertTrue(deletedTargetAmount.isRead());
}

@Test
Expand Down

0 comments on commit 3bc5ea6

Please sign in to comment.