Skip to content

Commit

Permalink
[feat] 테스트 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
sohyundoh committed Sep 27, 2024
1 parent 34a4539 commit 02a7836
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions module-api/src/test/java/com/mile/common/CorsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mile.common;

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.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
@AutoConfigureMockMvc
public class CorsTest {

@Autowired
private MockMvc mockMvc;

@Test
public void testCorsWithMockMvc() throws Exception {
mockMvc.perform(options("/api/moim/MQ==")
.header("Origin", "http://localhost:5173")
.header("Access-Control-Request-Method", "OPTIONS")
.header("Access-Control-Request-Headers", "Content-Type")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(print());
}
}

0 comments on commit 02a7836

Please sign in to comment.