Skip to content

Commit

Permalink
RAC-254 test: slack mock 등록
Browse files Browse the repository at this point in the history
  • Loading branch information
ay-eonii committed Jan 14, 2024
1 parent eff5838 commit 2276676
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
import com.postgraduate.domain.wish.domain.repository.WishRepository;
import com.postgraduate.global.config.redis.RedisRepository;
import com.postgraduate.global.config.security.jwt.util.JwtUtils;
import com.postgraduate.global.slack.SlackMessage;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;

import java.io.IOException;
import java.util.Optional;

import static com.postgraduate.domain.auth.presentation.constant.AuthResponseCode.*;
Expand All @@ -33,6 +35,7 @@
import static com.postgraduate.domain.user.presentation.constant.UserResponseMessage.NOT_FOUND_USER;
import static java.time.LocalDateTime.now;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand All @@ -53,14 +56,17 @@ class AuthControllerTest extends IntegrationTest {
private WishRepository wishRepository;
@MockBean
RedisRepository redisRepository;
@MockBean
private SlackMessage slackMessage;
private User user;
private final Long anonymousUserSocialId = 2L;


@BeforeEach
void setUp() {
void setUp() throws IOException {
user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, USER, true, now(), now(), false);
userRepository.save(user);
doNothing().when(slackMessage).sendSlackLog(any());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
import com.postgraduate.domain.user.domain.entity.constant.Role;
import com.postgraduate.domain.user.domain.repository.UserRepository;
import com.postgraduate.global.config.security.jwt.util.JwtUtils;
import com.postgraduate.global.slack.SlackMessage;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;

import java.io.IOException;
import java.time.LocalDate;

import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.*;
Expand All @@ -39,6 +42,8 @@
import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate;
import static com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING;
import static java.time.LocalDateTime.now;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand All @@ -60,13 +65,15 @@ class MentoringControllerTest extends IntegrationTest {
private SalaryRepository salaryRepository;
@Autowired
private PaymentRepository paymentRepository;
@MockBean
private SlackMessage slackMessage;
private User user;
private Senior senior;
private String userAccessToken;
private String seniorAccessToken;

@BeforeEach
void setUp() {
void setUp() throws IOException {
user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false);
userRepository.save(user);

Expand All @@ -80,6 +87,8 @@ void setUp() {

userAccessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER);
seniorAccessToken = jwtUtil.generateAccessToken(userOfSenior.getUserId(), Role.SENIOR);

doNothing().when(slackMessage).sendSlackLog(any());
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@
import com.postgraduate.domain.user.domain.entity.constant.Role;
import com.postgraduate.domain.user.domain.repository.UserRepository;
import com.postgraduate.global.config.security.jwt.util.JwtUtils;
import com.postgraduate.global.slack.SlackMessage;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;

import java.io.IOException;

import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseCode.SALARY_FIND;
import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseMessage.GET_SALARY_INFO;
import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseMessage.GET_SALARY_LIST_INFO;
import static java.time.LocalDateTime.now;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand All @@ -37,11 +43,13 @@ class SalaryControllerTest extends IntegrationTest {
private SeniorRepository seniorRepository;
@Autowired
private SalaryRepository salaryRepository;
@MockBean
private SlackMessage slackMessage;
private String token;


@BeforeEach
void setUp() {
void setUp() throws IOException {
User user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.SENIOR, true, now(), now(), false);
userRepository.save(user);

Expand All @@ -54,6 +62,8 @@ void setUp() {
salaryRepository.save(salary);

token = jwtUtil.generateAccessToken(user.getUserId(), Role.SENIOR);

doNothing().when(slackMessage).sendSlackLog(any());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,25 @@
import com.postgraduate.domain.user.domain.entity.constant.Role;
import com.postgraduate.domain.user.domain.repository.UserRepository;
import com.postgraduate.global.config.security.jwt.util.JwtUtils;
import com.postgraduate.global.slack.SlackMessage;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;

import java.io.IOException;
import java.util.List;

import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate;
import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.*;
import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.*;
import static java.time.LocalDateTime.now;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand All @@ -52,11 +57,13 @@ class SeniorControllerTest extends IntegrationTest {
private SalaryRepository salaryRepository;
@Autowired
private AccountRepository accountRepository;
@MockBean
private SlackMessage slackMessage;
private Senior senior;
private String token;

@BeforeEach
void setUp() {
void setUp() throws IOException {
User user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.SENIOR, true, now(), now(), false);
userRepository.save(user);

Expand All @@ -66,6 +73,8 @@ void setUp() {
seniorRepository.save(senior);

token = jwtUtil.generateAccessToken(user.getUserId(), Role.SENIOR);

doNothing().when(slackMessage).sendSlackLog(any());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@
import com.postgraduate.domain.user.domain.repository.UserRepository;
import com.postgraduate.domain.user.presentation.constant.UserResponseCode;
import com.postgraduate.global.config.security.jwt.util.JwtUtils;
import com.postgraduate.global.slack.SlackMessage;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;

import java.io.IOException;

import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_FIND;
import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_UPDATE;
import static com.postgraduate.domain.user.presentation.constant.UserResponseMessage.*;
import static java.time.LocalDateTime.now;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
Expand All @@ -35,14 +41,18 @@ class UserControllerTest extends IntegrationTest {
private JwtUtils jwtUtil;
@Autowired
private UserRepository userRepository;
@MockBean
private SlackMessage slackMessage;
private String token;

@BeforeEach
void setUp() {
void setUp() throws IOException {
User user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false);
userRepository.save(user);

token = jwtUtil.generateAccessToken(user.getUserId(), Role.USER);

doNothing().when(slackMessage).sendSlackLog(any());
}

@Test
Expand Down

0 comments on commit 2276676

Please sign in to comment.