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.
84 lines
3.5 KiB
84 lines
3.5 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.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.AfterEach;
|
|
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.jdbc.core.JdbcTemplate;
|
|
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;
|
|
@Autowired private JdbcTemplate jdbcTemplate;
|
|
@MockBean private CompanyReviewManagementService managementService;
|
|
@MockBean private CompanyReviewReplyService replyService;
|
|
@MockBean private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
static final long COMPANY_USER_ID = 9_320_011L;
|
|
static final long STUDENT_USER_ID = 9_320_012L;
|
|
|
|
@BeforeEach
|
|
void setUpFixtureUsers() {
|
|
removeFixtureUsers();
|
|
ReviewControllerFixtureUsers.provision(jdbcTemplate, COMPANY_USER_ID, "r01b-cr-company", "COMPANY");
|
|
ReviewControllerFixtureUsers.provision(jdbcTemplate, STUDENT_USER_ID, "r01b-cr-student", "STUDENT");
|
|
}
|
|
|
|
@AfterEach
|
|
void tearDownFixtureUsers() {
|
|
removeFixtureUsers();
|
|
}
|
|
|
|
private void removeFixtureUsers() {
|
|
ReviewControllerFixtureUsers.remove(jdbcTemplate, COMPANY_USER_ID, STUDENT_USER_ID);
|
|
}
|
|
|
|
private String token(long id, String role) {
|
|
return com.mydreamjob.auth.support.TestAuthTokens.bearer(id, 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(STUDENT_USER_ID), 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(STUDENT_USER_ID, "STUDENT")))
|
|
.andExpect(status().isForbidden());
|
|
}
|
|
|
|
@Test
|
|
void companyCanListItsReviews() throws Exception {
|
|
when(managementService.listMine(eq(COMPANY_USER_ID), 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(COMPANY_USER_ID, "COMPANY")))
|
|
.andExpect(status().isOk());
|
|
}
|
|
}
|
|
|