Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] Hotfix/#619 핀 삭제 시 토픽의 핀 개수가 업데이트되지 않는 버그 해결 #621

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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