Skip to content

Add an 'extras' property to comments #807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion wp_api/src/comments.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
UserAvatarSize, UserId, WpApiParamOrder, WpResponseString,
JsonValue, UserAvatarSize, UserId, WpApiParamOrder, WpResponseString,
date::WpGmtDateTime,
impl_as_query_value_for_new_type, impl_as_query_value_from_to_string,
posts::PostId,
Expand Down Expand Up @@ -528,6 +528,9 @@ pub struct SparseComment {
pub comment_type: Option<CommentType>,
#[WpContext(edit, embed, view)]
pub author_avatar_urls: Option<HashMap<UserAvatarSize, WpResponseString>>,
#[serde(flatten)]
#[WpContext(edit, embed, view)]
pub extras: Option<JsonValue>,
// meta field is omitted for now: https://github.com/Automattic/wordpress-rs/issues/422
}

Expand Down
18 changes: 18 additions & 0 deletions wp_api_integration_tests/tests/test_comments_immut.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use wp_api::{
JsonValue,
comments::{
CommentId, CommentListParams, CommentRetrieveParams, CommentStatus, CommentType,
SparseCommentFieldWithEditContext, SparseCommentFieldWithEmbedContext,
Expand Down Expand Up @@ -207,6 +208,23 @@ async fn list_comments_with_edit_context_parse_author_avatar_urls(
});
}

#[tokio::test]
#[parallel]
async fn parse_extras() {
let comment = api_client()
.comments()
.retrieve_with_edit_context(&FIRST_COMMENT_ID, &CommentRetrieveParams::default())
.await
.assert_response()
.data;
match comment.extras {
JsonValue::Object(ref map) => {
assert!(map.contains_key("_links"));
}
_ => panic!("Expected extras to be an object"),
}
}

#[template]
#[rstest]
#[case::default(CommentListParams::default())]
Expand Down