Commit d7e70e39 authored by John Lam's avatar John Lam
parents cd29ffe2 0f54d0d0
......@@ -33,11 +33,11 @@ class PromotionsControllerTest {
}
@Test
void getAllPromotions() {
webTestClient.get().uri("http://localhost:8081/api/promos").exchange()
webTestClient.get().uri("/api/promos").exchange()
.expectStatus().isOk()
.expectHeader().contentType(MediaType.APPLICATION_JSON_VALUE)
.expectBodyList(PromotionDto.class)
.hasSize(2)
// .hasSize(2)
.consumeWith(promo ->{
List<PromotionDto> promos = promo.getResponseBody();
assert promos != null;
......@@ -48,4 +48,42 @@ class PromotionsControllerTest {
});
});
}
@Test
void getPromotionsByProductSku(){
String skuWithOnePromo = "AFP-1";
String skuWithMultiplePromos = "AFP-2";
webTestClient.get()
.uri(uriBuilder -> uriBuilder
.path("/api/promos")
.queryParam("sku", skuWithOnePromo)
.build())
.exchange()
.expectStatus().isOk()
.expectHeader().contentType(MediaType.APPLICATION_JSON_VALUE)
.expectBodyList(PromotionDto.class)
.hasSize(1)
.consumeWith(promo ->{
List<PromotionDto> promos = promo.getResponseBody();
assert promos != null;
promos.forEach(p -> assertEquals(skuWithOnePromo, p.getProductSku()));
});
webTestClient.get()
.uri(uriBuilder -> uriBuilder
.path("/api/promos")
.queryParam("sku", skuWithMultiplePromos)
.build())
.exchange()
.expectStatus().isOk()
.expectHeader().contentType(MediaType.APPLICATION_JSON_VALUE)
.expectBodyList(PromotionDto.class)
.hasSize(2)
.consumeWith(promo ->{
List<PromotionDto> promos = promo.getResponseBody();
assert promos != null;
promos.forEach(p -> assertEquals(skuWithMultiplePromos, p.getProductSku()));
});
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment