Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿงช [Test] ํŒจ๋„ํ‹ฐ ๊ด€๋ จ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ #767

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ public ResponseEntity<PartyPenaltyListAdminResDto> penaltyList(@ModelAttribute @
*/
@PatchMapping("/{penaltyId}")
public ResponseEntity<Void> modifyAdminPenalty(@PathVariable Long penaltyId,
@RequestBody PartyPenaltyAdminReqDto reqDto) {
@RequestBody @Valid PartyPenaltyAdminReqDto reqDto) {
partyPenaltyAdminService.modifyAdminPenalty(penaltyId, reqDto);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

/**
* ํŒจ๋„ํ‹ฐ ๋ถ€์—ฌ
*/
@PostMapping()
@PostMapping
public ResponseEntity<Void> addAdminPenalty(
@RequestBody PartyPenaltyAdminReqDto reqDto) {
@RequestBody @Valid PartyPenaltyAdminReqDto reqDto) {
partyPenaltyAdminService.addAdminPenalty(reqDto);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import java.time.LocalDateTime;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import gg.data.party.PartyPenalty;
import gg.data.user.User;
import lombok.Getter;
Expand All @@ -10,13 +15,29 @@
@Getter
@NoArgsConstructor
public class PartyPenaltyAdminReqDto {
@NotBlank(message = "Penalty type์ด ๋น„์–ด์žˆ์Šต๋‹ˆ๋‹ค")
@Size(max = 20, message = "Penalty type์€ ์ตœ๋Œ€ 20์ž์ž…๋‹ˆ๋‹ค")
String penaltyType;

@NotBlank(message = "message๊ฐ€ ๋น„์–ด์žˆ์Šต๋‹ˆ๋‹ค")
@Size(max = 100, message = "Penalty type์€ ์ตœ๋Œ€ 100์ž์ž…๋‹ˆ๋‹ค")
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
String message;

@NotNull(message = "penaltyTime์ด ๋น„์–ด์žˆ์Šต๋‹ˆ๋‹ค")
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
int penaltyTime;

@NotBlank(message = "IntraId๊ฐ€ ๋น„์–ด์žˆ์Šต๋‹ˆ๋‹ค")
String userIntraId;

public PartyPenalty toEntity(User user, String penaltyType, String message, LocalDateTime startTime,
Integer penaltyTime) {
return new PartyPenalty(user, penaltyType, message, startTime, penaltyTime);
}

public PartyPenaltyAdminReqDto(String penaltyType, String message, int penaltyTime, String userIntraId) {
this.penaltyType = penaltyType;
this.message = message;
this.penaltyTime = penaltyTime;
this.userIntraId = userIntraId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package gg.party.api.admin.penalty;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import java.time.LocalDateTime;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
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.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

import com.fasterxml.jackson.databind.ObjectMapper;

import gg.auth.utils.AuthTokenProvider;
import gg.data.party.PartyPenalty;
import gg.data.user.User;
import gg.data.user.type.RacketType;
import gg.data.user.type.RoleType;
import gg.data.user.type.SnsType;
import gg.party.api.admin.penalty.controller.request.PageReqDto;
import gg.party.api.admin.penalty.controller.request.PartyPenaltyAdminReqDto;
import gg.repo.party.PartyPenaltyRepository;
import gg.utils.TestDataUtils;
import gg.utils.annotation.IntegrationTest;
import lombok.extern.slf4j.Slf4j;

@IntegrationTest
@AutoConfigureMockMvc
@SpringBootTest
@Transactional
@Slf4j
public class PartyPenaltyControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private TestDataUtils testDataUtils;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private AuthTokenProvider tokenProvider;
@Autowired
private PartyPenaltyRepository partyPenaltyRepository;

private User userTester;
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
User reportedTester;
String userAccessToken;
String reportedAccessToken;

@BeforeEach
void beforeEach() {
userTester = testDataUtils.createNewUser("User1", "emailTester",
RacketType.DUAL, SnsType.SLACK, RoleType.USER);
reportedTester = testDataUtils.createNewUser("reportedUser", "reportedTester",
RacketType.DUAL, SnsType.SLACK, RoleType.USER);
PartyPenalty testPenalty = testDataUtils.createNewPenalty(reportedTester, "test_penalty",
"becauseTest",
LocalDateTime.now(), 60);
userAccessToken = tokenProvider.createToken(userTester.getId());
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
reportedAccessToken = tokenProvider.createToken(reportedTester.getId());
}

@Nested
@DisplayName("ํŒจ๋„ํ‹ฐ ํ…Œ์ŠคํŠธ")
@WithMockUser(username = "admin", roles = {"ADMIN"})
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
class PenaltyAdminTests {

@Test
@DisplayName("ํŒจ๋„ํ‹ฐ ์กฐํšŒ")
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
void testRetrievePenaltiesList() throws Exception {
PageReqDto reqDto = new PageReqDto(1, 10);

mockMvc.perform(get("/party/admin/penalties?page=1&size=10") //์ •ํ™•ํ•œ ํŽ˜์ด์ง€, ์‚ฌ์ด์ฆˆ ์ •๋ณด ํ•„์š”
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(reqDto)))
.andExpect(status().isOk());
}

@Test
@DisplayName("ํŒจ๋„ํ‹ฐ ์ˆ˜์ •")
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
void testModifyAdminPenalty() throws Exception {
Long penaltyId = 1L;
JaBeast marked this conversation as resolved.
Show resolved Hide resolved

PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto(
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
"test_penalty",
"Test reason",
60,
reportedTester.getIntraId()
);

mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", penaltyId)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(penaltyDto)))
.andExpect(status().isNoContent());
}

@Test
@DisplayName("ํŒจ๋„ํ‹ฐ ๋ถ€์—ฌ")
void testAddAdminPenalty() throws Exception {
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto(
"test_penalty",
"Test reason",
60,
reportedTester.getIntraId()
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
);

mockMvc.perform(post("/party/admin/penalties")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(penaltyDto)))
.andExpect(status().isCreated());
}
}
}
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
Loading