diff --git a/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java b/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java
index ae9abe8..3d9bb6a 100644
--- a/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java
+++ b/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java
@@ -208,7 +208,7 @@ public void testShouldUpdateTheOrderUsingPut() {
}
@Test
- public void testShouldUpdateTheOrderUsingPatch() {
+ public void testShouldPartialUpdateTheOrderUsingPatch() {
final APIResponse authResponse = this.request.post("/auth", RequestOptions.create().setData(getCredentials()));
@@ -221,10 +221,7 @@ public void testShouldUpdateTheOrderUsingPatch() {
final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create()
.setHeader("Authorization", token)
.setData(partialUpdatedOrder));
-
- final Logger logger = new Logger(response);
- logger.logResponseDetails();
-
+
final JSONObject updateOrderResponseObject = new JSONObject(response.text());
final JSONObject orderObject = updateOrderResponseObject.getJSONObject("order");
diff --git a/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/SadPathTests.java b/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/SadPathTests.java
index 5d54ce5..6acf8a6 100644
--- a/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/SadPathTests.java
+++ b/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/SadPathTests.java
@@ -173,4 +173,73 @@ public void testShouldNotUpdateOrderWithInvalidToken() {
assertEquals(responseObject.get("message"), "Failed to authenticate token!");
}
+ @Test
+ public void testShouldNotPartialUpdateOrder_WhenTokenIsMissing() {
+
+ int orderId = 1;
+
+ final OrderData partialUpdatedOrder = getPartialUpdatedOrder();
+
+ final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create()
+ .setData(partialUpdatedOrder));
+
+ final JSONObject responseObject = new JSONObject(response.text());
+
+ assertEquals(response.status(), 403);
+ assertEquals(responseObject.get("message"), "Forbidden! Token is missing!");
+ }
+
+ @Test
+ public void testShouldNotPartialUpdateOrder_WhenOrderIdIsNotFound() {
+ final APIResponse authResponse = this.request.post("/auth", RequestOptions.create().setData(getCredentials()));
+
+ final JSONObject authResponseObject = new JSONObject(authResponse.text());
+ final String token = authResponseObject.get("token").toString();
+
+ final OrderData updatedOrder = getPartialUpdatedOrder();
+
+ final int orderId = 90;
+
+ final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create()
+ .setHeader("Authorization", token)
+ .setData(updatedOrder));
+
+
+ final JSONObject responseObject = new JSONObject(response.text());
+
+ assertEquals(response.status(), 404);
+ assertEquals(responseObject.get("message"), "No Order found with the given Order Id!");
+
+ }
+
+ @Test
+ public void testShouldNotPartialUpdateOrder_WhenOrderDetailsAreNotProvided() {
+ final APIResponse authResponse = this.request.post("/auth", RequestOptions.create().setData(getCredentials()));
+
+ final JSONObject authResponseObject = new JSONObject(authResponse.text());
+ final String token = authResponseObject.get("token").toString();
+
+ final int orderId = 2;
+
+ final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create()
+ .setHeader("Authorization", token));
+
+ final JSONObject responseObject = new JSONObject(response.text());
+
+ assertEquals(response.status(), 400);
+ assertEquals(responseObject.get("message"), "Invalid request, no data provided to update!");
+ }
+
+ @Test
+ public void testShouldNotPartialUpdateOrderWithInvalidToken() {
+ final int orderId = 2;
+
+ final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create()
+ .setHeader("Authorization", "token273678"));
+
+ final JSONObject responseObject = new JSONObject(response.text());
+
+ assertEquals(response.status(), 400);
+ assertEquals(responseObject.get("message"), "Failed to authenticate token!");
+ }
}
diff --git a/test-suite/testng-restfulecommerce-partialupdateorder.xml b/test-suite/testng-restfulecommerce-partialupdateorder.xml
new file mode 100644
index 0000000..f18ec38
--- /dev/null
+++ b/test-suite/testng-restfulecommerce-partialupdateorder.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test-suite/testng-restfulecommerce.xml b/test-suite/testng-restfulecommerce.xml
index 53be956..0488e9b 100644
--- a/test-suite/testng-restfulecommerce.xml
+++ b/test-suite/testng-restfulecommerce.xml
@@ -14,6 +14,10 @@
+
+
+
+
@@ -31,7 +35,7 @@
-
+