Skip to content

Commit 0472bf8

Browse files
authored
Add /templates related errors and their integration tests (#766)
1 parent bf9b8b7 commit 0472bf8

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

wp_api/src/api_error.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ pub enum WpErrorCode {
194194
CannotListApplicationPasswords,
195195
#[serde(rename = "rest_cannot_manage_plugins")]
196196
CannotManagePlugins,
197+
#[serde(rename = "rest_cannot_manage_templates")]
198+
CannotManageTemplates,
197199
#[serde(rename = "rest_cannot_read_application_password")]
198200
CannotReadApplicationPassword,
199201
#[serde(rename = "rest_cannot_read")]
@@ -280,10 +282,6 @@ pub enum WpErrorCode {
280282
RevisionInvalidOffsetNumber,
281283
#[serde(rename = "rest_taxonomy_invalid")]
282284
TaxonomyInvalid,
283-
#[serde(rename = "rest_template_already_trashed")]
284-
TemplateAlreadyTrashed,
285-
#[serde(rename = "rest_template_insert_error")]
286-
TemplateInsertError,
287285
#[serde(rename = "rest_template_not_found")]
288286
TemplateNotFound,
289287
#[serde(rename = "rest_term_invalid")]
@@ -363,6 +361,8 @@ pub enum WpErrorCode {
363361
SearchInvalidPageNumber,
364362
#[serde(rename = "rest_search_invalid_type")]
365363
SearchInvalidType,
364+
#[serde(rename = "rest_template_insert_error")]
365+
TemplateInsertError,
366366
#[serde(rename = "rest_upload_file_error")]
367367
UploadFileError,
368368
#[serde(rename = "rest_upload_file_too_big")]
@@ -422,6 +422,9 @@ pub enum WpErrorCode {
422422
// `parent` argument
423423
#[serde(rename = "rest_taxonomy_not_hierarchical")]
424424
TaxonomyNotHierarchical,
425+
// If the template is already trashed, the server returns `rest_template_not_found`
426+
#[serde(rename = "rest_template_already_trashed")]
427+
TemplateAlreadyTrashed,
425428
// If `force=true` is missing from delete user request.
426429
// If trash is not supported for the post type: https://github.com/WordPress/WordPress/blob/6.6.2/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L1011-L1029
427430
#[serde(rename = "rest_trash_not_supported")]

wp_api_integration_tests/tests/test_templates_err.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,43 @@ async fn delete_template_err_template_not_found() {
3232
.assert_wp_error(WpErrorCode::TemplateNotFound)
3333
}
3434

35+
#[tokio::test]
36+
#[parallel]
37+
async fn update_template_err_cannot_manage_templates() {
38+
api_client_as_subscriber()
39+
.templates()
40+
.update(
41+
&TemplateId(
42+
TestCredentials::instance()
43+
.integration_test_custom_template_id
44+
.to_string(),
45+
),
46+
&TemplateUpdateParams::default(),
47+
)
48+
.await
49+
.assert_wp_error(WpErrorCode::CannotManageTemplates)
50+
}
51+
52+
#[tokio::test]
53+
#[parallel]
54+
async fn update_template_err_invalid_author() {
55+
api_client()
56+
.templates()
57+
.update(
58+
&TemplateId(
59+
TestCredentials::instance()
60+
.integration_test_custom_template_id
61+
.to_string(),
62+
),
63+
&TemplateUpdateParams {
64+
author: Some(UserId(99999999)),
65+
..Default::default()
66+
},
67+
)
68+
.await
69+
.assert_wp_error(WpErrorCode::InvalidAuthor);
70+
}
71+
3572
#[tokio::test]
3673
#[parallel]
3774
async fn update_template_err_template_not_found() {

0 commit comments

Comments
 (0)