Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions wp_api/src/api_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ pub enum WpErrorCode {
PostInvalidParent,
#[serde(rename = "rest_revision_invalid_offset_number")]
RevisionInvalidOffsetNumber,
#[serde(rename = "rest_revision_invalid_page_number")]
RevisionInvalidPageNumber,
#[serde(rename = "rest_taxonomy_invalid")]
TaxonomyInvalid,
#[serde(rename = "rest_template_not_found")]
Expand Down Expand Up @@ -426,6 +428,11 @@ pub enum WpErrorCode {
// If the create post request includes an id.
#[serde(rename = "rest_post_exists")]
PostExists,
/// If a revision doesn't belong to the specified parent post.
/// However, WordPress validates revision existence first via `get_revision()` which will
/// return `rest_post_invalid_id` before checking parent-child relationships.
#[serde(rename = "rest_revision_parent_id_mismatch")]
RevisionParentIdMismatch,
// If a create/update request to a non-hierarchical endpoint, such as `/tags`, include
// `parent` argument
#[serde(rename = "rest_taxonomy_not_hierarchical")]
Expand Down
65 changes: 64 additions & 1 deletion wp_api_integration_tests/tests/test_post_revisions_err.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use wp_api::{post_revisions::PostRevisionListParams, posts::PostId};
use wp_api::{
post_revisions::{PostRevisionId, PostRevisionListParams},
posts::PostId,
};
use wp_api_integration_tests::prelude::*;

#[tokio::test]
Expand Down Expand Up @@ -27,6 +30,66 @@ async fn list_err_revision_invalid_offset_number() {
.assert_wp_error(WpErrorCode::RevisionInvalidOffsetNumber)
}

#[tokio::test]
#[parallel]
async fn list_err_revision_invalid_page_number() {
api_client()
.post_revisions()
.list_with_edit_context(
&revisioned_post_id(),
&PostRevisionListParams {
page: Some(99999999),
..Default::default()
},
)
.await
.assert_wp_error(WpErrorCode::RevisionInvalidPageNumber)
}

#[tokio::test]
#[parallel]
async fn retrieve_err_post_invalid_parent() {
api_client()
.post_revisions()
.retrieve_with_edit_context(&PostId(99999999), &valid_revision_id())
.await
.assert_wp_error(WpErrorCode::PostInvalidParent)
}

#[tokio::test]
#[parallel]
async fn retrieve_err_post_invalid_id() {
api_client()
.post_revisions()
.retrieve_with_edit_context(&revisioned_post_id(), &PostRevisionId(99999999))
.await
.assert_wp_error(WpErrorCode::PostInvalidId)
}

#[tokio::test]
#[parallel]
async fn delete_err_post_invalid_parent() {
api_client()
.post_revisions()
.delete(&PostId(99999999), &valid_revision_id())
.await
.assert_wp_error(WpErrorCode::PostInvalidParent)
}

#[tokio::test]
#[parallel]
async fn delete_err_post_invalid_id() {
api_client()
.post_revisions()
.delete(&revisioned_post_id(), &PostRevisionId(99999999))
.await
.assert_wp_error(WpErrorCode::PostInvalidId)
}

fn revisioned_post_id() -> PostId {
PostId(TestCredentials::instance().revisioned_post_id)
}

fn valid_revision_id() -> PostRevisionId {
PostRevisionId(TestCredentials::instance().revision_id_for_revisioned_post_id)
}