Skip to content

Commit

Permalink
fix: 장소 추천 범위 정상화 (#411)
Browse files Browse the repository at this point in the history
* fix: 장소 추천 범위 300m로 정상화

* test: 300미터 추천 못할 떄 테스트 보완
  • Loading branch information
dooboocookie authored and kokodak committed Oct 5, 2023
1 parent d03da84 commit 5d51c9e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

import static com.now.naaga.place.exception.PlaceExceptionType.NO_EXIST;

@Transactional
@Service
public class PlaceRecommendService {

private static final int DISTANCE = 500;
private static final double DISTANCE = 0.3;

private final PlaceRepository placeRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.now.naaga.place.service;

import com.now.naaga.common.builder.PlaceBuilder;
import com.now.naaga.common.exception.BaseExceptionType;
import com.now.naaga.common.fixture.PositionFixture;
import com.now.naaga.place.application.PlaceService;
import com.now.naaga.place.application.dto.RecommendPlaceCommand;
import com.now.naaga.place.domain.Place;
import com.now.naaga.place.domain.Position;
import com.now.naaga.place.exception.PlaceException;
import com.now.naaga.place.exception.PlaceExceptionType;
import io.restassured.internal.common.assertion.Assertion;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.SoftAssertions.assertSoftly;
import static org.junit.jupiter.api.Assertions.assertThrows;

@ActiveProfiles("test")
@Sql("/truncate.sql")
@SpringBootTest
class PlaceServiceTest {

@Autowired
PlaceService placeService;

@Autowired
PlaceBuilder placeBuilder;

@Transactional
@RepeatedTest(value = 10)
void 사용자로부터_300미터_이내의_장소_추천한다() {
//given
final Position 현재위치 = PositionFixture.잠실_루터회관_정문_근처_좌표;

final Position 잠실역교보문고좌표 = PositionFixture.잠실역_교보문고_좌표;
final Position 잠실루터회관정문좌표 = PositionFixture.잠실_루터회관_정문_좌표;
final Position 제주좌표 = PositionFixture.제주_좌표;

final Place 잠실역교보문고 = placeBuilder.init()
.position(잠실역교보문고좌표)
.build();
final Place 잠실루터회관정문 = placeBuilder.init()
.position(잠실루터회관정문좌표)
.build();
final Place 제주 = placeBuilder.init()
.position(제주좌표)
.build();

final RecommendPlaceCommand recommendPlaceCommand = new RecommendPlaceCommand(현재위치);

//when
final Place place = placeService.recommendPlaceByPosition(recommendPlaceCommand);

//then
assertSoftly(softAssertions -> {
assertThat(place).usingRecursiveComparison().isNotEqualTo(제주);
assertThat(place).usingRecursiveComparison().isIn(잠실루터회관정문, 잠실역교보문고);
});
}

@Test
void 사용자로부터_300미터_이내의_추천할_장소가_없으면_예외를_발생한다() {
//given
final Position 제주좌표 = PositionFixture.제주_좌표;

final Position 잠실역교보문고좌표 = PositionFixture.잠실역_교보문고_좌표;
final Position 잠실루터회관정문좌표 = PositionFixture.잠실_루터회관_정문_좌표;

final Place 잠실역교보문고 = placeBuilder.init()
.position(잠실역교보문고좌표)
.build();
final Place 잠실루터회관정문 = placeBuilder.init()
.position(잠실루터회관정문좌표)
.build();

final RecommendPlaceCommand recommendPlaceCommand = new RecommendPlaceCommand(제주좌표);

// when & then
assertSoftly(softAssertions -> {
final BaseExceptionType baseExceptionType = assertThrows(PlaceException.class, () -> placeService.recommendPlaceByPosition(recommendPlaceCommand)).exceptionType();
assertThat(baseExceptionType).isEqualTo(PlaceExceptionType.NO_EXIST);
});
}
}

0 comments on commit 5d51c9e

Please sign in to comment.