Skip to content

Commit

Permalink
test: 출석 체크 API 테스트 구성(#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
Minjae-An committed May 25, 2024
1 parent df16fb8 commit 7ee87b8
Showing 1 changed file with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package yeonba.be.arrow.controller;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.time.LocalDate;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import yeonba.be.arrow.service.ArrowService;
import yeonba.be.support.ControllerTestSupport;

@WebMvcTest(ArrowController.class)
class ArrowControllerTest extends ControllerTestSupport {

@Autowired
private ArrowController arrowController;

@MockBean
private ArrowService arrowService;

@Override
protected Object controller() {

return arrowController;
}

@Nested
@DisplayName("사용자 고유 번호를 요청해 ")
class dailyCheckTest {

private long userId = 1L;

@DisplayName("출석 체크를 할 수 있다.")
@Test
void dailCheck() throws Exception {

// given
given(arrowService.dailyCheck(eq(userId), any(LocalDate.class)))
.willReturn(true);

// 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());
}

@DisplayName("이미 출석 체크한 경우 출석 체크할 수 없다.")
@Test
void alreadyDailyChecked() throws Exception {

// given
given(arrowService.dailyCheck(eq(userId), any(LocalDate.class)))
.willReturn(false);

// when & then
mockMvc.perform(post("/daily-check")
.requestAttr("userId", userId))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.status").value("fail"))
.andExpect(jsonPath("$.message").value("이미 출석 체크한 사용자입니다."))
.andExpect(jsonPath("$.data").isEmpty());
}
}
}

0 comments on commit 7ee87b8

Please sign in to comment.