Skip to content

Commit

Permalink
Merge pull request #297 from Team-Smeme/unan#285
Browse files Browse the repository at this point in the history
[TEST] GoalService 테스트 코드 작성
  • Loading branch information
unanchoi authored Jun 11, 2024
2 parents 0bfe2ee + 24f1294 commit 158ad5c
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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(GoalFixture.goal().type(GoalType.DEVELOP).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-goal-way", "test-goal-detail");

}
}
30 changes: 30 additions & 0 deletions smeem-api/src/test/java/com/smeem/support/fixture/GoalFixture.java
Original file line number Diff line number Diff line change
@@ -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();
}

}

0 comments on commit 158ad5c

Please sign in to comment.