Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wichapons committed Mar 31, 2024
2 parents f599e47 + eabdc1d commit 221c9d1
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.kampus.kbazaar.cart;

import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.kampus.kbazaar.promotion.PromotionService;
import com.kampus.kbazaar.security.JwtAuthFilter;
import java.math.BigDecimal;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -46,16 +49,29 @@ public void getCart_ReturnsOk() throws Exception {
.andExpect(status().isOk());
}

// @Test
// public void getCards_ReturnsCorrectResponse() throws Exception {
// mockMvc.perform(get("/api/v1/carts").contentType(MediaType.APPLICATION_JSON))
// .andDo(print())
// .andExpect(jsonPath("$.username").value("TechNinja"))
// .andExpect(jsonPath("$.items").isArray())
// .andExpect(jsonPath("$.discount").value(0))
// .andExpect(jsonPath("$.totalDiscount").value(0))
// .andExpect(jsonPath("$.subtotal").value(1))
// .andExpect(jsonPath("$.grandTotal").value(1))
// .andExpect(status().isOk());
// }
@Test
public void getCards_ReturnsCorrectResponse() throws Exception {
when(cartService.getAllCart())
.thenReturn(
List.of(
CartResponse.builder()
.username("TechNinja")
.discount(BigDecimal.valueOf(0))
.totalDiscount(BigDecimal.valueOf(0))
.subtotal(BigDecimal.valueOf(1))
.grandTotal(BigDecimal.valueOf(1))
.items(List.of())
.build()));

mockMvc.perform(get("/api/v1/carts").contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(jsonPath("$.length()").value(1))
.andExpect(jsonPath("$[0].username").value("TechNinja"))
.andExpect(jsonPath("$[0].items").isArray())
.andExpect(jsonPath("$[0].discount").value(0))
.andExpect(jsonPath("$[0].totalDiscount").value(0))
.andExpect(jsonPath("$[0].subtotal").value(1))
.andExpect(jsonPath("$[0].grandTotal").value(1))
.andExpect(status().isOk());
}
}

0 comments on commit 221c9d1

Please sign in to comment.