|
| 1 | +use crate::url_query::FromUrlQueryPairs; |
| 2 | +use crate::url_query::UrlQueryPairsMap; |
1 | 3 | use crate::{ |
2 | 4 | date::WpGmtDateTime, |
3 | | - impl_as_query_value_for_new_type, |
| 5 | + impl_as_query_value_for_new_type, impl_as_query_value_from_to_string, |
4 | 6 | url_query::{AppendUrlQueryPairs, QueryPairs, QueryPairsExtension}, |
5 | 7 | users::UserId, |
6 | 8 | }; |
7 | 9 | use serde::{Deserialize, Serialize}; |
8 | 10 | use serde_repr::*; |
9 | 11 | use std::collections::HashMap; |
| 12 | +use wp_derive::WpDeriveParamsField; |
10 | 13 | use wp_serde_helper::deserialize_empty_vec_or_none; |
11 | 14 |
|
12 | 15 | use super::WpComSiteId; |
13 | 16 |
|
| 17 | +#[derive( |
| 18 | + Debug, |
| 19 | + Default, |
| 20 | + Clone, |
| 21 | + PartialEq, |
| 22 | + Eq, |
| 23 | + PartialOrd, |
| 24 | + Ord, |
| 25 | + Hash, |
| 26 | + Serialize, |
| 27 | + Deserialize, |
| 28 | + uniffi::Enum, |
| 29 | + strum_macros::EnumString, |
| 30 | + strum_macros::Display, |
| 31 | +)] |
| 32 | +#[serde(rename_all = "snake_case")] |
| 33 | +#[strum(serialize_all = "snake_case")] |
| 34 | +pub enum ListBotConversationsSummaryMethod { |
| 35 | + FirstMessage, |
| 36 | + #[default] |
| 37 | + LastMessage, |
| 38 | +} |
| 39 | + |
| 40 | +impl_as_query_value_from_to_string!(ListBotConversationsSummaryMethod); |
| 41 | + |
| 42 | +#[derive( |
| 43 | + Debug, Default, PartialEq, Eq, Serialize, Deserialize, uniffi::Record, WpDeriveParamsField, |
| 44 | +)] |
| 45 | +#[supports_pagination(false)] |
| 46 | +pub struct ListBotConversationsParams { |
| 47 | + #[uniffi(default = None)] |
| 48 | + pub summary_method: Option<ListBotConversationsSummaryMethod>, |
| 49 | +} |
| 50 | + |
14 | 51 | #[derive(Debug, PartialEq, Eq, Serialize, uniffi::Record)] |
15 | 52 | pub struct CreateBotConversationParams { |
16 | 53 | pub message: String, |
@@ -107,7 +144,9 @@ pub struct UserPaidSupportPlan { |
107 | 144 | pub struct BotConversationSummary { |
108 | 145 | pub chat_id: u64, |
109 | 146 | pub created_at: WpGmtDateTime, |
110 | | - pub last_message: BotMessageSummary, |
| 147 | + #[serde(alias = "first_message")] |
| 148 | + #[serde(alias = "last_message")] |
| 149 | + pub summary_message: BotMessageSummary, |
111 | 150 | } |
112 | 151 |
|
113 | 152 | #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, uniffi::Record)] |
@@ -231,17 +270,20 @@ mod tests { |
231 | 270 | #[case] json_file_path: &str, |
232 | 271 | #[case] expected_chat_id: u64, |
233 | 272 | ) { |
234 | | - let json = test_json(json_file_path).expect("Failed to read JSON file"); |
| 273 | + let json: Vec<u8> = test_json(json_file_path).expect("Failed to read JSON file"); |
235 | 274 | let conversation: BotConversation = serde_json::from_slice(json.as_slice()) |
236 | 275 | .expect("Failed to deserialize bot conversation"); |
237 | 276 | assert_eq!(conversation.chat_id, expected_chat_id); |
238 | 277 | } |
239 | 278 |
|
240 | | - #[test] |
241 | | - fn test_bot_conversation_summary_deserialization() { |
242 | | - let json = include_str!("../../tests/wpcom/support_bots/converation-list.json"); |
243 | | - let conversations: Vec<BotConversationSummary> = |
244 | | - serde_json::from_str(json).expect("Failed to deserialize bot conversation summary"); |
| 279 | + #[rstest] |
| 280 | + #[case("conversation-list-01.json")] |
| 281 | + #[case("conversation-list-02.json")] |
| 282 | + fn test_bot_conversation_summary_deserialization(#[case] json_file_path: &str) { |
| 283 | + let json = test_json(json_file_path).expect("Failed to read JSON file"); |
| 284 | + let conversations: Vec<BotConversationSummary> = serde_json::from_slice(json.as_slice()) |
| 285 | + .expect("Failed to deserialize bot conversation summary"); |
| 286 | + |
245 | 287 | assert_eq!(conversations.len(), 1); |
246 | 288 | assert_eq!(conversations[0].chat_id, 1965758); |
247 | 289 | } |
|
0 commit comments