Skip to content

Commit

Permalink
test: pointLog API 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
EunChanNam committed Nov 4, 2023
1 parent afa3a3c commit 9ffc740
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api/users/point")
@RequestMapping("/api/points")
@RequiredArgsConstructor
public class PointController {

Expand All @@ -26,7 +26,6 @@ public ResponseEntity<Success> usePoint(
final @RequestBody PointUseRequest request,
final @FetchAuthInfo AuthInfo authInfo
) {

pointService.usePoint(request, authInfo.userId());

return ResponseEntity.ok(new Success());
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/inq/wishhair/wesharewishhair/LikeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

import com.inq.wishhair.wesharewishhair.review.application.LikeReviewService;

@SpringBootTest
// @SpringBootTest
@DisplayName("[좋아요 동시성 테스트]")
class LikeTest {

@Autowired
// @Autowired
private LikeReviewService likeReviewService;

@Test
// @Test
@DisplayName("[100개의 동시요청에서 100개의 좋아요 개수를 기록한다]")
void test() throws InterruptedException {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
Expand All @@ -18,9 +17,7 @@
import com.inq.wishhair.wesharewishhair.auth.application.dto.response.LoginResponse;
import com.inq.wishhair.wesharewishhair.auth.presentation.dto.request.LoginRequest;
import com.inq.wishhair.wesharewishhair.common.support.ApiTestSupport;
import com.inq.wishhair.wesharewishhair.global.config.SecurityConfig;

@WebMvcTest(value = {AuthController.class, SecurityConfig.class})
@DisplayName("[AuthController 테스트] - API")
class AuthControllerTest extends ApiTestSupport {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
Expand All @@ -16,10 +15,8 @@
import com.inq.wishhair.wesharewishhair.auth.presentation.dto.request.AuthKeyRequest;
import com.inq.wishhair.wesharewishhair.auth.presentation.dto.request.MailRequest;
import com.inq.wishhair.wesharewishhair.common.support.ApiTestSupport;
import com.inq.wishhair.wesharewishhair.global.config.SecurityConfig;
import com.inq.wishhair.wesharewishhair.user.application.utils.UserValidator;

@WebMvcTest(value = {MailAuthController.class, SecurityConfig.class})
@DisplayName("[MailAuthController 테스트] - API")
class MailAuthControllerTest extends ApiTestSupport {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
Expand All @@ -16,9 +15,7 @@
import com.inq.wishhair.wesharewishhair.auth.application.TokenReissueService;
import com.inq.wishhair.wesharewishhair.auth.application.dto.response.TokenResponse;
import com.inq.wishhair.wesharewishhair.common.support.ApiTestSupport;
import com.inq.wishhair.wesharewishhair.global.config.SecurityConfig;

@WebMvcTest(value = {TokenReissueController.class, SecurityConfig.class})
@DisplayName("[TokenReissueController 테스트] - API")
class TokenReissueControllerTest extends ApiTestSupport {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import static org.mockito.BDDMockito.*;

import org.junit.jupiter.api.BeforeEach;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.inq.wishhair.wesharewishhair.auth.domain.AuthToken;
import com.inq.wishhair.wesharewishhair.auth.domain.AuthTokenManager;

@SpringBootTest
@AutoConfigureMockMvc
public abstract class ApiTestSupport {

private final ObjectMapper objectMapper = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static PointLog getUsePointLog(User user) {
return PointLog.addPointLog(user, PointType.USE, DEAL_AMOUNT, PRE_POINT);
}

public static PointLog getChargePointLog(User user) {
return PointLog.addPointLog(user, PointType.CHARGE, DEAL_AMOUNT, PRE_POINT);
}

public static PointUseRequest getPointUseRequest() {
return new PointUseRequest("bank", "1234-1234", DEAL_AMOUNT);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.inq.wishhair.wesharewishhair.point.presentation;

import static com.inq.wishhair.wesharewishhair.common.fixture.AuthFixture.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

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.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import com.inq.wishhair.wesharewishhair.common.support.ApiTestSupport;
import com.inq.wishhair.wesharewishhair.point.domain.PointLogRepository;
import com.inq.wishhair.wesharewishhair.point.fixture.PointLogFixture;
import com.inq.wishhair.wesharewishhair.user.domain.UserRepository;
import com.inq.wishhair.wesharewishhair.user.domain.entity.User;
import com.inq.wishhair.wesharewishhair.user.fixture.UserFixture;

@SpringBootTest
@AutoConfigureMockMvc
@DisplayName("[PointController 테스트 - API]")
class PointControllerTest extends ApiTestSupport {

private static final String POINT_USE_URL = "/api/points/use";

@Autowired
private MockMvc mockMvc;
@Autowired
private PointLogRepository pointLogRepository;
@Autowired
private UserRepository userRepository;

@Test
@DisplayName("[포인트 사용 API 를 호출한다]")
void usePoint() throws Exception {
//given
User user = UserFixture.getFixedManUser();
userRepository.save(user);
pointLogRepository.save(PointLogFixture.getUsePointLog(user));

//when
ResultActions result = mockMvc.perform(
MockMvcRequestBuilders
.post(POINT_USE_URL)
.header(AUTHORIZATION, ACCESS_TOKEN)
.contentType(MediaType.APPLICATION_JSON)
.content(toJson(PointLogFixture.getPointUseRequest()))
);

//then
result.andExpect(status().isOk());
}
}

0 comments on commit 9ffc740

Please sign in to comment.