Skip to content

Commit 6cbf17c

Browse files
authored
Add /posts/<post_id>/revisions related errors and their integration tests (#864)
* Add `/posts/<post_id>/revisions` related errors and their integration tests * make fmt-rust
1 parent ef8fb22 commit 6cbf17c

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

wp_api/src/api_error.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ pub enum WpErrorCode {
284284
PostInvalidParent,
285285
#[serde(rename = "rest_revision_invalid_offset_number")]
286286
RevisionInvalidOffsetNumber,
287+
#[serde(rename = "rest_revision_invalid_page_number")]
288+
RevisionInvalidPageNumber,
287289
#[serde(rename = "rest_taxonomy_invalid")]
288290
TaxonomyInvalid,
289291
#[serde(rename = "rest_template_not_found")]
@@ -426,6 +428,11 @@ pub enum WpErrorCode {
426428
// If the create post request includes an id.
427429
#[serde(rename = "rest_post_exists")]
428430
PostExists,
431+
/// If a revision doesn't belong to the specified parent post.
432+
/// However, WordPress validates revision existence first via `get_revision()` which will
433+
/// return `rest_post_invalid_id` before checking parent-child relationships.
434+
#[serde(rename = "rest_revision_parent_id_mismatch")]
435+
RevisionParentIdMismatch,
429436
// If a create/update request to a non-hierarchical endpoint, such as `/tags`, include
430437
// `parent` argument
431438
#[serde(rename = "rest_taxonomy_not_hierarchical")]

wp_api_integration_tests/tests/test_post_revisions_err.rs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use wp_api::{post_revisions::PostRevisionListParams, posts::PostId};
1+
use wp_api::{
2+
post_revisions::{PostRevisionId, PostRevisionListParams},
3+
posts::PostId,
4+
};
25
use wp_api_integration_tests::prelude::*;
36

47
#[tokio::test]
@@ -27,6 +30,66 @@ async fn list_err_revision_invalid_offset_number() {
2730
.assert_wp_error(WpErrorCode::RevisionInvalidOffsetNumber)
2831
}
2932

33+
#[tokio::test]
34+
#[parallel]
35+
async fn list_err_revision_invalid_page_number() {
36+
api_client()
37+
.post_revisions()
38+
.list_with_edit_context(
39+
&revisioned_post_id(),
40+
&PostRevisionListParams {
41+
page: Some(99999999),
42+
..Default::default()
43+
},
44+
)
45+
.await
46+
.assert_wp_error(WpErrorCode::RevisionInvalidPageNumber)
47+
}
48+
49+
#[tokio::test]
50+
#[parallel]
51+
async fn retrieve_err_post_invalid_parent() {
52+
api_client()
53+
.post_revisions()
54+
.retrieve_with_edit_context(&PostId(99999999), &valid_revision_id())
55+
.await
56+
.assert_wp_error(WpErrorCode::PostInvalidParent)
57+
}
58+
59+
#[tokio::test]
60+
#[parallel]
61+
async fn retrieve_err_post_invalid_id() {
62+
api_client()
63+
.post_revisions()
64+
.retrieve_with_edit_context(&revisioned_post_id(), &PostRevisionId(99999999))
65+
.await
66+
.assert_wp_error(WpErrorCode::PostInvalidId)
67+
}
68+
69+
#[tokio::test]
70+
#[parallel]
71+
async fn delete_err_post_invalid_parent() {
72+
api_client()
73+
.post_revisions()
74+
.delete(&PostId(99999999), &valid_revision_id())
75+
.await
76+
.assert_wp_error(WpErrorCode::PostInvalidParent)
77+
}
78+
79+
#[tokio::test]
80+
#[parallel]
81+
async fn delete_err_post_invalid_id() {
82+
api_client()
83+
.post_revisions()
84+
.delete(&revisioned_post_id(), &PostRevisionId(99999999))
85+
.await
86+
.assert_wp_error(WpErrorCode::PostInvalidId)
87+
}
88+
3089
fn revisioned_post_id() -> PostId {
3190
PostId(TestCredentials::instance().revisioned_post_id)
3291
}
92+
93+
fn valid_revision_id() -> PostRevisionId {
94+
PostRevisionId(TestCredentials::instance().revision_id_for_revisioned_post_id)
95+
}

0 commit comments

Comments
 (0)