Skip to content

Commit b8cc918

Browse files
authored
Add /posts/<post_id>/autosaves related errors and their integration tests (#868)
1 parent a24cd84 commit b8cc918

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

wp_api/src/api_error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ pub enum WpErrorCode {
282282
PostInvalidPageNumber,
283283
#[serde(rename = "rest_post_invalid_parent")]
284284
PostInvalidParent,
285+
#[serde(rename = "rest_post_no_autosave")]
286+
PostNoAutosave,
285287
#[serde(rename = "rest_revision_invalid_offset_number")]
286288
RevisionInvalidOffsetNumber,
287289
#[serde(rename = "rest_revision_invalid_page_number")]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use wp_api::{
2+
post_revisions::PostRevisionId,
3+
posts::{PostCreateParams, PostId},
4+
};
5+
use wp_api_integration_tests::prelude::*;
6+
7+
#[tokio::test]
8+
#[parallel]
9+
async fn list_err_post_invalid_parent() {
10+
api_client()
11+
.autosaves()
12+
.list_with_edit_context(&PostId(99999999))
13+
.await
14+
.assert_wp_error(WpErrorCode::PostInvalidParent)
15+
}
16+
17+
#[tokio::test]
18+
#[parallel]
19+
async fn retrieve_err_post_invalid_parent() {
20+
api_client()
21+
.autosaves()
22+
.retrieve_with_edit_context(&PostId(99999999), &PostRevisionId(1))
23+
.await
24+
.assert_wp_error(WpErrorCode::PostInvalidParent)
25+
}
26+
27+
#[tokio::test]
28+
#[parallel]
29+
async fn retrieve_err_post_no_autosave() {
30+
api_client()
31+
.autosaves()
32+
.retrieve_with_edit_context(
33+
&PostId(TestCredentials::instance().revisioned_post_id),
34+
&PostRevisionId(1),
35+
)
36+
.await
37+
.assert_wp_error(WpErrorCode::PostNoAutosave)
38+
}
39+
40+
#[tokio::test]
41+
#[parallel]
42+
async fn create_err_post_invalid_id() {
43+
api_client()
44+
.autosaves()
45+
.create(&PostId(99999999), &PostCreateParams::default())
46+
.await
47+
.assert_wp_error(WpErrorCode::PostInvalidId)
48+
}

0 commit comments

Comments
 (0)