@@ -173,4 +173,73 @@ public void testShouldNotUpdateOrderWithInvalidToken() {
173173 assertEquals (responseObject .get ("message" ), "Failed to authenticate token!" );
174174 }
175175
176+ @ Test
177+ public void testShouldNotPartialUpdateOrder_WhenTokenIsMissing () {
178+
179+ int orderId = 1 ;
180+
181+ final OrderData partialUpdatedOrder = getPartialUpdatedOrder ();
182+
183+ final APIResponse response = this .request .patch ("/partialUpdateOrder/" + orderId , RequestOptions .create ()
184+ .setData (partialUpdatedOrder ));
185+
186+ final JSONObject responseObject = new JSONObject (response .text ());
187+
188+ assertEquals (response .status (), 403 );
189+ assertEquals (responseObject .get ("message" ), "Forbidden! Token is missing!" );
190+ }
191+
192+ @ Test
193+ public void testShouldNotPartialUpdateOrder_WhenOrderIdIsNotFound () {
194+ final APIResponse authResponse = this .request .post ("/auth" , RequestOptions .create ().setData (getCredentials ()));
195+
196+ final JSONObject authResponseObject = new JSONObject (authResponse .text ());
197+ final String token = authResponseObject .get ("token" ).toString ();
198+
199+ final OrderData updatedOrder = getPartialUpdatedOrder ();
200+
201+ final int orderId = 90 ;
202+
203+ final APIResponse response = this .request .patch ("/partialUpdateOrder/" + orderId , RequestOptions .create ()
204+ .setHeader ("Authorization" , token )
205+ .setData (updatedOrder ));
206+
207+
208+ final JSONObject responseObject = new JSONObject (response .text ());
209+
210+ assertEquals (response .status (), 404 );
211+ assertEquals (responseObject .get ("message" ), "No Order found with the given Order Id!" );
212+
213+ }
214+
215+ @ Test
216+ public void testShouldNotPartialUpdateOrder_WhenOrderDetailsAreNotProvided () {
217+ final APIResponse authResponse = this .request .post ("/auth" , RequestOptions .create ().setData (getCredentials ()));
218+
219+ final JSONObject authResponseObject = new JSONObject (authResponse .text ());
220+ final String token = authResponseObject .get ("token" ).toString ();
221+
222+ final int orderId = 2 ;
223+
224+ final APIResponse response = this .request .patch ("/partialUpdateOrder/" + orderId , RequestOptions .create ()
225+ .setHeader ("Authorization" , token ));
226+
227+ final JSONObject responseObject = new JSONObject (response .text ());
228+
229+ assertEquals (response .status (), 400 );
230+ assertEquals (responseObject .get ("message" ), "Invalid request, no data provided to update!" );
231+ }
232+
233+ @ Test
234+ public void testShouldNotPartialUpdateOrderWithInvalidToken () {
235+ final int orderId = 2 ;
236+
237+ final APIResponse response = this .request .patch ("/partialUpdateOrder/" + orderId , RequestOptions .create ()
238+ .setHeader ("Authorization" , "token273678" ));
239+
240+ final JSONObject responseObject = new JSONObject (response .text ());
241+
242+ assertEquals (response .status (), 400 );
243+ assertEquals (responseObject .get ("message" ), "Failed to authenticate token!" );
244+ }
176245}
0 commit comments