Skip to content

Commit edc273f

Browse files
authored
[Fix]: 테스트 코드 오류 전체 수정 (#228)
1 parent ba9d10b commit edc273f

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

src/test/java/com/backend/domain/notification/controller/NotificationControllerTest.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import java.util.List;
2626

27-
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
2827
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
2928
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
3029
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
@@ -35,7 +34,7 @@
3534
@AutoConfigureMockMvc
3635
@Transactional
3736
@ActiveProfiles("test")
38-
@WithMockUser
37+
@WithMockUser(username = "[email protected]")
3938
@Import({TestElasticsearchConfiguration.class, TestRedisConfiguration.class})
4039
class NotificationControllerTest {
4140

@@ -115,7 +114,6 @@ private void setupTestData() {
115114
@DisplayName("전체 알림 목록 조회 - 성공")
116115
void getNotifications_Success() throws Exception {
117116
mockMvc.perform(get("/notifications")
118-
.with(user(String.valueOf(testMember.getId())))
119117
.param("page", "0")
120118
.param("size", "10")
121119
.contentType(MediaType.APPLICATION_JSON))
@@ -135,7 +133,6 @@ void getNotifications_Success() throws Exception {
135133
@DisplayName("읽지 않은 알림만 조회 - 성공")
136134
void getNotifications_UnreadOnly_Success() throws Exception {
137135
mockMvc.perform(get("/notifications")
138-
.with(user(String.valueOf(testMember.getId())))
139136
.param("page", "0")
140137
.param("size", "10")
141138
.param("isRead", "false")
@@ -153,7 +150,6 @@ void getNotifications_UnreadOnly_Success() throws Exception {
153150
@DisplayName("읽은 알림만 조회 - 성공")
154151
void getNotifications_ReadOnly_Success() throws Exception {
155152
mockMvc.perform(get("/notifications")
156-
.with(user(String.valueOf(testMember.getId())))
157153
.param("page", "0")
158154
.param("size", "10")
159155
.param("isRead", "true")
@@ -170,7 +166,6 @@ void getNotifications_ReadOnly_Success() throws Exception {
170166
@DisplayName("페이징 처리 확인")
171167
void getNotifications_Paging_Success() throws Exception {
172168
mockMvc.perform(get("/notifications")
173-
.with(user(String.valueOf(testMember.getId())))
174169
.param("page", "0")
175170
.param("size", "2")
176171
.contentType(MediaType.APPLICATION_JSON))
@@ -188,7 +183,6 @@ void markAsRead_Success() throws Exception {
188183
Long notificationId = unreadNotification1.getId();
189184

190185
mockMvc.perform(put("/notifications/{id}/read", notificationId)
191-
.with(user(String.valueOf(testMember.getId())))
192186
.contentType(MediaType.APPLICATION_JSON))
193187
.andDo(print())
194188
.andExpect(status().isOk())
@@ -208,7 +202,6 @@ void markAsRead_NotFound() throws Exception {
208202
Long nonExistentId = 999999L;
209203

210204
mockMvc.perform(put("/notifications/{id}/read", nonExistentId)
211-
.with(user(String.valueOf(testMember.getId())))
212205
.contentType(MediaType.APPLICATION_JSON))
213206
.andDo(print())
214207
.andExpect(status().isNotFound())
@@ -220,7 +213,6 @@ void markAsRead_NotFound() throws Exception {
220213
@DisplayName("모든 알림 읽음 처리 - 성공")
221214
void markAllAsRead_Success() throws Exception {
222215
mockMvc.perform(put("/notifications/read-all")
223-
.with(user(String.valueOf(testMember.getId())))
224216
.contentType(MediaType.APPLICATION_JSON))
225217
.andDo(print())
226218
.andExpect(status().isOk())
@@ -240,7 +232,6 @@ void markAllAsRead_AlreadyRead() throws Exception {
240232
notificationRepository.markAllAsRead(testMember.getId());
241233

242234
mockMvc.perform(put("/notifications/read-all")
243-
.with(user(String.valueOf(testMember.getId())))
244235
.contentType(MediaType.APPLICATION_JSON))
245236
.andDo(print())
246237
.andExpect(status().isOk())
@@ -253,7 +244,6 @@ void markAllAsRead_AlreadyRead() throws Exception {
253244
@DisplayName("읽지 않은 알림 개수 조회 - 성공")
254245
void getUnreadCount_Success() throws Exception {
255246
mockMvc.perform(get("/notifications/unread-count")
256-
.with(user(String.valueOf(testMember.getId())))
257247
.contentType(MediaType.APPLICATION_JSON))
258248
.andDo(print())
259249
.andExpect(status().isOk())
@@ -266,7 +256,6 @@ void getUnreadCount_Success() throws Exception {
266256
@DisplayName("알림 응답 데이터 구조 검증")
267257
void getNotifications_ResponseStructure() throws Exception {
268258
mockMvc.perform(get("/notifications")
269-
.with(user(String.valueOf(testMember.getId())))
270259
.param("page", "0")
271260
.param("size", "10")
272261
.contentType(MediaType.APPLICATION_JSON))
@@ -285,7 +274,6 @@ void getNotifications_ResponseStructure() throws Exception {
285274
@DisplayName("알림 내용과 타입 검증")
286275
void getNotifications_ContentValidation() throws Exception {
287276
mockMvc.perform(get("/notifications")
288-
.with(user(String.valueOf(testMember.getId())))
289277
.param("page", "0")
290278
.param("size", "10")
291279
.contentType(MediaType.APPLICATION_JSON))
@@ -306,7 +294,6 @@ void getNotifications_ContentValidation() throws Exception {
306294
@DisplayName("잘못된 페이지 파라미터")
307295
void getNotifications_InvalidPageParameter() throws Exception {
308296
mockMvc.perform(get("/notifications")
309-
.with(user(String.valueOf(testMember.getId())))
310297
.param("page", "-1")
311298
.param("size", "10")
312299
.contentType(MediaType.APPLICATION_JSON))
@@ -334,7 +321,6 @@ void getNotifications_OnlyOwnNotifications() throws Exception {
334321

335322
// 현재 테스트 멤버의 알림만 조회됨
336323
mockMvc.perform(get("/notifications")
337-
.with(user(String.valueOf(testMember.getId())))
338324
.param("page", "0")
339325
.param("size", "10")
340326
.contentType(MediaType.APPLICATION_JSON))

src/test/java/com/backend/domain/payment/controller/ApiV1PaymentControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void issue_billing_key_success() throws Exception {
246246
.andExpect(status().isOk())
247247
.andExpect(jsonPath("$.data.billingKey", is("BILL-XYZ")))
248248
.andExpect(jsonPath("$.data.provider", is("toss")))
249-
.andExpect(jsonPath("$.data.cardBrand", is("SHINHAN")));
249+
.andExpect(jsonPath("$.data.brand", is("SHINHAN")));
250250
}
251251

252252
// 6) 인증 없으면 401

src/test/java/com/backend/domain/payment/service/TossBillingClientServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void issueBillingKey_success_parses_fields() {
5454

5555
var res = sut.issueBillingKey("user-1","AUTH-123");
5656
assertThat(res.getBillingKey()).isEqualTo("BILL-123");
57-
assertThat(res.getCardBrand()).isEqualTo("SHINHAN");
57+
assertThat(res.getBrand()).isEqualTo("SHINHAN");
5858
assertThat(res.getLast4()).isEqualTo("****-****-****-1234");
5959
assertThat(res.getExpMonth()).isEqualTo(12);
6060
assertThat(res.getExpYear()).isEqualTo(2030);

src/test/java/com/backend/domain/product/controller/ApiV1ProductElasticsearchControllerTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package com.backend.domain.product.controller;
22

3-
import com.backend.domain.member.repository.MemberRepository;
43
import com.backend.domain.product.document.ProductDocument;
54
import com.backend.domain.product.dto.ProductSearchDto;
65
import com.backend.domain.product.enums.AuctionStatus;
76
import com.backend.domain.product.enums.ProductCategory;
87
import com.backend.domain.product.enums.ProductSearchSortType;
8+
import com.backend.domain.product.repository.elasticsearch.ProductElasticRepository;
99
import com.backend.domain.product.service.ProductSearchService;
10+
import com.backend.domain.product.service.ProductSyncService;
1011
import com.backend.global.redis.TestRedisConfiguration;
1112
import org.hamcrest.Matchers;
13+
import org.junit.jupiter.api.BeforeEach;
1214
import org.junit.jupiter.api.DisplayName;
1315
import org.junit.jupiter.api.Test;
1416
import org.springframework.beans.factory.annotation.Autowired;
@@ -44,7 +46,19 @@ class ApiV1ProductElasticsearchControllerTest {
4446
private ProductSearchService productSearchService;
4547

4648
@Autowired
47-
private MemberRepository memberRepository;
49+
private ProductSyncService productSyncService;
50+
51+
@Autowired
52+
private ProductElasticRepository productElasticRepository;
53+
54+
@BeforeEach
55+
void setUp() {
56+
// Elasticsearch 인덱스 초기화
57+
productElasticRepository.deleteAll();
58+
59+
// 테스트 데이터 재인덱싱
60+
productSyncService.indexAllProducts();
61+
}
4862

4963
@Test
5064
@DisplayName("상품 목록 조회")

src/test/java/com/backend/domain/product/repository/ProductElasticRepositoryTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import com.backend.domain.product.enums.ProductCategory;
88
import com.backend.domain.product.enums.ProductSearchSortType;
99
import com.backend.domain.product.repository.elasticsearch.ProductElasticRepository;
10+
import com.backend.domain.product.service.ProductSyncService;
1011
import com.backend.global.redis.TestRedisConfiguration;
12+
import org.junit.jupiter.api.BeforeEach;
1113
import org.junit.jupiter.api.DisplayName;
1214
import org.junit.jupiter.api.Test;
1315
import org.springframework.beans.factory.annotation.Autowired;
@@ -34,6 +36,18 @@ class ProductElasticRepositoryTest {
3436
@Autowired
3537
private ProductElasticRepository productElasticRepository;
3638

39+
@Autowired
40+
private ProductSyncService productSyncService;
41+
42+
@BeforeEach
43+
void setUp() {
44+
// Elasticsearch 인덱스 초기화
45+
productElasticRepository.deleteAll();
46+
47+
// 테스트 데이터 재인덱싱
48+
productSyncService.indexAllProducts();
49+
}
50+
3751
@Test
3852
@DisplayName("키워드로 상품 검색")
3953
void searchByKeyword() {

0 commit comments

Comments
 (0)