From 07b687e412f906d1642ac0d844b57a7159621c8d Mon Sep 17 00:00:00 2001 From: Steven Miller Date: Fri, 12 Jan 2024 11:24:29 -0500 Subject: [PATCH] Support additional_emails field on Customer --- CHANGELOG.md | 2 ++ src/client/customers.rs | 8 ++++++++ tests/api.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9dd8bf..45dabe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ Versioning]. ## [Unreleased] +* Support `additional_emails` field on `Customer`. + ## [0.8.1] - 2024-01-12 * Fix bug causing deserialization errors when `get_customer_costs` responses diff --git a/src/client/customers.rs b/src/client/customers.rs index 4154601..7432379 100644 --- a/src/client/customers.rs +++ b/src/client/customers.rs @@ -66,6 +66,9 @@ pub struct CreateCustomerRequest<'a> { pub name: &'a str, /// A valid email for the customer, to be used for notifications. pub email: &'a str, + /// Additional email addresses for this customer. + #[serde(skip_serializing_if = "Option::is_none")] + pub additional_emails: Option>, /// The customer's timezone as an identifier from the IANA timezone /// database. #[serde(skip_serializing_if = "Option::is_none")] @@ -102,6 +105,9 @@ pub struct UpdateCustomerRequest<'a> { /// A valid email for the customer, to be used for notifications. #[serde(skip_serializing_if = "Option::is_none")] pub email: Option<&'a str>, + /// Additional email addresses for this customer. + #[serde(skip_serializing_if = "Option::is_none")] + pub additional_emails: Option>, /// The external payments or invoicing solution connected to the customer. #[serde(skip_serializing_if = "Option::is_none")] #[serde(flatten)] @@ -152,6 +158,8 @@ pub struct Customer { pub name: String, /// A valid email for the customer, to be used for notifications. pub email: String, + /// Additional email addresses for this customer. + pub additional_emails: Vec, /// The customer's timezone as an identifier from the IANA timezone /// database. pub timezone: String, diff --git a/tests/api.rs b/tests/api.rs index 2baf678..1ce920d 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -145,6 +145,8 @@ async fn test_customers() { assert_eq!(customer.billing_address, None); assert_eq!(customer.shipping_address, None); assert_eq!(customer.tax_id, None); + let empty_emails: Vec = vec![]; + assert_eq!(customer.additional_emails, empty_emails); // Test fetching the customer by ID. let customer = client.get_customer(&customer.id).await.unwrap(); @@ -242,6 +244,37 @@ async fn test_customers() { assert_eq!(customer.email, "orb-testing+update-1@materialize.com"); let customer = client.get_customer(&customer.id).await.unwrap(); assert_eq!(customer.email, "orb-testing+update-1@materialize.com"); + let empty_emails: Vec = vec![]; + assert_eq!(customer.additional_emails, empty_emails); + + // Test updating additional_emails by ID + let customer = client + .update_customer( + &customer.id, + &UpdateCustomerRequest { + additional_emails: Some(vec![ + "orb-testing+update-2@materialize.com", + "orb-testing+update-3@materialize.com", + ]), + ..Default::default() + }, + ) + .await + .unwrap(); + assert!(customer + .additional_emails + .contains(&"orb-testing+update-2@materialize.com".to_string())); + assert!(customer + .additional_emails + .contains(&"orb-testing+update-3@materialize.com".to_string())); + let customer = client.get_customer(&customer.id).await.unwrap(); + assert!(customer + .additional_emails + .contains(&"orb-testing+update-2@materialize.com".to_string())); + assert!(customer + .additional_emails + .contains(&"orb-testing+update-3@materialize.com".to_string())); + assert_eq!(customer.email, "orb-testing+update-1@materialize.com"); // Test updating the customer by external ID. let customer = client