REST API: Modify the structure of our DELETE responses to be more explicit.

Add the `deleted` property to the root of the Response object to communicate if the delete action was successful. Move the state of the resource prior to the delete request under a new `previous` property.  As a result DELETE responses are now structured like so:
 `{ deleted: true, previous: { ... } }`

Also includes helpful information to DELETE requests for resources that are not trashable.

Props timmydcrawford, rmccue, jnylen0.
Fixes #38494.

git-svn-id: https://develop.svn.wordpress.org/trunk@39126 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Rachel Baker
2016-11-03 20:04:59 +00:00
parent b7cfad8697
commit 4757546045
12 changed files with 129 additions and 45 deletions
@@ -1888,12 +1888,14 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
'comment_post_ID' => self::$post_id,
'user_id' => self::$subscriber_id,
));
$request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
$request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
$request->set_param( 'force', 'false' );
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
$data = $response->get_data();
$this->assertEquals( self::$post_id, $data['post'] );
$this->assertEquals( 'trash', $data['status'] );
}
public function test_delete_item_skip_trash() {
@@ -1910,7 +1912,8 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
$data = $response->get_data();
$this->assertEquals( self::$post_id, $data['post'] );
$this->assertTrue( $data['deleted'] );
$this->assertNotEmpty( $data['previous']['post'] );
}
public function test_delete_item_already_trashed() {