-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
src/test/java/com/server/bbo_gak/domain/recruit/controller/SeasonControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.server.bbo_gak.domain.recruit.controller; | ||
|
||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.server.bbo_gak.domain.recruit.dto.response.SeasonGetResponse; | ||
import com.server.bbo_gak.domain.recruit.entity.Season; | ||
import com.server.bbo_gak.domain.user.entity.User; | ||
import com.server.bbo_gak.domain.user.entity.UserRepository; | ||
import com.server.bbo_gak.domain.user.entity.UserRole; | ||
import com.server.bbo_gak.global.AbstractRestDocsTests; | ||
import com.server.bbo_gak.global.RestDocsFactory; | ||
import com.server.bbo_gak.global.security.PrincipalDetails; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Transactional | ||
@SpringBootTest | ||
@ActiveProfiles("test") | ||
@Sql("/season-test-data.sql") | ||
public class SeasonControllerTest extends AbstractRestDocsTests { | ||
|
||
private static final String DEFAULT_URL = "/api/v1/seasons"; | ||
@Autowired | ||
private UserRepository userRepository; | ||
@Autowired | ||
private RestDocsFactory restDocsFactory; | ||
private List<SeasonGetResponse> responses; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
User user = userRepository.findById(1L).get(); | ||
Season season1 = new Season("2024 하반기", user); | ||
Season season2 = new Season("2025 상반기", user); | ||
|
||
responses = List.of( | ||
SeasonGetResponse.from(season1), | ||
SeasonGetResponse.from(season2) | ||
); | ||
} | ||
|
||
@Nested | ||
class 분기리스트_조회 { | ||
|
||
@Test | ||
public void 분기_없으면_기본생성_성공() throws Exception { | ||
mockMvc.perform( | ||
restDocsFactory.createRequest(DEFAULT_URL, null, HttpMethod.GET, objectMapper)) | ||
.andExpect(status().isOk()) | ||
.andDo( | ||
restDocsFactory.getSuccessResourceList("[GET] 분기 리스트 조회 성공", "분기 리스트 조회", "Season", | ||
List.of(), responses)); | ||
} | ||
|
||
@Test | ||
public void 분기_있으면_DB에서_조회_성공() throws Exception { | ||
UserDetails userDetails = PrincipalDetails.ofJwt(2L, UserRole.USER); | ||
Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, null, | ||
userDetails.getAuthorities()); | ||
SecurityContextHolder.getContext().setAuthentication(authentication); | ||
|
||
User mockUser = User.builder() | ||
.id(2L) | ||
.role(UserRole.USER) | ||
.build(); | ||
|
||
when(userRepository.findById(2L)).thenReturn(Optional.of(mockUser)); | ||
|
||
mockMvc.perform( | ||
restDocsFactory.createRequest(DEFAULT_URL, null, HttpMethod.GET, objectMapper)) | ||
.andExpect(status().isOk()) | ||
.andDo( | ||
restDocsFactory.getSuccessResourceList("[GET] 분기 리스트 조회 성공", "분기 리스트 조회", "Season", | ||
List.of(), responses)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
delete | ||
from notification; | ||
|
||
delete | ||
from recruit_schedule; | ||
|
||
delete | ||
from recruit; | ||
|
||
delete | ||
from recruit_season; | ||
|
||
delete | ||
from users; | ||
|
||
INSERT INTO users (deleted, created_at, update_at, user_id, dtype, email, login_id, name, password, role) | ||
VALUES (false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000', 1, 'AuthTestUser', 'email', 'test', 'test', | ||
'test123', 'USER'), | ||
(false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000', 2, 'AuthTestUser', 'email', 'test', 'test', | ||
'test123', 'USER'); | ||
|
||
INSERT INTO recruit_season (recruit_season_id, name, user_id) | ||
VALUES (1, '2024 상반기', 2), | ||
(2, '2024 하반기', 2), | ||
(3, '2025 상반기', 2); | ||
|
||
|
||
|
||
|
||
|