forked from baskbuddy/zhangshun
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.7 KiB
62 lines
2.7 KiB
package com.mydreamjob.review;
|
|
|
|
import com.mydreamjob.common.exception.BusinessException;
|
|
import com.mydreamjob.common.exception.ErrorCode;
|
|
import com.mydreamjob.auth.JwtTokenProvider;
|
|
import com.mydreamjob.review.dto.ReviewReplyPageResponse;
|
|
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.boot.test.mock.mockito.MockBean;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
import java.util.Map;
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
import static org.mockito.Mockito.when;
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
@SpringBootTest
|
|
@AutoConfigureMockMvc
|
|
@ActiveProfiles("integration-test")
|
|
class CompanyReviewManagementControllerTest {
|
|
|
|
@Autowired private MockMvc mockMvc;
|
|
@Autowired private JwtTokenProvider jwtTokenProvider;
|
|
@MockBean private CompanyReviewManagementService managementService;
|
|
@MockBean private CompanyReviewReplyService replyService;
|
|
@MockBean private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
private String token(long id, String role) {
|
|
return "Bearer " + jwtTokenProvider.generateAccessToken(id, role.equals("COMPANY") ? "1" : "2",
|
|
Map.of("roles", role));
|
|
}
|
|
|
|
@Test
|
|
void unauthenticatedCannotAccessCompanyReviews() throws Exception {
|
|
mockMvc.perform(get("/companies/me/job-reviews"))
|
|
.andExpect(status().isUnauthorized());
|
|
}
|
|
|
|
@Test
|
|
void studentCannotAccessCompanyReviews() throws Exception {
|
|
when(managementService.listMine(eq(2L), any(), any(), any(), any(), any(), any(), eq(0), eq(20)))
|
|
.thenThrow(new BusinessException(ErrorCode.FORBIDDEN));
|
|
mockMvc.perform(get("/companies/me/job-reviews").header("Authorization", token(2L, "STUDENT")))
|
|
.andExpect(status().isForbidden());
|
|
}
|
|
|
|
@Test
|
|
void companyCanListItsReviews() throws Exception {
|
|
when(managementService.listMine(eq(1L), any(), any(), any(), any(), any(), any(), eq(0), eq(20)))
|
|
.thenReturn(ReviewReplyPageResponse.builder().items(java.util.List.of()).total(0)
|
|
.page(0).size(20).totalPages(0).build());
|
|
mockMvc.perform(get("/companies/me/job-reviews").header("Authorization", token(1L, "COMPANY")))
|
|
.andExpect(status().isOk());
|
|
}
|
|
}
|
|
|