Skip to content

Commit

Permalink
test: write cancel-share api
Browse files Browse the repository at this point in the history
  • Loading branch information
jinlee1703 committed Oct 31, 2023
1 parent 4752fe7 commit dd08e14
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.swmaestro.repl.gifthub.giftcard.entity.Giftcard;
import org.swmaestro.repl.gifthub.giftcard.service.GiftcardService;
import org.swmaestro.repl.gifthub.util.JwtProvider;
import org.swmaestro.repl.gifthub.vouchers.dto.GptResponseDto;
Expand Down Expand Up @@ -326,4 +327,32 @@ void shareVoucher() throws Exception {
.andExpect(status().isOk());
}

/**
* 기프티콘 공유 취소 테스트
*/
@Test
@WithMockUser(username = "이진우", roles = "USER")
void shareCancel() throws Exception {
//Given
Long voucherId = 1L;
VoucherShareRequestDto voucherShareRequestDto = VoucherShareRequestDto.builder()
.message("축하드립니다")
.build();
VoucherShareResponseDto voucherShareResponseDto = VoucherShareResponseDto.builder()
.id("uuid")
.build();
Giftcard giftcard = Giftcard.builder()
.id("uuid")
.build();
//When
when(jwtProvider.resolveToken(any())).thenReturn("my_awesome_access_token");
when(jwtProvider.getUsername(anyString())).thenReturn("이진우");
when(voucherService.cancelShare(anyString(), eq(voucherId))).thenReturn(giftcard);

//Then
mockMvc.perform(delete("/vouchers/1/share")
.header("Authorization", "my_awesome_access_token")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}
}

0 comments on commit dd08e14

Please sign in to comment.