diff --git a/wp_api/src/lib.rs b/wp_api/src/lib.rs index 1af570235..d0f7041a7 100644 --- a/wp_api/src/lib.rs +++ b/wp_api/src/lib.rs @@ -1,7 +1,6 @@ #![allow(dead_code, unused_variables)] -use request::{endpoint::ApiEndpoint, WPNetworkRequest, WPNetworkResponse}; -use serde::Deserialize; +use request::{endpoint::ApiEndpoint, RequestMethod, WPNetworkRequest, WPNetworkResponse}; use std::collections::HashMap; use url::Url; @@ -356,15 +355,6 @@ impl WPAuthentication { } } -#[derive(Debug, uniffi::Enum)] -pub enum RequestMethod { - GET, - POST, - PUT, - DELETE, - HEAD, -} - #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, uniffi::Enum)] pub enum WPApiParamOrder { #[default] @@ -386,43 +376,12 @@ pub fn parse_api_details_response(response: WPNetworkResponse) -> Result>( - response: &'de WPNetworkResponse, -) -> Result { - parse_response_for_generic_errors(response)?; - serde_json::from_slice(&response.body).map_err(|err| WPApiError::ParsingError { - reason: err.to_string(), - response: String::from_utf8_lossy(&response.body).to_string(), - }) -} - -pub fn parse_response_for_generic_errors(response: &WPNetworkResponse) -> Result<(), WPApiError> { - let response_str = String::from_utf8_lossy(&response.body).to_string(); - // TODO: Further parse the response body to include error message - // TODO: Lots of unwraps to get a basic setup working - let status = http::StatusCode::from_u16(response.status_code).unwrap(); - if let Ok(rest_error) = serde_json::from_slice(&response.body) { - Err(WPApiError::RestError { - rest_error, - status_code: response.status_code, - response: response_str, - }) - } else if status.is_client_error() || status.is_server_error() { - Err(WPApiError::UnknownError { - status_code: response.status_code, - response: response_str, - }) - } else { - Ok(()) - } -} - // TODO: Figure out why we can't expose this method on `WPNetworkResponse` via UniFFI #[uniffi::export] pub fn get_link_header(response: &WPNetworkResponse, name: &str) -> Option { @@ -437,16 +396,6 @@ trait SparseField { fn as_str(&self) -> &str; } -#[macro_export] -macro_rules! add_uniffi_exported_parser { - ($fn_name:ident, $return_type: ty) => { - #[uniffi::export] - pub fn $fn_name(response: &WPNetworkResponse) -> Result<$return_type, WPApiError> { - parse_wp_response(response) - } - }; -} - #[macro_export] macro_rules! generate { ($type_name:ident) => { diff --git a/wp_api/src/plugins.rs b/wp_api/src/plugins.rs index 429ef53a8..1fa334ef2 100644 --- a/wp_api/src/plugins.rs +++ b/wp_api/src/plugins.rs @@ -1,9 +1,7 @@ use serde::{Deserialize, Serialize}; use wp_contextual::WPContextual; -use crate::{ - add_uniffi_exported_parser, parse_wp_response, SparseField, WPApiError, WPNetworkResponse, -}; +use crate::{add_uniffi_exported_parser, SparseField, WPApiError, WPNetworkResponse}; add_uniffi_exported_parser!(parse_filter_plugins_response, Vec); add_uniffi_exported_parser!(parse_filter_retrieve_plugin_response, SparsePlugin); diff --git a/wp_api/src/request.rs b/wp_api/src/request.rs index 5fff0369a..e0a34d450 100644 --- a/wp_api/src/request.rs +++ b/wp_api/src/request.rs @@ -1,8 +1,9 @@ use std::{collections::HashMap, fmt::Debug}; +use serde::Deserialize; use url::Url; -use crate::RequestMethod; +use crate::WPApiError; pub mod endpoint; @@ -80,6 +81,41 @@ impl WPNetworkResponse { pub fn body_as_string(&self) -> String { body_as_string(&self.body) } + + pub fn parse<'de, T: Deserialize<'de>>(&'de self) -> Result { + self.parse_response_for_generic_errors()?; + serde_json::from_slice(&self.body).map_err(|err| WPApiError::ParsingError { + reason: err.to_string(), + response: self.body_as_string(), + }) + } + + pub fn parse_with(&self, parser: F) -> Result + where + F: Fn(&WPNetworkResponse) -> Result, + { + parser(self) + } + + fn parse_response_for_generic_errors(&self) -> Result<(), WPApiError> { + // TODO: Further parse the response body to include error message + // TODO: Lots of unwraps to get a basic setup working + let status = http::StatusCode::from_u16(self.status_code).unwrap(); + if let Ok(rest_error) = serde_json::from_slice(&self.body) { + Err(WPApiError::RestError { + rest_error, + status_code: self.status_code, + response: self.body_as_string(), + }) + } else if status.is_client_error() || status.is_server_error() { + Err(WPApiError::UnknownError { + status_code: self.status_code, + response: self.body_as_string(), + }) + } else { + Ok(()) + } + } } impl Debug for WPNetworkResponse { @@ -101,6 +137,25 @@ impl Debug for WPNetworkResponse { } } +#[derive(Debug, uniffi::Enum)] +pub enum RequestMethod { + GET, + POST, + PUT, + DELETE, + HEAD, +} + fn body_as_string(body: &[u8]) -> String { String::from_utf8_lossy(body).to_string() } + +#[macro_export] +macro_rules! add_uniffi_exported_parser { + ($fn_name:ident, $return_type: ty) => { + #[uniffi::export] + pub fn $fn_name(response: &WPNetworkResponse) -> Result<$return_type, WPApiError> { + response.parse::<$return_type>() + } + }; +} diff --git a/wp_api/src/users.rs b/wp_api/src/users.rs index 1ff74941d..c193fdd33 100644 --- a/wp_api/src/users.rs +++ b/wp_api/src/users.rs @@ -4,8 +4,7 @@ use serde::{Deserialize, Serialize}; use wp_contextual::WPContextual; use crate::{ - add_uniffi_exported_parser, parse_wp_response, SparseField, WPApiError, WPApiParamOrder, - WPNetworkResponse, + add_uniffi_exported_parser, SparseField, WPApiError, WPApiParamOrder, WPNetworkResponse, }; add_uniffi_exported_parser!(parse_filter_users_response, Vec); diff --git a/wp_api/tests/integration_test_common.rs b/wp_api/tests/integration_test_common.rs index 78ea27f9c..68738a98d 100644 --- a/wp_api/tests/integration_test_common.rs +++ b/wp_api/tests/integration_test_common.rs @@ -2,7 +2,7 @@ use futures::Future; use http::HeaderMap; use std::{fs::read_to_string, process::Command}; use wp_api::{ - request::{WPNetworkRequest, WPNetworkResponse}, + request::{RequestMethod, WPNetworkRequest, WPNetworkResponse}, users::UserId, WPApiError, WPApiHelper, WPAuthentication, WPRestError, WPRestErrorCode, WPRestErrorWrapper, }; @@ -46,21 +46,6 @@ impl WPNetworkRequestExecutor for WPNetworkRequest { } } -pub trait WPNetworkResponseParser { - fn parse(&self, parser: F) -> Result - where - F: Fn(&WPNetworkResponse) -> Result; -} - -impl WPNetworkResponseParser for WPNetworkResponse { - fn parse(&self, parser: F) -> Result - where - F: Fn(&WPNetworkResponse) -> Result, - { - parser(self) - } -} - pub trait AssertWpError { fn assert_wp_error(self, expected_error_code: WPRestErrorCode); } @@ -214,13 +199,13 @@ impl AsyncWPNetworking { }) } - fn request_method(method: wp_api::RequestMethod) -> http::Method { + fn request_method(method: RequestMethod) -> http::Method { match method { - wp_api::RequestMethod::GET => reqwest::Method::GET, - wp_api::RequestMethod::POST => reqwest::Method::POST, - wp_api::RequestMethod::PUT => reqwest::Method::PUT, - wp_api::RequestMethod::DELETE => reqwest::Method::DELETE, - wp_api::RequestMethod::HEAD => reqwest::Method::HEAD, + RequestMethod::GET => reqwest::Method::GET, + RequestMethod::POST => reqwest::Method::POST, + RequestMethod::PUT => reqwest::Method::PUT, + RequestMethod::DELETE => reqwest::Method::DELETE, + RequestMethod::HEAD => reqwest::Method::HEAD, } } } diff --git a/wp_api/tests/test_plugins_err.rs b/wp_api/tests/test_plugins_err.rs index f753f0c93..62e856840 100644 --- a/wp_api/tests/test_plugins_err.rs +++ b/wp_api/tests/test_plugins_err.rs @@ -2,8 +2,8 @@ use wp_api::plugins::{PluginCreateParams, PluginStatus, PluginUpdateParams}; use wp_api::{WPContext, WPRestErrorCode}; use crate::integration_test_common::{ - api, api_as_subscriber, AssertWpError, WPNetworkRequestExecutor, WPNetworkResponseParser, - HELLO_DOLLY_PLUGIN_SLUG, WP_ORG_PLUGIN_SLUG_CLASSIC_WIDGETS, + api, api_as_subscriber, AssertWpError, WPNetworkRequestExecutor, HELLO_DOLLY_PLUGIN_SLUG, + WP_ORG_PLUGIN_SLUG_CLASSIC_WIDGETS, }; pub mod integration_test_common; @@ -18,7 +18,7 @@ async fn create_plugin_err_cannot_install_plugin() { .execute() .await .unwrap() - .parse(wp_api::plugins::parse_create_plugin_response) + .parse_with(wp_api::plugins::parse_create_plugin_response) .assert_wp_error(WPRestErrorCode::CannotInstallPlugin); } @@ -29,7 +29,7 @@ async fn delete_plugin_err_cannot_delete_active_plugin() { .execute() .await .unwrap() - .parse(wp_api::plugins::parse_delete_plugin_response) + .parse_with(wp_api::plugins::parse_delete_plugin_response) .assert_wp_error(WPRestErrorCode::CannotDeleteActivePlugin); } @@ -40,7 +40,7 @@ async fn list_plugins_err_cannot_view_plugins() { .execute() .await .unwrap() - .parse(wp_api::plugins::parse_retrieve_plugin_response_with_edit_context) + .parse_with(wp_api::plugins::parse_retrieve_plugin_response_with_edit_context) .assert_wp_error(WPRestErrorCode::CannotViewPlugins); } @@ -51,7 +51,7 @@ async fn retrieve_plugin_err_cannot_view_plugin() { .execute() .await .unwrap() - .parse(wp_api::plugins::parse_retrieve_plugin_response_with_edit_context) + .parse_with(wp_api::plugins::parse_retrieve_plugin_response_with_edit_context) .assert_wp_error(WPRestErrorCode::CannotViewPlugin); } @@ -67,7 +67,7 @@ async fn update_plugin_err_plugin_not_found() { .execute() .await .unwrap() - .parse(wp_api::plugins::parse_update_plugin_response) + .parse_with(wp_api::plugins::parse_update_plugin_response) .assert_wp_error(WPRestErrorCode::PluginNotFound); } @@ -83,6 +83,6 @@ async fn update_plugin_err_cannot_manage_plugins() { .execute() .await .unwrap() - .parse(wp_api::plugins::parse_update_plugin_response) + .parse_with(wp_api::plugins::parse_update_plugin_response) .assert_wp_error(WPRestErrorCode::CannotManagePlugins); } diff --git a/wp_api/tests/test_plugins_immut.rs b/wp_api/tests/test_plugins_immut.rs index 6e19040d8..fe952e723 100644 --- a/wp_api/tests/test_plugins_immut.rs +++ b/wp_api/tests/test_plugins_immut.rs @@ -7,8 +7,7 @@ use wp_api::{ }; use crate::integration_test_common::{ - api, WPNetworkRequestExecutor, WPNetworkResponseParser, CLASSIC_EDITOR_PLUGIN_SLUG, - HELLO_DOLLY_PLUGIN_SLUG, + api, WPNetworkRequestExecutor, CLASSIC_EDITOR_PLUGIN_SLUG, HELLO_DOLLY_PLUGIN_SLUG, }; pub mod integration_test_common; @@ -29,7 +28,7 @@ async fn filter_plugins( .execute() .await .unwrap() - .parse(wp_api::plugins::parse_filter_plugins_response); + .parse_with(wp_api::plugins::parse_filter_plugins_response); assert!(parsed_response.is_ok()); parsed_response .unwrap() @@ -48,7 +47,7 @@ async fn filter_retrieve_plugin( .execute() .await .unwrap() - .parse(wp_api::plugins::parse_filter_retrieve_plugin_response); + .parse_with(wp_api::plugins::parse_filter_retrieve_plugin_response); assert!(plugin_result.is_ok()); validate_sparse_plugin_fields(&plugin_result.unwrap(), fields); } @@ -115,7 +114,7 @@ async fn retrieve_plugin_with_edit_context( .execute() .await .unwrap() - .parse(wp_api::plugins::parse_retrieve_plugin_response_with_edit_context); + .parse_with(wp_api::plugins::parse_retrieve_plugin_response_with_edit_context); assert!( parsed_response.is_ok(), "Retrieve plugin failed!\nContext: {:?}\nPlugin: {:?}\nResponse was: '{:?}'", diff --git a/wp_api/tests/test_plugins_mut.rs b/wp_api/tests/test_plugins_mut.rs index 2e7da8fe7..3fe20a32c 100644 --- a/wp_api/tests/test_plugins_mut.rs +++ b/wp_api/tests/test_plugins_mut.rs @@ -1,8 +1,8 @@ use wp_api::plugins::{PluginCreateParams, PluginStatus, PluginUpdateParams}; use crate::integration_test_common::{ - api, run_and_restore_wp_content_plugins, WPNetworkRequestExecutor, WPNetworkResponseParser, - CLASSIC_EDITOR_PLUGIN_SLUG, HELLO_DOLLY_PLUGIN_SLUG, WP_ORG_PLUGIN_SLUG_CLASSIC_WIDGETS, + api, run_and_restore_wp_content_plugins, WPNetworkRequestExecutor, CLASSIC_EDITOR_PLUGIN_SLUG, + HELLO_DOLLY_PLUGIN_SLUG, WP_ORG_PLUGIN_SLUG_CLASSIC_WIDGETS, }; pub mod integration_test_common; @@ -22,7 +22,7 @@ async fn create_plugin() { .execute() .await .unwrap() - .parse(wp_api::plugins::parse_create_plugin_response) + .parse_with(wp_api::plugins::parse_create_plugin_response) .unwrap(); println!("Created Plugin: {:?}", created_plugin); }) @@ -43,7 +43,7 @@ async fn update_plugin() { .execute() .await .unwrap() - .parse(wp_api::plugins::parse_update_plugin_response) + .parse_with(wp_api::plugins::parse_update_plugin_response) .unwrap(); println!("Updated Plugin: {:?}", updated_plugin); }) @@ -60,7 +60,7 @@ async fn delete_plugin() { .execute() .await .unwrap() - .parse(wp_api::plugins::parse_delete_plugin_response) + .parse_with(wp_api::plugins::parse_delete_plugin_response) .unwrap(); println!("Deleted Plugin: {:?}", deleted_plugin); }) diff --git a/wp_api/tests/test_users_err.rs b/wp_api/tests/test_users_err.rs index c7aef0951..b063ea381 100644 --- a/wp_api/tests/test_users_err.rs +++ b/wp_api/tests/test_users_err.rs @@ -8,8 +8,8 @@ use wp_api::{ }; use crate::integration_test_common::{ - api, api_as_subscriber, AssertWpError, WPNetworkRequestExecutor, WPNetworkResponseParser, - FIRST_USER_ID, SECOND_USER_ID, SECOND_USER_SLUG, + api, api_as_subscriber, AssertWpError, WPNetworkRequestExecutor, FIRST_USER_ID, SECOND_USER_ID, + SECOND_USER_SLUG, }; pub mod integration_test_common; @@ -21,7 +21,7 @@ async fn create_user_err_cannot_create_user() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::CannotCreateUser); } @@ -37,7 +37,7 @@ async fn delete_user_err_user_cannot_delete() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::UserCannotDelete); } @@ -53,7 +53,7 @@ async fn delete_user_err_user_invalid_reassign() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::UserInvalidReassign); } @@ -66,7 +66,7 @@ async fn delete_current_user_err_user_invalid_reassign() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::UserInvalidReassign); } @@ -77,7 +77,7 @@ async fn list_users_err_forbidden_context() { .execute() .await .unwrap() - .parse(wp_api::users::parse_list_users_response_with_edit_context) + .parse_with(wp_api::users::parse_list_users_response_with_edit_context) .assert_wp_error(WPRestErrorCode::ForbiddenContext); } @@ -92,7 +92,7 @@ async fn list_users_err_forbidden_orderby_email() { .execute() .await .unwrap() - .parse(wp_api::users::parse_list_users_response_with_view_context) + .parse_with(wp_api::users::parse_list_users_response_with_view_context) .assert_wp_error(WPRestErrorCode::ForbiddenOrderBy); } @@ -107,7 +107,7 @@ async fn list_users_err_forbidden_who() { .execute() .await .unwrap() - .parse(wp_api::users::parse_list_users_response_with_view_context) + .parse_with(wp_api::users::parse_list_users_response_with_view_context) .assert_wp_error(WPRestErrorCode::ForbiddenWho); } @@ -122,7 +122,7 @@ async fn list_users_with_capabilities_err_user_cannot_view() { .execute() .await .unwrap() - .parse(wp_api::users::parse_list_users_response_with_edit_context) + .parse_with(wp_api::users::parse_list_users_response_with_edit_context) .assert_wp_error(WPRestErrorCode::UserCannotView); } @@ -137,7 +137,7 @@ async fn list_users_with_roles_err_user_cannot_view() { .execute() .await .unwrap() - .parse(wp_api::users::parse_list_users_response_with_edit_context) + .parse_with(wp_api::users::parse_list_users_response_with_edit_context) .assert_wp_error(WPRestErrorCode::UserCannotView); } @@ -152,7 +152,7 @@ async fn list_users_orderby_registered_date_err_forbidden_orderby() { .execute() .await .unwrap() - .parse(wp_api::users::parse_list_users_response_with_view_context) + .parse_with(wp_api::users::parse_list_users_response_with_view_context) .assert_wp_error(WPRestErrorCode::ForbiddenOrderBy); } @@ -163,7 +163,7 @@ async fn retrieve_user_err_user_invalid_id() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::UserInvalidId); } @@ -177,7 +177,7 @@ async fn retrieve_user_err_unauthorized() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::Unauthorized); } @@ -193,7 +193,7 @@ async fn update_user_err_cannot_edit() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::CannotEdit); } @@ -212,7 +212,7 @@ async fn update_user_err_user_invalid_argument() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::UserInvalidArgument); } @@ -228,7 +228,7 @@ async fn update_user_err_cannot_edit_roles() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::CannotEditRoles); } @@ -244,7 +244,7 @@ async fn update_user_err_user_invalid_email() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::UserInvalidEmail); } @@ -259,7 +259,7 @@ async fn update_user_email_err_invalid_param() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::InvalidParam); } @@ -274,7 +274,7 @@ async fn update_user_password_err_invalid_param() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::InvalidParam); } @@ -290,7 +290,7 @@ async fn update_user_err_user_invalid_role() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::UserInvalidRole); } @@ -306,7 +306,7 @@ async fn update_user_err_user_invalid_slug() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::UserInvalidSlug); } @@ -322,7 +322,7 @@ async fn create_user_err_user_exists() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::UserExists); } @@ -339,7 +339,7 @@ async fn delete_user_err_trash_not_supported() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .assert_wp_error(WPRestErrorCode::TrashNotSupported); } diff --git a/wp_api/tests/test_users_immut.rs b/wp_api/tests/test_users_immut.rs index 61ffe3ac1..5ee6796f1 100644 --- a/wp_api/tests/test_users_immut.rs +++ b/wp_api/tests/test_users_immut.rs @@ -9,7 +9,7 @@ use wp_api::{ }; use crate::integration_test_common::{ - api, WPNetworkRequestExecutor, WPNetworkResponseParser, FIRST_USER_ID, SECOND_USER_ID, + api, WPNetworkRequestExecutor, FIRST_USER_ID, SECOND_USER_ID, }; pub mod integration_test_common; @@ -22,7 +22,7 @@ async fn filter_users(#[case] fields: &[SparseUserField]) { .execute() .await .unwrap() - .parse(wp_api::users::parse_filter_users_response); + .parse_with(wp_api::users::parse_filter_users_response); assert!(parsed_response.is_ok()); parsed_response .unwrap() @@ -38,7 +38,7 @@ async fn filter_retrieve_user(#[case] fields: &[SparseUserField]) { .execute() .await .unwrap() - .parse(wp_api::users::parse_filter_retrieve_user_response); + .parse_with(wp_api::users::parse_filter_retrieve_user_response); assert!(user_result.is_ok()); validate_sparse_user_fields(&user_result.unwrap(), fields); } @@ -51,7 +51,7 @@ async fn filter_retrieve_current_user(#[case] fields: &[SparseUserField]) { .execute() .await .unwrap() - .parse(wp_api::users::parse_filter_retrieve_user_response); + .parse_with(wp_api::users::parse_filter_retrieve_user_response); assert!(user_result.is_ok()); validate_sparse_user_fields(&user_result.unwrap(), fields); } @@ -123,7 +123,7 @@ async fn retrieve_user_with_edit_context() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .is_ok()); } @@ -134,7 +134,7 @@ async fn retrieve_user_with_embed_context() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_embed_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_embed_context) .is_ok()); } @@ -145,7 +145,7 @@ async fn retrieve_user_with_view_context() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_view_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_view_context) .is_ok()); } @@ -156,7 +156,7 @@ async fn retrieve_current_user_with_edit_context() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .is_ok()); } @@ -167,7 +167,7 @@ async fn retrieve_current_user_with_embed_context() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_embed_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_embed_context) .is_ok()); } @@ -178,7 +178,7 @@ async fn retrieve_current_user_with_view_context() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_view_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_view_context) .is_ok()); } diff --git a/wp_api/tests/test_users_mut.rs b/wp_api/tests/test_users_mut.rs index 069e59871..42cdbfcb0 100644 --- a/wp_api/tests/test_users_mut.rs +++ b/wp_api/tests/test_users_mut.rs @@ -2,7 +2,7 @@ use wp_api::users::{UserCreateParams, UserDeleteParams, UserUpdateParams}; use wp_db::{DbUser, DbUserMeta}; use crate::integration_test_common::{ - api, WPNetworkRequestExecutor, WPNetworkResponseParser, FIRST_USER_ID, SECOND_USER_ID, + api, WPNetworkRequestExecutor, FIRST_USER_ID, SECOND_USER_ID, }; pub mod integration_test_common; @@ -26,7 +26,7 @@ async fn create_user() { .execute() .await .unwrap() - .parse(wp_api::users::parse_retrieve_user_response_with_edit_context) + .parse_with(wp_api::users::parse_retrieve_user_response_with_edit_context) .unwrap(); // Assert that the user is in DB @@ -71,7 +71,7 @@ async fn delete_current_user() { .execute() .await .unwrap() - .parse(wp_api::users::parse_delete_user_response) + .parse_with(wp_api::users::parse_delete_user_response) .unwrap(); assert!(deleted_user.deleted); assert_eq!(FIRST_USER_ID, deleted_user.previous.id);