Commit 583b954c authored by John Lam's avatar John Lam

merge branch with dev before pushing

parents bc3b1318 b3ee5e26
......@@ -37,8 +37,7 @@ public class ProductService {
return productRepository.findAll();
}
public Mono<Product> updateProductBySku(String sku, Product product){
public Mono<Product> updateProductBySku(String sku, Product product){
return productRepository.findBySku(sku)
.flatMap(dbProduct -> {
dbProduct.setUpc(product.getUpc());
......
......@@ -36,6 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import reactor.core.publisher.Mono;
import java.util.Random;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.*;
......@@ -90,7 +91,8 @@ class ProductControllerTest {
.expectBodyList(Product.class)
.consumeWith(product ->{
List<Product> products = product.getResponseBody();
products.forEach( p ->{
assert products != null;
products.forEach(p ->{
assertNotNull(p.getSku());
assertNotNull(p.getUpc());
System.out.println("Product SKU: " + p.getSku());
......@@ -115,14 +117,42 @@ class ProductControllerTest {
*/
@Test
public void testDeleteProduct(){
String sku = "SH=1123";
webTestClient.delete().uri("/api/products".concat("/{sku}"),sku)
Product deleteLater = new Product("SH=1123", "3d2dsd9cm", "Blue Sweater", "A nice red sweater", 23.99f, 45,
"", "SweatCo", "Sweatshirts");
webTestClient.get()
.uri("/api/products".concat("/{productSku}"), deleteLater.getSku())
.exchange()
.expectStatus().isNotFound();
webTestClient.post()
.uri("/api/products")
.contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
.body(Mono.just(deleteLater), Product.class)
.exchange()
.expectStatus().isOk()
.expectBody(Product.class);
webTestClient.delete()
.uri("/api/products".concat("/{productSku}"), deleteLater.getSku())
.accept(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
.exchange()
.expectStatus().isOk()
.expectBody(Void.class);
System.out.println("Deletion Successful. Ending test...");
webTestClient.get()
.uri("/api/products".concat("/{productSku}"), deleteLater.getSku())
.exchange()
.expectStatus().isNotFound();
// String sku = "SH=1123";
// webTestClient.delete().uri("/api/products".concat("/{sku}"),sku)
// .accept(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
// .exchange()
// .expectStatus().isOk()
// .expectBody(Void.class);
//
// System.out.println("Deletion Successful. Ending test...");
}
@Test
......@@ -142,10 +172,11 @@ class ProductControllerTest {
@Test
public void updateProduct(){
double newPrice = 49.99;
String sku = "SH=1123";
Random rd = new Random();
float newPrice = rd.nextFloat()*100;
String sku = "SKU-PUT";
Product product = new Product(sku, "3d2dsd9cm", "Blue Sweater",
"A Nice red sweater", (float) newPrice, 45, "",
"A Nice red sweater", newPrice, 45, "",
"SweatCo", "Sweatshirts");
webTestClient.put().uri("/api/products".concat("/{sku}"),sku)
.contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
......@@ -162,7 +193,7 @@ class ProductControllerTest {
double newPrice = 49.99;
String sku = "SH=2021";
Product product = new Product(sku, "3d2dsd9cm", "Blue Sweater",
"A Nice red sweater", (float) 23.99, 45, "",
"A Nice red sweater", 23.99f, 45, "",
"SweatCo", "Sweatshirts");
webTestClient.put().uri("/api/products".concat("/{sku}"),sku)
.contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
......
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