Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop to main #175

Merged
merged 12 commits into from
Nov 14, 2023
Prev Previous commit
Next Next commit
test: write voucher-check api test
jinlee1703 committed Nov 14, 2023
commit 9bf116d8eabe85cd0332483a118ec3bcb3141646
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@@ -32,6 +33,7 @@
import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateRequestDto;
import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseRequestDto;
import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseResponseDto;
import org.swmaestro.repl.gifthub.vouchers.entity.Voucher;
import org.swmaestro.repl.gifthub.vouchers.service.GptService;
import org.swmaestro.repl.gifthub.vouchers.service.PendingVoucherService;
import org.swmaestro.repl.gifthub.vouchers.service.SearchService;
@@ -363,4 +365,29 @@ void shareCancel() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}

@Test
@WithMockUser(username = "이진우", roles = "USER")
void check() throws Exception {
// Given
Voucher voucher = Voucher.builder()
.id(1L)
.user(User.builder()
.id(1L)
.username("이진우")
.build())
.build();

// When
when(jwtProvider.resolveToken(any())).thenReturn("my_awesome_access_token");
when(jwtProvider.getUsername(anyString())).thenReturn("이진우");
when(voucherService.check(anyString(), eq(voucher.getId()))).thenReturn(voucher.check());

// Then
Assertions.assertTrue(voucher.isChecked());
mockMvc.perform(post("/vouchers/1/check")
.header("Authorization", "my_awesome_access_token")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}
}