Skip to content

Commit 16b37e7

Browse files
authored
Merge pull request #250 from prgrms-web-devcourse-final-project/feat/#233-add-notification-test
feat: 알림 테스트 코드 추가
2 parents 4819121 + dd5e2d7 commit 16b37e7

File tree

5 files changed

+759
-0
lines changed

5 files changed

+759
-0
lines changed
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
package devut.buzzerbidder.domain.notification.listener;
2+
3+
import static org.mockito.ArgumentMatchers.any;
4+
import static org.mockito.ArgumentMatchers.contains;
5+
import static org.mockito.ArgumentMatchers.eq;
6+
import static org.mockito.Mockito.times;
7+
import static org.mockito.Mockito.verify;
8+
9+
import devut.buzzerbidder.domain.liveitem.event.LiveAuctionEndedEvent;
10+
import devut.buzzerbidder.domain.notification.enums.NotificationType;
11+
import devut.buzzerbidder.domain.notification.service.NotificationService;
12+
import java.util.Map;
13+
import org.junit.jupiter.api.DisplayName;
14+
import org.junit.jupiter.api.Test;
15+
import org.junit.jupiter.api.extension.ExtendWith;
16+
import org.mockito.InjectMocks;
17+
import org.mockito.Mock;
18+
import org.mockito.junit.jupiter.MockitoExtension;
19+
20+
@ExtendWith(MockitoExtension.class)
21+
public class LiveAuctionEndedNotificationListenerTest {
22+
23+
@Mock
24+
private NotificationService notificationService;
25+
26+
@InjectMocks
27+
private LiveAuctionEndedNotificationListener listener;
28+
29+
// ========== 낙찰 성공 알림 테스트 ==========
30+
31+
@Test
32+
@DisplayName("t1: 낙찰 성공시 판매자에게 낙찰 알림 전송")
33+
void t1() {
34+
// given
35+
Long liveItemId = 1L;
36+
Long sellerUserId = 10L;
37+
Long winnerUserId = 20L;
38+
String liveItemName = "테스트 상품";
39+
Integer finalPrice = 50000;
40+
41+
LiveAuctionEndedEvent event = new LiveAuctionEndedEvent(
42+
liveItemId,
43+
liveItemName,
44+
sellerUserId,
45+
true,
46+
winnerUserId,
47+
finalPrice
48+
);
49+
50+
// when
51+
listener.handle(event);
52+
53+
// then
54+
verify(notificationService).createAndSend(
55+
eq(sellerUserId),
56+
eq(NotificationType.LIVE_SUCCESS_SELLER),
57+
contains("낙찰되었습니다"),
58+
eq("LIVE_ITEM"),
59+
eq(liveItemId),
60+
any(Map.class)
61+
);
62+
}
63+
64+
@Test
65+
@DisplayName("t2: 낙찰 성공시 낙찰자에게 낙찰 축하 알림 전송")
66+
void t2() {
67+
// given
68+
Long liveItemId = 2L;
69+
Long sellerUserId = 15L;
70+
Long winnerUserId = 25L;
71+
String liveItemName = "경매 상품";
72+
Integer finalPrice = 75000;
73+
74+
LiveAuctionEndedEvent event = new LiveAuctionEndedEvent(
75+
liveItemId,
76+
liveItemName,
77+
sellerUserId,
78+
true,
79+
winnerUserId,
80+
finalPrice
81+
);
82+
83+
// when
84+
listener.handle(event);
85+
86+
// then
87+
verify(notificationService).createAndSend(
88+
eq(winnerUserId),
89+
eq(NotificationType.LIVE_SUCCESS_BIDDER),
90+
contains("축하합니다"),
91+
eq("LIVE_ITEM"),
92+
eq(liveItemId),
93+
any(Map.class)
94+
);
95+
}
96+
97+
@Test
98+
@DisplayName("t3: 낙찰 성공시 판매자와 낙찰자 모두에게 알림 전송")
99+
void t3() {
100+
// given
101+
Long liveItemId = 3L;
102+
Long sellerUserId = 30L;
103+
Long winnerUserId = 40L;
104+
String liveItemName = "인기 상품";
105+
Integer finalPrice = 100000;
106+
107+
LiveAuctionEndedEvent event = new LiveAuctionEndedEvent(
108+
liveItemId,
109+
liveItemName,
110+
sellerUserId,
111+
true,
112+
winnerUserId,
113+
finalPrice
114+
);
115+
116+
// when
117+
listener.handle(event);
118+
119+
// then
120+
verify(notificationService, times(2)).createAndSend(
121+
any(Long.class),
122+
any(NotificationType.class),
123+
any(String.class),
124+
eq("LIVE_ITEM"),
125+
eq(liveItemId),
126+
any(Map.class)
127+
);
128+
}
129+
130+
@Test
131+
@DisplayName("t4: 판매자 알림 메시지에 상품명과 낙찰가가 포함됨")
132+
void t4() {
133+
// given
134+
String liveItemName = "특별한 상품";
135+
Integer finalPrice = 120000;
136+
137+
LiveAuctionEndedEvent event = new LiveAuctionEndedEvent(
138+
1L,
139+
liveItemName,
140+
10L,
141+
true,
142+
20L,
143+
finalPrice
144+
);
145+
146+
// when
147+
listener.handle(event);
148+
149+
// then
150+
verify(notificationService).createAndSend(
151+
eq(10L),
152+
eq(NotificationType.LIVE_SUCCESS_SELLER),
153+
contains(liveItemName),
154+
eq("LIVE_ITEM"),
155+
eq(1L),
156+
any(Map.class)
157+
);
158+
159+
verify(notificationService).createAndSend(
160+
eq(10L),
161+
eq(NotificationType.LIVE_SUCCESS_SELLER),
162+
contains(String.valueOf(finalPrice)),
163+
eq("LIVE_ITEM"),
164+
eq(1L),
165+
any(Map.class)
166+
);
167+
}
168+
169+
// ========== 유찰 알림 테스트 ==========
170+
171+
@Test
172+
@DisplayName("t5: 유찰시 판매자에게 유찰 알림 전송")
173+
void t5() {
174+
// given
175+
Long liveItemId = 5L;
176+
Long sellerUserId = 50L;
177+
String liveItemName = "유찰 상품";
178+
179+
LiveAuctionEndedEvent event = new LiveAuctionEndedEvent(
180+
liveItemId,
181+
liveItemName,
182+
sellerUserId,
183+
false,
184+
null,
185+
null
186+
);
187+
188+
// when
189+
listener.handle(event);
190+
191+
// then
192+
verify(notificationService).createAndSend(
193+
eq(sellerUserId),
194+
eq(NotificationType.LIVE_FAILED_SELLER),
195+
contains("유찰되었습니다"),
196+
eq("LIVE_ITEM"),
197+
eq(liveItemId),
198+
any(Map.class)
199+
);
200+
}
201+
202+
@Test
203+
@DisplayName("t6: 유찰시 낙찰자에게는 알림을 전송하지 않음")
204+
void t6() {
205+
// given
206+
Long liveItemId = 6L;
207+
Long sellerUserId = 60L;
208+
String liveItemName = "미낙찰 상품";
209+
210+
LiveAuctionEndedEvent event = new LiveAuctionEndedEvent(
211+
liveItemId,
212+
liveItemName,
213+
sellerUserId,
214+
false,
215+
null,
216+
null
217+
);
218+
219+
// when
220+
listener.handle(event);
221+
222+
// then
223+
verify(notificationService, times(1)).createAndSend(
224+
any(Long.class),
225+
any(NotificationType.class),
226+
any(String.class),
227+
any(String.class),
228+
any(Long.class),
229+
any(Map.class)
230+
);
231+
}
232+
233+
@Test
234+
@DisplayName("t7: 유찰 알림 메시지에 상품명이 포함됨")
235+
void t7() {
236+
String liveItemName = "유찰된 상품";
237+
238+
LiveAuctionEndedEvent event = new LiveAuctionEndedEvent(
239+
1L,
240+
liveItemName,
241+
10L,
242+
false,
243+
null,
244+
null
245+
);
246+
247+
// when
248+
listener.handle(event);
249+
250+
// then
251+
verify(notificationService).createAndSend(
252+
eq(10L),
253+
eq(NotificationType.LIVE_FAILED_SELLER),
254+
contains(liveItemName),
255+
eq("LIVE_ITEM"),
256+
eq(1L),
257+
any(Map.class)
258+
);
259+
}
260+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package devut.buzzerbidder.domain.notification.listener;
2+
3+
import static org.mockito.ArgumentMatchers.any;
4+
import static org.mockito.ArgumentMatchers.contains;
5+
import static org.mockito.ArgumentMatchers.eq;
6+
import static org.mockito.Mockito.verify;
7+
8+
import devut.buzzerbidder.domain.deal.event.PaymentCompleteEvent;
9+
import devut.buzzerbidder.domain.notification.enums.NotificationType;
10+
import devut.buzzerbidder.domain.notification.service.NotificationService;
11+
import java.util.Map;
12+
import org.junit.jupiter.api.DisplayName;
13+
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.api.extension.ExtendWith;
15+
import org.mockito.InjectMocks;
16+
import org.mockito.Mock;
17+
import org.mockito.junit.jupiter.MockitoExtension;
18+
19+
@ExtendWith(MockitoExtension.class)
20+
public class PaymentCompleteNotificationListenerTest {
21+
22+
@Mock
23+
private NotificationService notificationService;
24+
25+
@InjectMocks
26+
private PaymentCompleteNotificationListener listener;
27+
28+
@Test
29+
@DisplayName("t1: 잔금 결제 완료시 판매자에게 알림 전송")
30+
void t1() {
31+
// given
32+
Long dealId = 1L;
33+
Long buyerId = 10L;
34+
Long sellerId = 20L;
35+
Long itemId = 100L;
36+
String itemName = "테스트 상품";
37+
Long totalPrice = 100000L;
38+
Long depositAmount = 10000L;
39+
Long remainingAmount = 90000L;
40+
41+
PaymentCompleteEvent event = new PaymentCompleteEvent(
42+
dealId,
43+
buyerId,
44+
sellerId,
45+
itemId,
46+
itemName,
47+
totalPrice,
48+
depositAmount,
49+
remainingAmount
50+
);
51+
52+
// when
53+
listener.handlePaymentComplete(event);
54+
55+
// then
56+
verify(notificationService).createAndSend(
57+
eq(sellerId),
58+
eq(NotificationType.PAYMENT_COMPLETE),
59+
contains("잔금이 입금되었습니다"),
60+
eq("LIVE_DEAL"),
61+
eq(dealId),
62+
any(Map.class)
63+
);
64+
}
65+
66+
@Test
67+
@DisplayName("t2: 알림 메시지에 상품명이 포함됨")
68+
void t2() {
69+
// given
70+
String itemName = "특별한 상품";
71+
72+
PaymentCompleteEvent event = new PaymentCompleteEvent(
73+
1L, 10L, 20L, 100L, itemName, 100000L, 10000L, 90000L
74+
);
75+
76+
// when
77+
listener.handlePaymentComplete(event);
78+
79+
// then
80+
verify(notificationService).createAndSend(
81+
eq(20L),
82+
eq(NotificationType.PAYMENT_COMPLETE),
83+
contains(itemName),
84+
eq("LIVE_DEAL"),
85+
eq(1L),
86+
any(Map.class)
87+
);
88+
}
89+
90+
@Test
91+
@DisplayName("t3: 알림 메시지에 발송 요청 안내가 포함됨")
92+
void t3() {
93+
// given
94+
PaymentCompleteEvent event = new PaymentCompleteEvent(
95+
1L, 10L, 20L, 100L, "상품", 100000L, 10000L, 90000L
96+
);
97+
98+
// when
99+
listener.handlePaymentComplete(event);
100+
101+
// then
102+
verify(notificationService).createAndSend(
103+
eq(20L),
104+
eq(NotificationType.PAYMENT_COMPLETE),
105+
contains("발송해주세요"),
106+
eq("LIVE_DEAL"),
107+
eq(1L),
108+
any(Map.class)
109+
);
110+
}
111+
}

0 commit comments

Comments
 (0)