#24 simple sns: 알림기능 테스트 코드
This commit is contained in:
@@ -8,6 +8,8 @@ import com.example.sns.repository.UserEntityRepository;
|
||||
import com.example.sns.util.JwtTokenUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -64,4 +66,8 @@ public class UserService {
|
||||
// 토큰 생성
|
||||
return JwtTokenUtils.generateToken(username, secretKey, expiredTimeMs);
|
||||
}
|
||||
|
||||
public Page<Void> alarmList(String username, Pageable pageable) {
|
||||
return Page.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,17 @@ 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.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.test.context.support.WithAnonymousUser;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static com.example.sns.exception.ErrorCode.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
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;
|
||||
@@ -104,4 +109,31 @@ public class UserControllerTest {
|
||||
).andDo(print())
|
||||
.andExpect(status().isUnauthorized());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithMockUser
|
||||
void 알람기능() throws Exception {
|
||||
|
||||
when(userService.alarmList(any(), any())).thenReturn(Page.empty());
|
||||
|
||||
mockMvc.perform(get("/api/v1/users/alarm")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithAnonymousUser
|
||||
void 알람리스트요청시_로그인하지_않은경우() throws Exception {
|
||||
|
||||
when(userService.alarmList(any(), any())).thenReturn(Page.empty());
|
||||
|
||||
mockMvc.perform(get("/api/v1/users/alarm")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user