diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java index 4666a76..e7c4778 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java @@ -23,7 +23,7 @@ public CartService( this.shopperRepository = shopperRepository; } - //story_6 + // story_6 public ApplyCodeResponse applyCode(String username, ApplyCodeRequest request) { Optional shopper = shopperRepository.findByUsername(username); if (shopper.isPresent()) { @@ -37,12 +37,14 @@ public ApplyCodeResponse applyCode(String username, ApplyCodeRequest request) { promotion.get().getMaxDiscountAmount()); } - boolean skuMatch = request.getProductSkus().stream().anyMatch(x->promotion.get().getProductSkus().contains(x)); + boolean skuMatch = + request.getProductSkus().stream() + .anyMatch(x -> promotion.get().getProductSkus().contains(x)); if (skuMatch) { return new ApplyCodeResponse( - request.getCode(), - promotion.get().getDiscountAmount(), - promotion.get().getMaxDiscountAmount()); + request.getCode(), + promotion.get().getDiscountAmount(), + promotion.get().getMaxDiscountAmount()); } throw new BadRequestException("Cannot use discount code."); } else { diff --git a/kbazaar/src/test/java/com/kampus/kbazaar/cart/CartControllerTest.java b/kbazaar/src/test/java/com/kampus/kbazaar/cart/CartControllerTest.java index acfe89a..e83d6da 100644 --- a/kbazaar/src/test/java/com/kampus/kbazaar/cart/CartControllerTest.java +++ b/kbazaar/src/test/java/com/kampus/kbazaar/cart/CartControllerTest.java @@ -7,7 +7,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -18,7 +17,6 @@ import org.springframework.http.MediaType; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; @ExtendWith(SpringExtension.class) @AutoConfigureMockMvc(addFilters = false) @@ -32,15 +30,14 @@ public class CartControllerTest { @Autowired private MockMvc mockMvc; -// @InjectMocks private CartController cartController; + // @InjectMocks private CartController cartController; - @MockBean - private CartService cartService; + @MockBean private CartService cartService; @BeforeEach public void setup() { MockitoAnnotations.openMocks(this); -// this.mockMvc = MockMvcBuilders.standaloneSetup(cartController).build(); + // this.mockMvc = MockMvcBuilders.standaloneSetup(cartController).build(); } @Test @@ -49,11 +46,12 @@ public void getCart_ReturnsOk() throws Exception { .andExpect(status().isOk()); } -// @Test -// public void applyCodeIfSuccess_ShouldReturnOk() throws Exception { -// String username = "TechNinja"; -// when(cartService.applyCode(anyString(), any())).thenReturn(new ApplyCodeResponse()); -// mockMvc.perform(post("/api/v1/carts/{username}/promotions", username).contentType(MediaType.APPLICATION_JSON)) -// .andExpect(status().isOk()); -// } + // @Test + // public void applyCodeIfSuccess_ShouldReturnOk() throws Exception { + // String username = "TechNinja"; + // when(cartService.applyCode(anyString(), any())).thenReturn(new ApplyCodeResponse()); + // mockMvc.perform(post("/api/v1/carts/{username}/promotions", + // username).contentType(MediaType.APPLICATION_JSON)) + // .andExpect(status().isOk()); + // } }