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

feat: Mock 축제 데이터 추가하는 관리자 API 추가 (#907) #908

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,26 @@
package com.festago.admin.presentation.v1;

import com.festago.mock.application.MockDataService;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Profile({"!prod"})
@RestController
@RequestMapping("/admin/api/v1/mock-data")
@RequiredArgsConstructor
@Hidden
public class AdminMockDataV1Controller {

private final MockDataService mockDataService;

@PostMapping("/festivals")
public ResponseEntity<Void> generateMockFestivals() {
mockDataService.makeMockFestivals();
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.festago.admin.presentation.v1;

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

import com.fasterxml.jackson.databind.ObjectMapper;
import com.festago.auth.domain.Role;
import com.festago.mock.application.MockDataService;
import com.festago.support.CustomWebMvcTest;
import com.festago.support.WithMockAuth;
import jakarta.servlet.http.Cookie;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

@CustomWebMvcTest
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
@SuppressWarnings("NonAsciiCharacters")
class AdminMockDataV1ControllerTest {

private static final Cookie TOKEN_COOKIE = new Cookie("token", "token");

@Autowired
MockMvc mockMvc;

@Autowired
ObjectMapper objectMapper;

@Autowired
MockDataService mockDataService;

@Nested
class Mock_축제_생성 {

final String uri = "/admin/api/v1/mock-data/festivals";

@Nested
@DisplayName("POST " + uri)
class 올바른_주소로 {

@Test
@WithMockAuth(role = Role.ADMIN)
void 요청을_보내면_200_응답이_반환된다() throws Exception {
// when & then
mockMvc.perform(post(uri)
.cookie(TOKEN_COOKIE)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}

@Test
void 토큰_없이_보내면_401_응답이_반환된다() throws Exception {
// when & then
mockMvc.perform(post(uri))
.andExpect(status().isUnauthorized());
}

@Test
@WithMockAuth(role = Role.MEMBER)
void 토큰의_권한이_Admin이_아니면_404_응답이_반환된다() throws Exception {
// when & then
mockMvc.perform(post(uri)
.cookie(TOKEN_COOKIE))
.andExpect(status().isNotFound());
}
}
}
}
Loading