From 957c18fbf971d43d94fde1ae301c585828744326 Mon Sep 17 00:00:00 2001 From: unanchoi Date: Mon, 27 May 2024 21:35:50 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[TEST]=20GoalService=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/GoalServiceIntegrationTest.java | 83 +++++++++++++++++++ .../smeem/support/fixture/GoalFixture.java | 30 +++++++ 2 files changed, 113 insertions(+) create mode 100644 smeem-api/src/test/java/com/smeem/goal/service/GoalServiceIntegrationTest.java create mode 100644 smeem-api/src/test/java/com/smeem/support/fixture/GoalFixture.java diff --git a/smeem-api/src/test/java/com/smeem/goal/service/GoalServiceIntegrationTest.java b/smeem-api/src/test/java/com/smeem/goal/service/GoalServiceIntegrationTest.java new file mode 100644 index 00000000..ca34f04d --- /dev/null +++ b/smeem-api/src/test/java/com/smeem/goal/service/GoalServiceIntegrationTest.java @@ -0,0 +1,83 @@ +package com.smeem.goal.service; + +import com.smeem.api.goal.service.GoalService; +import com.smeem.api.goal.service.dto.request.GoalGetServiceRequest; +import com.smeem.api.goal.service.dto.response.GoalGetServiceResponse; +import com.smeem.domain.goal.model.Goal; +import com.smeem.domain.goal.model.GoalType; +import com.smeem.domain.goal.repository.GoalRepository; +import com.smeem.support.ServiceIntegrationTest; +import com.smeem.support.fixture.GoalFixture; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +public class GoalServiceIntegrationTest extends ServiceIntegrationTest { + + @Autowired + GoalService goalService; + + @Autowired + GoalRepository goalRepository; + + @AfterEach + void tearDown() { + goalRepository.deleteAllInBatch(); + } + + @Test + @DisplayName("[성공] 모든 학습 목표를 조회할 수 있다.") + void getAllGoals() throws Exception { + // given + val goal1 = GoalFixture.goal().type(GoalType.DEVELOP).build(); + val goal2 = GoalFixture.goal().type(GoalType.APPLY).build(); + val goal3 = GoalFixture.goal().type(GoalType.BUSINESS).build(); + val goal4 = GoalFixture.goal().type(GoalType.EXAM).build(); + val goal5 = GoalFixture.goal().type(GoalType.NONE).build(); + val goal6 = GoalFixture.goal().type(GoalType.HOBBY).build(); + goalRepository.saveAll(List.of(goal1, goal2, goal3, goal4, goal5, goal6)); + + // when + val response = goalService.getAllGoals(); + + // then + Assertions.assertThat(response.goals()) + .extracting("goalType", "goalDescription") + .containsExactlyInAnyOrder( + Assertions.tuple(GoalType.DEVELOP.name(), GoalType.DEVELOP.getDescription()), + Assertions.tuple(GoalType.APPLY.name(), GoalType.APPLY.getDescription()), + Assertions.tuple(GoalType.EXAM.name(), GoalType.EXAM.getDescription()), + Assertions.tuple(GoalType.BUSINESS.name(), GoalType.BUSINESS.getDescription()), + Assertions.tuple(GoalType.NONE.name(), GoalType.NONE.getDescription()), + Assertions.tuple(GoalType.HOBBY.name(), GoalType.HOBBY.getDescription()) + ); + } + + @Test + @DisplayName("[성공] 학습 목표 유형으로 학습 목표를 조회할 수 있다.") + void getByType() throws Exception { + // given + goalRepository.save( + Goal.builder() + .type(GoalType.DEVELOP) + .way("Test Way") + .detail("Test Detail") + .build() + ); + + val request = GoalGetServiceRequest.of(GoalType.DEVELOP); + // when + final GoalGetServiceResponse response = goalService.getByType(request); + + // then + Assertions.assertThat(response) + .extracting("goalType", "way", "detail") + .containsExactly(GoalType.DEVELOP, "Test Way", "Test Detail"); + + } +} diff --git a/smeem-api/src/test/java/com/smeem/support/fixture/GoalFixture.java b/smeem-api/src/test/java/com/smeem/support/fixture/GoalFixture.java new file mode 100644 index 00000000..44051c1a --- /dev/null +++ b/smeem-api/src/test/java/com/smeem/support/fixture/GoalFixture.java @@ -0,0 +1,30 @@ +package com.smeem.support.fixture; + +import com.smeem.domain.goal.model.Goal; +import com.smeem.domain.goal.model.GoalType; + +public class GoalFixture { + + private GoalType type; + + private String way = "test-goal-way"; + private String detail = "test-goal-detail"; + + public static GoalFixture goal() { + return new GoalFixture(); + } + + public GoalFixture type(GoalType type) { + this.type = type; + return this; + } + + public Goal build() { + return Goal.builder() + .type(type) + .way(way) + .detail(detail) + .build(); + } + +} From 24f1294691f916bd9bbf970380f55af8d62b755d Mon Sep 17 00:00:00 2001 From: unanchoi Date: Tue, 11 Jun 2024 22:07:49 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FIX]=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/GoalServiceIntegrationTest.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/smeem-api/src/test/java/com/smeem/goal/service/GoalServiceIntegrationTest.java b/smeem-api/src/test/java/com/smeem/goal/service/GoalServiceIntegrationTest.java index ca34f04d..fdcfcd04 100644 --- a/smeem-api/src/test/java/com/smeem/goal/service/GoalServiceIntegrationTest.java +++ b/smeem-api/src/test/java/com/smeem/goal/service/GoalServiceIntegrationTest.java @@ -61,23 +61,19 @@ void getAllGoals() throws Exception { @Test @DisplayName("[성공] 학습 목표 유형으로 학습 목표를 조회할 수 있다.") void getByType() throws Exception { - // given - goalRepository.save( - Goal.builder() - .type(GoalType.DEVELOP) - .way("Test Way") - .detail("Test Detail") - .build() - ); + // given + + goalRepository.save(GoalFixture.goal().type(GoalType.DEVELOP).build()); val request = GoalGetServiceRequest.of(GoalType.DEVELOP); - // when + + // when final GoalGetServiceResponse response = goalService.getByType(request); - // then + // then Assertions.assertThat(response) .extracting("goalType", "way", "detail") - .containsExactly(GoalType.DEVELOP, "Test Way", "Test Detail"); + .containsExactly(GoalType.DEVELOP, "test-goal-way", "test-goal-detail"); } }