-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from HongDam-org/feat/plan-service-test
[FEAT] plan service test
- Loading branch information
Showing
12 changed files
with
213 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/twtw/backend/domain/plan/exception/InvalidPlanMemberException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.twtw.backend.domain.plan.exception; | ||
|
||
public class InvalidPlanMemberException extends IllegalArgumentException { | ||
|
||
private static final String MESSAGE = "계획에 추가되지 않은 멤버입니다."; | ||
|
||
public InvalidPlanMemberException() { | ||
super(MESSAGE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
backend/src/test/java/com/twtw/backend/domain/plan/service/PlanServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package com.twtw.backend.domain.plan.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.twtw.backend.domain.group.repository.GroupRepository; | ||
import com.twtw.backend.domain.member.entity.Member; | ||
import com.twtw.backend.domain.place.entity.CategoryGroupCode; | ||
import com.twtw.backend.domain.plan.dto.client.SearchDestinationRequest; | ||
import com.twtw.backend.domain.plan.dto.request.PlanMemberRequest; | ||
import com.twtw.backend.domain.plan.dto.request.SavePlanRequest; | ||
import com.twtw.backend.domain.plan.dto.response.PlanDestinationResponse; | ||
import com.twtw.backend.domain.plan.dto.response.PlanInfoResponse; | ||
import com.twtw.backend.domain.plan.dto.response.PlanResponse; | ||
import com.twtw.backend.domain.plan.entity.Plan; | ||
import com.twtw.backend.domain.plan.repository.PlanRepository; | ||
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.plan.PlanEntityFixture; | ||
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 java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@DisplayName("PlanService의") | ||
class PlanServiceTest extends LoginTest { | ||
|
||
@Autowired private PlanService planService; | ||
@Autowired private GroupRepository groupRepository; | ||
@Autowired private PlanRepository planRepository; | ||
|
||
@Test | ||
@DisplayName("목적지 검색이 수행되는가") | ||
void searchPlanDestination() { | ||
// given | ||
final SearchDestinationRequest given = | ||
new SearchDestinationRequest("스타벅스", 123.321, 123.123, 1, CategoryGroupCode.CE7); | ||
|
||
// when | ||
final PlanDestinationResponse result = planService.searchPlanDestination(given); | ||
|
||
// then | ||
assertThat(result.getResults()).isNotNull(); | ||
} | ||
|
||
@Test | ||
@DisplayName("계획 저장이 수행되는가") | ||
void savePlan() { | ||
// given | ||
final Plan plan = PlanEntityFixture.FIRST_PLACE.toEntity(loginUser); | ||
final UUID groupId = groupRepository.save(GroupEntityFixture.HDJ_GROUP.toEntity()).getId(); | ||
|
||
// when | ||
final PlanResponse planResponse = | ||
planService.savePlan( | ||
new SavePlanRequest( | ||
groupId, PlaceDetailsFixture.FIRST_PLACE.toPlaceDetails())); | ||
|
||
// then | ||
final Optional<Plan> result = planRepository.findById(planResponse.getPlanId()); | ||
assertThat(result).isPresent(); | ||
} | ||
|
||
@Test | ||
@DisplayName("계획 참여가 수행되는가") | ||
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(); | ||
|
||
// when | ||
planService.joinPlan(new PlanMemberRequest(planId)); | ||
|
||
// then | ||
final Plan result = planRepository.findById(planId).orElseThrow(); | ||
assertThat(result.getPlanMembers()).hasSize(2); | ||
} | ||
|
||
@Test | ||
@DisplayName("계획 나가기가 수행되는가") // TODO: 계획에 1명 있는데 나가는 경우 생각해보기 | ||
void outPlan() { | ||
// given | ||
final Plan plan = PlanEntityFixture.SECOND_PLACE.toEntity(loginUser); | ||
final UUID planId = planRepository.save(plan).getId(); | ||
|
||
// when | ||
planService.outPlan(new PlanMemberRequest(planId)); | ||
|
||
// then | ||
final Plan result = planRepository.findById(planId).orElseThrow(); | ||
assertThat(result.getPlanMembers()).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("PK로 계획 조회가 수행되는가") | ||
void getPlanById() { | ||
// given | ||
final Plan plan = PlanEntityFixture.FIRST_PLACE.toEntity(loginUser); | ||
final UUID planId = planRepository.save(plan).getId(); | ||
|
||
// when | ||
final PlanInfoResponse result = planService.getPlanById(planId); | ||
|
||
// then | ||
assertThat(result.getPlanId()).isEqualTo(planId); | ||
} | ||
|
||
@Test | ||
@DisplayName("삭제가 수행되는가") | ||
void deletePlan() { | ||
// given | ||
final Plan plan = PlanEntityFixture.SECOND_PLACE.toEntity(loginUser); | ||
final UUID planId = planRepository.save(plan).getId(); | ||
|
||
// when | ||
planService.deletePlan(planId); | ||
|
||
// then | ||
assertThat(planRepository.findById(planId)).isEmpty(); | ||
} | ||
} |
37 changes: 35 additions & 2 deletions
37
backend/src/test/java/com/twtw/backend/fixture/place/PlaceDetailsFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,53 @@ | ||
package com.twtw.backend.fixture.place; | ||
|
||
import com.twtw.backend.domain.place.entity.CategoryGroupCode; | ||
import com.twtw.backend.domain.plan.dto.client.PlaceDetails; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public enum PlaceDetailsFixture { | ||
; | ||
FIRST_PLACE( | ||
"스타벅스", | ||
30, | ||
"http://someUrlToPlaceDetails", | ||
"카페", | ||
"주소", | ||
"도로명주소", | ||
CategoryGroupCode.CE7, | ||
123.123, | ||
321.321), | ||
SECOND_PLACE( | ||
"별다방", | ||
20, | ||
"http://someUrlToPlaceInMap", | ||
"숙박", | ||
"밥좀주소", | ||
"도로명좀주소", | ||
CategoryGroupCode.AD5, | ||
345.543, | ||
543.345); | ||
|
||
private final String placeName; | ||
private final String distance; | ||
private final Integer distance; | ||
private final String placeUrl; | ||
private final String categoryName; | ||
private final String addressName; | ||
private final String roadAddressName; | ||
private final CategoryGroupCode categoryGroupCode; | ||
private final Double x; | ||
private final Double y; | ||
|
||
public PlaceDetails toPlaceDetails() { | ||
return new PlaceDetails( | ||
placeName, | ||
distance, | ||
placeUrl, | ||
categoryName, | ||
addressName, | ||
roadAddressName, | ||
categoryGroupCode, | ||
x, | ||
y); | ||
} | ||
} |