Skip to content

Commit

Permalink
Merge pull request #621 from woowacourse-teams/hotfix/#619
Browse files Browse the repository at this point in the history
[BE] Hotfix/#619 ํ•€ ์‚ญ์ œ ์‹œ ํ† ํ”ฝ์˜ ํ•€ ๊ฐœ์ˆ˜๊ฐ€ ์—…๋ฐ์ดํŠธ๋˜์ง€ ์•Š๋Š” ๋ฒ„๊ทธ ํ•ด๊ฒฐ
  • Loading branch information
yoondgu authored Nov 14, 2023
2 parents da2c754 + ad19450 commit 8f2395a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void deletePin(Long pinId) {
.orElseThrow(() -> new PinNotFoundException(PIN_NOT_FOUND, pinId));

pin.decreaseTopicPinCount();
pinRepository.flush();
pinImageRepository.deleteAllByPinId(pinId);
pinRepository.deleteById(pin.getId());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mapbefine.mapbefine.admin;

import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.HttpHeaders.AUTHORIZATION;

Expand All @@ -23,7 +23,8 @@
import com.mapbefine.mapbefine.topic.TopicFixture;
import com.mapbefine.mapbefine.topic.domain.Topic;
import com.mapbefine.mapbefine.topic.domain.TopicRepository;
import io.restassured.common.mapper.TypeRef;
import io.restassured.common.mapper.*;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -32,8 +33,6 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import java.util.List;

class AdminIntegrationTest extends IntegrationTest {

@Autowired
Expand Down Expand Up @@ -124,15 +123,13 @@ void findMemberDetail_Success() {
.extract()
.as(new TypeRef<>() {
});
System.out.println("====" + topic.getPinCount());
//then

//then
AdminMemberDetailResponse expected = AdminMemberDetailResponse.of(
member,
member.getCreatedTopics(),
member.getCreatedPins()
);

assertThat(response).usingRecursiveComparison()
.ignoringFields("updatedAt")
.ignoringFields("topics.updatedAt")
Expand Down Expand Up @@ -218,6 +215,9 @@ void deletePin_Success() {
.when().delete("/admin/pins/" + pin.getId())
.then().log().all()
.statusCode(HttpStatus.NO_CONTENT.value());

Topic updatedTopic = topicRepository.findById(topic.getId()).get();
assertThat(updatedTopic.getPinCount()).isEqualTo(0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ void deletePin_Success() {
assertThat(pinRepository.existsById(pin.getId())).isFalse();
}

@DisplayName("ํ•€ ์‚ญ์ œ ์‹œ, ํ† ํ”ฝ์˜ ํ•€ ๊ฐœ์ˆ˜๋ฅผ 1 ๊ฐ์†Œ์‹œํ‚จ๋‹ค.")
@Test
void deletePin_Success_decreaseTopicPinCount() {
//given
assertThat(pin.isDeleted()).isFalse();
int pinCountBeforeDelete = topic.getPinCount();

//when
adminCommandService.deletePin(pin.getId());

//then
assertThat(topic.getPinCount()).isEqualTo(pinCountBeforeDelete - 1);
}

@DisplayName("Admin์ธ ๊ฒฝ์šฐ, ํ•€ ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ•  ์ˆ˜ ์žˆ๋‹ค.")
@Test
void deletePinImage_Success() {
Expand Down

0 comments on commit 8f2395a

Please sign in to comment.