From 8070ec7a13ddd7f74e85e2a9fcc801057963486a Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Fri, 29 Aug 2025 00:24:40 -0400 Subject: [PATCH 1/2] Add `/posts//revisions` related errors and their integration tests --- wp_api/src/api_error.rs | 7 +++ .../tests/test_post_revisions_err.rs | 62 ++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index 51758fedf..9cdb96406 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -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")] @@ -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")] diff --git a/wp_api_integration_tests/tests/test_post_revisions_err.rs b/wp_api_integration_tests/tests/test_post_revisions_err.rs index 088cc73e2..007219c84 100644 --- a/wp_api_integration_tests/tests/test_post_revisions_err.rs +++ b/wp_api_integration_tests/tests/test_post_revisions_err.rs @@ -1,4 +1,4 @@ -use wp_api::{post_revisions::PostRevisionListParams, posts::PostId}; +use wp_api::{post_revisions::{PostRevisionListParams, PostRevisionId}, posts::PostId}; use wp_api_integration_tests::prelude::*; #[tokio::test] @@ -27,6 +27,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) +} From 601a4e215f6833433dc08df8f3e79be9b46e514b Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Fri, 29 Aug 2025 00:53:37 -0400 Subject: [PATCH 2/2] make fmt-rust --- wp_api_integration_tests/tests/test_post_revisions_err.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wp_api_integration_tests/tests/test_post_revisions_err.rs b/wp_api_integration_tests/tests/test_post_revisions_err.rs index 007219c84..c1804c60c 100644 --- a/wp_api_integration_tests/tests/test_post_revisions_err.rs +++ b/wp_api_integration_tests/tests/test_post_revisions_err.rs @@ -1,4 +1,7 @@ -use wp_api::{post_revisions::{PostRevisionListParams, PostRevisionId}, posts::PostId}; +use wp_api::{ + post_revisions::{PostRevisionId, PostRevisionListParams}, + posts::PostId, +}; use wp_api_integration_tests::prelude::*; #[tokio::test]