-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
be/src/test/java/yeonba/be/arrow/integration/ArrowIntegrationTest.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,90 @@ | ||
package yeonba.be.arrow.integration; | ||
|
||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.TestInstance.Lifecycle; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import yeonba.be.arrow.controller.ArrowController; | ||
import yeonba.be.exception.ExceptionAdvice; | ||
import yeonba.be.fixture.UserFixtureFactory; | ||
import yeonba.be.user.entity.Animal; | ||
import yeonba.be.user.entity.Area; | ||
import yeonba.be.user.entity.User; | ||
import yeonba.be.user.entity.VocalRange; | ||
|
||
|
||
@ActiveProfiles("test") | ||
@TestInstance(Lifecycle.PER_CLASS) | ||
@Transactional | ||
@SpringBootTest | ||
public class ArrowIntegrationTest { | ||
|
||
@PersistenceContext | ||
private EntityManager em; | ||
|
||
@Autowired | ||
private ExceptionAdvice exceptionAdvice; | ||
|
||
@Autowired | ||
private ArrowController arrowController; | ||
private MockMvc mockMvc; | ||
private long userId; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
mockMvc = MockMvcBuilders.standaloneSetup(arrowController) | ||
.setControllerAdvice(exceptionAdvice) | ||
.alwaysDo(print()) | ||
.build(); | ||
|
||
VocalRange vocalRange = new VocalRange("저음"); | ||
em.persist(vocalRange); | ||
|
||
Animal animal = new Animal("강아지상"); | ||
em.persist(animal); | ||
|
||
Area area = new Area("서울"); | ||
em.persist(area); | ||
em.flush(); | ||
|
||
User user = UserFixtureFactory.builder() | ||
.vocalRange(vocalRange) | ||
.animal(animal) | ||
.area(area) | ||
.build().getFixture(); | ||
em.persist(user); | ||
em.flush(); | ||
|
||
userId = user.getId(); | ||
} | ||
|
||
@DisplayName("출석 체크를 할 수 있다.") | ||
@Test | ||
void dailyCheck() throws Exception { | ||
|
||
// when & then | ||
mockMvc.perform( | ||
post("/daily-check") | ||
.requestAttr("userId", userId) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.status").value("success")) | ||
.andExpect(jsonPath("$.message").isEmpty()) | ||
.andExpect(jsonPath("$.data").isEmpty()); | ||
} | ||
} |