Skip to content

Commit

Permalink
#34 - Test: 회원 로그인 POST 요청(JSON 방식) 컨트롤러 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ahah525 committed Nov 8, 2022
1 parent 19414b1 commit d31c078
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.example.mutbooks.app.api.controller;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.transaction.annotation.Transactional;

import java.nio.charset.StandardCharsets;

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.status;

@SpringBootTest
@AutoConfigureMockMvc
@Transactional
@ActiveProfiles("test")
class MemberApiControllerTest {

@Autowired
private MockMvc mvc;

@Test
@DisplayName("POST /api/v1/member/login 은 로그인 처리 URL 이다.")
void t1() throws Exception {
// When
ResultActions resultActions = mvc
.perform(
post("/api/v1/member/login")
.content("""
{
"username": "user1",
"password": "1234"
}
""".stripIndent())
.contentType(new MediaType(MediaType.APPLICATION_JSON, StandardCharsets.UTF_8))
)
.andDo(print());

// Then
resultActions
.andExpect(status().is2xxSuccessful());
}
}

0 comments on commit d31c078

Please sign in to comment.