-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
259 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
use macro_helper::generate_update_test; | ||
use serial_test::serial; | ||
use wp_api::comments::{ | ||
CommentCreateParams, CommentDeleteParams, CommentStatus, CommentWithEditContext, | ||
CommentCreateParams, CommentDeleteParams, CommentStatus, CommentUpdateParams, | ||
CommentWithEditContext, | ||
}; | ||
use wp_api_integration_tests::{ | ||
api_client, | ||
backend::{Backend, RestoreServer}, | ||
AssertResponse, FIRST_COMMENT_ID, FIRST_POST_ID, | ||
AssertResponse, FIRST_COMMENT_ID, FIRST_POST_ID, POST_ID_555, SECOND_COMMENT_ID, | ||
SECOND_USER_ID, | ||
}; | ||
use wp_cli::WpCliComment; | ||
|
||
|
@@ -16,7 +19,7 @@ async fn create_comment_with_just_content() { | |
&CommentCreateParams::new(FIRST_POST_ID, "foo".to_string()), | ||
|created_comment, comment_from_wp_cli| { | ||
assert_eq!(created_comment.content.raw, "foo"); | ||
assert_eq!(comment_from_wp_cli.comment_content, "foo"); | ||
assert_eq!(comment_from_wp_cli.content, "foo"); | ||
}, | ||
) | ||
.await; | ||
|
@@ -30,7 +33,7 @@ async fn create_comment_with_content_and_status() { | |
|created_comment, comment_from_wp_cli| { | ||
assert_eq!(created_comment.content.raw, "foo"); | ||
assert_eq!(created_comment.status, CommentStatus::Hold); | ||
assert_eq!(comment_from_wp_cli.comment_content, "foo"); | ||
assert_eq!(comment_from_wp_cli.content, "foo"); | ||
}, | ||
) | ||
.await; | ||
|
@@ -87,6 +90,128 @@ async fn trash_comment() { | |
RestoreServer::db().await; | ||
} | ||
|
||
generate_update_test!( | ||
update_author, | ||
author, | ||
SECOND_USER_ID, | ||
|updated_comment, updated_comment_from_wp_cli| { | ||
assert_eq!(updated_comment.author, SECOND_USER_ID); | ||
assert_eq!(updated_comment_from_wp_cli.author, SECOND_USER_ID.0); | ||
} | ||
); | ||
|
||
generate_update_test!( | ||
update_author_email, | ||
author_email, | ||
"[email protected]".to_string(), | ||
|updated_comment, updated_comment_from_wp_cli| { | ||
assert_eq!(updated_comment.author_email, "[email protected]"); | ||
assert_eq!(updated_comment_from_wp_cli.author_email, "[email protected]"); | ||
} | ||
); | ||
|
||
generate_update_test!( | ||
update_author_ip, | ||
author_ip, | ||
"127.0.0.1".to_string(), | ||
|updated_comment, updated_comment_from_wp_cli| { | ||
assert_eq!(updated_comment.author_ip, "127.0.0.1"); | ||
assert_eq!(updated_comment_from_wp_cli.author_ip, "127.0.0.1"); | ||
} | ||
); | ||
|
||
generate_update_test!( | ||
update_author_name, | ||
author_name, | ||
"foo".to_string(), | ||
|updated_comment, updated_comment_from_wp_cli| { | ||
assert_eq!(updated_comment.author_name, "foo"); | ||
assert_eq!(updated_comment_from_wp_cli.author_name, "foo"); | ||
} | ||
); | ||
|
||
generate_update_test!( | ||
update_author_url, | ||
author_url, | ||
"https://example.com".to_string(), | ||
|updated_comment, updated_comment_from_wp_cli| { | ||
assert_eq!(updated_comment.author_url, "https://example.com"); | ||
assert_eq!( | ||
updated_comment_from_wp_cli.author_url, | ||
"https://example.com" | ||
); | ||
} | ||
); | ||
|
||
generate_update_test!( | ||
update_author_user_agent, | ||
author_user_agent, | ||
"foo".to_string(), | ||
|updated_comment, updated_comment_from_wp_cli| { | ||
assert_eq!(updated_comment.author_user_agent, "foo"); | ||
assert_eq!(updated_comment_from_wp_cli.author_user_agent, "foo"); | ||
} | ||
); | ||
|
||
generate_update_test!( | ||
update_content, | ||
content, | ||
"foo".to_string(), | ||
|updated_comment, updated_comment_from_wp_cli| { | ||
assert_eq!(updated_comment.content.raw, "foo"); | ||
assert_eq!(updated_comment_from_wp_cli.content, "foo"); | ||
} | ||
); | ||
|
||
generate_update_test!( | ||
update_date, | ||
date, | ||
"2024-09-09T12:00:00".to_string(), | ||
|updated_comment, updated_comment_from_wp_cli| { | ||
assert_eq!(updated_comment.date, "2024-09-09T12:00:00"); | ||
assert_eq!(updated_comment_from_wp_cli.date, "2024-09-09 12:00:00"); | ||
} | ||
); | ||
|
||
generate_update_test!( | ||
update_date_gmt, | ||
date_gmt, | ||
"2024-09-09T12:00:00".to_string(), | ||
|updated_comment, updated_comment_from_wp_cli| { | ||
assert_eq!(updated_comment.date_gmt, "2024-09-09T12:00:00"); | ||
assert_eq!(updated_comment_from_wp_cli.date_gmt, "2024-09-09 12:00:00"); | ||
} | ||
); | ||
|
||
generate_update_test!( | ||
update_parent, | ||
parent, | ||
SECOND_COMMENT_ID, | ||
|updated_comment, updated_comment_from_wp_cli| { | ||
assert_eq!(updated_comment.parent, SECOND_COMMENT_ID); | ||
assert_eq!(updated_comment_from_wp_cli.parent, SECOND_COMMENT_ID.0); | ||
} | ||
); | ||
|
||
generate_update_test!( | ||
update_post, | ||
post, | ||
POST_ID_555, | ||
|updated_comment, updated_comment_from_wp_cli| { | ||
assert_eq!(updated_comment.post, POST_ID_555); | ||
assert_eq!(updated_comment_from_wp_cli.post, POST_ID_555.0); | ||
} | ||
); | ||
|
||
generate_update_test!( | ||
update_status, | ||
status, | ||
CommentStatus::Hold, | ||
|updated_comment, _| { | ||
assert_eq!(updated_comment.status, CommentStatus::Hold); | ||
} | ||
); | ||
|
||
async fn test_create_comment<F>(params: &CommentCreateParams, assert: F) | ||
where | ||
F: Fn(CommentWithEditContext, WpCliComment), | ||
|
@@ -101,3 +226,40 @@ where | |
assert(created_comment, created_comment_from_wp_cli); | ||
RestoreServer::db().await; | ||
} | ||
|
||
async fn test_update_comment<F>(params: &CommentUpdateParams, assert: F) | ||
where | ||
F: Fn(CommentWithEditContext, WpCliComment), | ||
{ | ||
let updated_comment = api_client() | ||
.comments() | ||
.update(&FIRST_COMMENT_ID, params) | ||
.await | ||
.assert_response() | ||
.data; | ||
let updated_comment_from_wp_cli = Backend::comment(&FIRST_COMMENT_ID).await; | ||
assert(updated_comment, updated_comment_from_wp_cli); | ||
RestoreServer::db().await; | ||
} | ||
|
||
mod macro_helper { | ||
macro_rules! generate_update_test { | ||
($ident:ident, $field:ident, $new_value:expr, $assertion:expr) => { | ||
paste::paste! { | ||
#[tokio::test] | ||
#[serial] | ||
async fn $ident() { | ||
let updated_value = $new_value; | ||
test_update_comment( | ||
&CommentUpdateParams { | ||
$field: Some(updated_value), | ||
..Default::default() | ||
}, $assertion) | ||
.await; | ||
} | ||
} | ||
}; | ||
} | ||
|
||
pub(super) use generate_update_test; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters