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

[FEAT] place service test #66

Merged
merged 4 commits into from
Nov 20, 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 @@ -10,7 +10,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class SurroundPlaceRequest {
private String x;
private String y;
private Double x;
private Double y;
private Integer page;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.twtw.backend.domain.place.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;

import com.twtw.backend.domain.place.dto.client.SurroundPlaceRequest;
import com.twtw.backend.domain.place.dto.client.SurroundPlaceResponse;
import com.twtw.backend.domain.place.dto.response.PlaceResponse;
import com.twtw.backend.domain.place.entity.Place;
import com.twtw.backend.domain.plan.dto.client.MetaDetails;
import com.twtw.backend.domain.plan.dto.client.PlaceDetails;
import com.twtw.backend.fixture.place.PlaceDetailsFixture;
import com.twtw.backend.fixture.place.PlaceEntityFixture;
import com.twtw.backend.global.client.KakaoMapClient;
import com.twtw.backend.support.service.LoginTest;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;

import java.util.List;

@DisplayName("PlaceService의")
class PlaceServiceTest extends LoginTest {

@Autowired private PlaceService placeService;

@MockBean
private KakaoMapClient<SurroundPlaceRequest, SurroundPlaceResponse> surroundPlaceClient;

@Test
@DisplayName("주변 장소 찾기가 수행되는가")
void searchSurroundPlace() {
// given
final SurroundPlaceResponse expected =
new SurroundPlaceResponse(
new MetaDetails(true),
List.of(PlaceDetailsFixture.FIRST_PLACE.toPlaceDetails()));
given(surroundPlaceClient.request(any())).willReturn(expected);

// when
final PlaceResponse result =
placeService.searchSurroundPlace(new SurroundPlaceRequest(1.1, 2.2, 1));

// then
assertThat(result.getResults()).hasSameElementsAs(expected.getDocuments());
assertThat(result.getIsLast()).isEqualTo(expected.getMeta().getIsEnd());
}

@Test
@DisplayName("Place 엔티티를 통한 dto 생성이 수행되는가")
void getPlaceDetails() {
// given
final Place place = PlaceEntityFixture.FIRST_PLACE.toEntity();

// when
final PlaceDetails placeDetails = placeService.getPlaceDetails(place);

// then
assertThat(placeDetails.getPlaceName()).isEqualTo(place.getPlaceName());
}

@Test
@DisplayName("Place dto를 통한 엔티티 생성이 수행되는가")
void getEntityByDetail() {
// given
final PlaceDetails placeDetails = PlaceDetailsFixture.SECOND_PLACE.toPlaceDetails();

// when
final Place place = placeService.getEntityByDetail(placeDetails);

// then
assertThat(place.getPlaceName()).isEqualTo(placeDetails.getPlaceName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ void savePlan() throws Exception {
UUID.randomUUID(),
new PlaceDetails(
"카페 온마이마인드",
"345",
345,
"https://place.map.kakao.com/1625295668",
"음식점 > 카페",
"경기 안성시 죽산면 죽산리 414",
"경기 안성시 죽산면 죽산초교길 36-4",
CategoryGroupCode.CE7,
"127.420430538256",
"37.0766874564297"))))
127.420430538256,
37.0766874564297))))
.header(
"Authorization",
"Bearer wefa3fsdczf32.gaoiuergf92.gb5hsa2jgh"));
Expand All @@ -147,14 +147,14 @@ void getPlanById() throws Exception {
UUID.randomUUID(),
new PlaceDetails(
"카페 온마이마인드",
"345",
345,
"https://place.map.kakao.com/1625295668",
"음식점 > 카페",
"경기 안성시 죽산면 죽산리 414",
"경기 안성시 죽산면 죽산초교길 36-4",
CategoryGroupCode.CE7,
"127.420430538256",
"37.0766874564297"),
127.420430538256,
37.0766874564297),
new GroupInfoResponse(
UUID.randomUUID(), UUID.randomUUID(), "홍담진", "http://someUrlToS3"),
List.of(new MemberResponse(UUID.randomUUID(), "진호정")));
Expand Down Expand Up @@ -215,14 +215,14 @@ void joinPlan() throws Exception {
UUID.randomUUID(),
new PlaceDetails(
"이디야커피 안성죽산점",
"435",
435,
"http://place.map.kakao.com/1562566188",
"음식점 > 카페 > 커피전문점 > 이디야커피",
"경기 안성시 죽산면 죽산리 118-3",
"경기 안성시 죽산면 죽주로 287-1",
CategoryGroupCode.CE7,
"127.426865189637",
"37.0764635355795"))))
127.426865189637,
37.0764635355795))))
.header(
"Authorization",
"Bearer wefa3fsdczf32.gaoiuergf92.gb5hsa2jgh"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.twtw.backend.fixture.group.GroupEntityFixture;
import com.twtw.backend.fixture.member.MemberEntityFixture;
import com.twtw.backend.fixture.place.PlaceDetailsFixture;
import com.twtw.backend.fixture.place.PlaceEntityFixture;
import com.twtw.backend.fixture.plan.PlanEntityFixture;
import com.twtw.backend.support.service.LoginTest;

Expand Down Expand Up @@ -51,7 +52,6 @@ void searchPlanDestination() {
@DisplayName("계획 저장이 수행되는가")
void savePlan() {
// given
final Plan plan = PlanEntityFixture.FIRST_PLACE.toEntity(loginUser);
final UUID groupId = groupRepository.save(GroupEntityFixture.HDJ_GROUP.toEntity()).getId();

// when
Expand All @@ -70,9 +70,8 @@ void savePlan() {
void joinPlan() {
// given
final Member member = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity());
final Plan plan = PlanEntityFixture.FIRST_PLACE.toEntity(member);
final Plan savedPlan = planRepository.save(plan);
final UUID planId = savedPlan.getId();
final Plan plan = planRepository.save(PlanEntityFixture.FIRST_PLACE.toEntity(member));
final UUID planId = plan.getId();

// when
planService.joinPlan(new PlanMemberRequest(planId));
Expand All @@ -98,11 +97,17 @@ void outPlan() {
}

@Test
@DisplayName("PK로 계획 조회가 수행되는가")
@DisplayName("PK로 계획 조회가 수행되는가") // TODO Fixture 사용하여 저장시 에러 확인
void getPlanById() {
// given
final Plan plan = PlanEntityFixture.FIRST_PLACE.toEntity(loginUser);
final UUID planId = planRepository.save(plan).getId();
final UUID planId =
planRepository
.save(
new Plan(
loginUser,
PlaceEntityFixture.SECOND_PLACE.toEntity(),
GroupEntityFixture.HDJ_GROUP.toEntity()))
.getId();

// when
final PlanInfoResponse result = planService.getPlanById(planId);
Expand All @@ -112,11 +117,17 @@ void getPlanById() {
}

@Test
@DisplayName("삭제가 수행되는가")
@DisplayName("삭제가 수행되는가") // TODO Fixture 사용하여 저장시 에러 확인
void deletePlan() {
// given
final Plan plan = PlanEntityFixture.SECOND_PLACE.toEntity(loginUser);
final UUID planId = planRepository.save(plan).getId();
final UUID planId =
planRepository
.save(
new Plan(
loginUser,
PlaceEntityFixture.SECOND_PLACE.toEntity(),
GroupEntityFixture.HDJ_GROUP.toEntity()))
.getId();

// when
planService.deletePlan(planId);
Expand Down