-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: 알림 도메인 테스트 작성 및 문서화 추가
- Loading branch information
Showing
3 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...st/java/com/prgrms/nabmart/domain/notification/controller/NotificationControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.prgrms.nabmart.domain.notification.controller; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; | ||
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.prgrms.nabmart.base.BaseControllerTest; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; | ||
|
||
class NotificationControllerTest extends BaseControllerTest { | ||
|
||
@Nested | ||
@DisplayName("sseConnection API 호출 시") | ||
class ConnectNotificationTest { | ||
|
||
@Test | ||
@DisplayName("성공") | ||
void connectNotification() throws Exception { | ||
//given | ||
SseEmitter emitter = new SseEmitter(); | ||
|
||
given(notificationService.connectNotification(any())).willReturn(emitter); | ||
|
||
//when | ||
ResultActions resultActions = mockMvc.perform(get("/api/v1/notifications/connect") | ||
.header(AUTHORIZATION, accessToken)); | ||
|
||
//then | ||
resultActions.andExpect(status().isOk()) | ||
.andDo(restDocs.document( | ||
requestHeaders( | ||
headerWithName(AUTHORIZATION).description("액세스 토큰"), | ||
headerWithName("Last-Event-ID").description("마지막 이벤트 ID").optional() | ||
) | ||
)); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/test/java/com/prgrms/nabmart/domain/notification/service/NotificationServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.prgrms.nabmart.domain.notification.service; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.then; | ||
|
||
import com.prgrms.nabmart.domain.notification.controller.request.ConnectNotificationCommand; | ||
import com.prgrms.nabmart.domain.notification.repository.EmitterRepository; | ||
import com.prgrms.nabmart.domain.user.repository.UserRepository; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class NotificationServiceTest { | ||
|
||
@InjectMocks | ||
NotificationService notificationService; | ||
|
||
@Mock | ||
UserRepository userRepository; | ||
|
||
@Mock | ||
EmitterRepository emitterRepository; | ||
|
||
@Nested | ||
@DisplayName("connectNotification 메서드 실행 시") | ||
class ConnectNotificationTest { | ||
|
||
@Test | ||
@DisplayName("성공") | ||
void success() { | ||
//given | ||
long userId = 1L; | ||
ConnectNotificationCommand connectNotificationCommand | ||
= ConnectNotificationCommand.of(userId, ""); | ||
|
||
//when | ||
SseEmitter emitter = notificationService.connectNotification( | ||
connectNotificationCommand); | ||
|
||
//then | ||
then(emitterRepository).should().save(any(), any()); | ||
} | ||
} | ||
} |