Skip to content

Commit

Permalink
test: 캐스퍼 봇 응모 여부
Browse files Browse the repository at this point in the history
  • Loading branch information
k000927 committed Jul 31, 2024
1 parent da87a20 commit 663d335
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

@RestController
@RequestMapping("/event/lottery")
public class LotteryEventController {
Expand All @@ -20,4 +23,9 @@ public ResponseEntity<CustomResponse<GetCasperBot>> postCasperBot(@CookieValue S
@RequestBody String body) {
return new ResponseEntity<>(CustomResponse.create(lotteryEventService.postCasperBot(userData, body)), HttpStatus.CREATED);
}

@GetMapping("/{casperBotId}")
public ResponseEntity<GetCasperBot> getCasperBot(@PathVariable String casperBotId){
return new ResponseEntity<>(lotteryEventService.getCasperBot(Long.parseLong(casperBotId)), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static JGS.CasperEvent.global.util.GsonUtil.getGson;
import static JGS.CasperEvent.global.util.UserUtil.getDecodedPhoneNumber;

Expand Down Expand Up @@ -54,4 +56,8 @@ public LotteryParticipants registerUserIfNeed(String userData) {

return participants;
}

public GetCasperBot getCasperBot(long casperBotId){
return GetCasperBot.of(casperBotRepository.findById(casperBotId).get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;

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.jsonPath;
Expand Down Expand Up @@ -148,13 +149,48 @@ void createCasperBotSuccessTest_CookieNotPresent() throws Exception {
}

@Test
@DisplayName("캐스퍼 봇 응모 여부 조회 - 성공")
void userHasAppliedCasperBot() {
@DisplayName("캐스퍼 봇 응모 여부 조회 성공 - 이미 참여한 유저")
void userHasAppliedCasperBotSuccessTest_AlreadyApplied() throws Exception {
//given
Cookie myCookie = new Cookie("userData", "abc");

//when
ResultActions perform = mockMvc.perform(get("/event/lottery/applied")
.cookie(myCookie));

//then
perform.andExpect(status().isOk())
.andExpect(jsonPath("$.message").value("true"))
.andDo(print());
}

@Test
@DisplayName("캐스퍼 봇 응모 여부 조회 성공 - 참여하지 않은 유저")
void userHasAppliedCasperBotSuccessTest_NotApplied() throws Exception {
//given
Cookie myCookie = new Cookie("userData", "abc");

//when
ResultActions perform = mockMvc.perform(get("/event/lottery/applied")
.cookie(myCookie));

//then
perform.andExpect(status().isOk())
.andExpect(jsonPath("$.message").value("true"))
.andDo(print());
}

@Test
@DisplayName("캐스퍼 봇 응모 여부 조회 실패 - 쿠키에 유저 정보 없음")
void userHasAppliedCasperBotSuccessTest_UnAuthorized() throws Exception {
//given

//when
ResultActions perform = mockMvc.perform(get("/event/lottery/applied"));

//then
perform.andExpect(status().isOk())
.andExpect(jsonPath("$.message").value("true"))
.andDo(print());
}
}

0 comments on commit 663d335

Please sign in to comment.