Skip to content

Commit

Permalink
test: write delete device-token-api test
Browse files Browse the repository at this point in the history
  • Loading branch information
jinlee1703 committed Oct 12, 2023
1 parent b8b4011 commit f8a9fe0
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.swmaestro.repl.gifthub.auth.entity.Member;
import org.swmaestro.repl.gifthub.auth.service.MemberService;
import org.swmaestro.repl.gifthub.notifications.dto.DeviceTokenRequestDto;
import org.swmaestro.repl.gifthub.notifications.dto.NotificationReadResponseDto;
import org.swmaestro.repl.gifthub.notifications.service.NotificationService;
Expand All @@ -38,6 +40,9 @@ public class NotificationControllerTest {
@MockBean
private NotificationService notificationService;

@MockBean
private MemberService memberService;

/**
* 알림 목록 조회 테스트
*/
Expand Down Expand Up @@ -121,12 +126,20 @@ void readNotificationTest() throws Exception {

@Test
@WithMockUser(username = "이진우", roles = "USER")
void deleteDeviceToken() {
void deleteDeviceToken() throws Exception {
String accessToken = "my.access.token";
String username = "이진우";
DeviceTokenRequestDto deviceTokenRequestDto = DeviceTokenRequestDto.builder().token("my.device.token").build();
Member member = Member.builder().username(username).build();

when(jwtProvider.resolveToken(any())).thenReturn(accessToken);
when(jwtProvider.getUsername(anyString())).thenReturn(username);
when(notificationService.saveDeviceToken(username, deviceTokenSaveRequestDto.getToken())).thenReturn(true);
when(memberService.read(username)).thenReturn(member);
when(notificationService.deleteDeviceToken(member, deviceTokenRequestDto.getToken())).thenReturn(true);

mockMvc.perform(delete("/notifications/device").header("Authorization", "Bearer " + accessToken)
.contentType("application/json")
.content(objectMapper.writeValueAsString(deviceTokenRequestDto)))
.andExpect(status().isOk());
}
}

0 comments on commit f8a9fe0

Please sign in to comment.