Skip to content

Commit

Permalink
Merge pull request #17 from MaterializeInc/feat/plan-metadata
Browse files Browse the repository at this point in the history
Feat/plan metadata
  • Loading branch information
benesch authored Nov 23, 2023
2 parents 6bc3c8f + 3aba3e2 commit e0b93b0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 34 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
include:
- build: macos
os: macos-latest
rust: 1.65.0
rust: 1.67.0
- build: ubuntu
os: ubuntu-latest
rust: 1.65.0
rust: 1.67.0
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -36,7 +36,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.65.0
toolchain: 1.67.0
default: true
components: rustfmt
- run: cargo fmt -- --check
Expand All @@ -47,7 +47,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.65.0
toolchain: 1.67.0
default: true
components: clippy
- uses: actions-rs/clippy-check@v1
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ Versioning].

## [Unreleased] <!-- #release:date -->

* Add support for Plan metadata.
* Bump MSRV to 1.67.

## [0.6.0] - 2023-05-12

* Modified the `InvoiceSubscription` field to be optional.

## [0.5.0] - 2023-05-11

* Add `amount_due` as part of `Invoice`.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ categories = ["api-bindings", "web-programming"]
keywords = ["orb", "billing", "api", "sdk"]
repository = "https://github.com/MaterializeInc/rust-orb-billing"
version = "0.6.0"
rust-version = "1.65"
rust-version = "1.67"
edition = "2021"

[dependencies]
Expand Down
5 changes: 5 additions & 0 deletions src/client/plans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::BTreeMap;

use futures_core::Stream;
use reqwest::Method;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -58,6 +60,9 @@ pub struct Plan {
/// The time at which the plan was created.
#[serde(with = "time::serde::rfc3339")]
pub created_at: OffsetDateTime,
/// Arbitrary metadata that is attached to the plan. Cannot be nested, must have string values.
#[serde(default)]
pub metadata: BTreeMap<String, String>,
// TODO: many missing fields.
}

Expand Down
77 changes: 48 additions & 29 deletions tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async fn delete_all_test_customers(client: &Client) {
.list_customers(&MAX_PAGE_LIST_PARAMS)
.try_filter(|customer| future::ready(customer.name.starts_with(TEST_PREFIX)))
.try_for_each_concurrent(Some(CONCURRENCY_LIMIT), |customer| async move {
info!(%customer.id, "deleting custome");
info!(%customer.id, "deleting customer");
client.delete_customer(&customer.id).await
})
.await
Expand All @@ -87,11 +87,11 @@ async fn create_test_customer(client: &Client, i: usize) -> Customer {
client
.create_customer(&CreateCustomerRequest {
name: &format!("{TEST_PREFIX}-{i}"),
email: "orb-testing-{i}@materialize.com",
email: &format!("orb-testing-{i}@materialize.com"),
external_id: None,
payment_provider: Some(CustomerPaymentProviderRequest {
kind: PaymentProvider::Stripe,
id: "cus_fake_{i}",
id: &format!("cus_fake_{i}"),
}),
..Default::default()
})
Expand Down Expand Up @@ -385,28 +385,31 @@ async fn test_events() {
events,
vec![
Event {
id: ids[2].clone(),
id: ids[0].clone(),
customer_id: customer.id.clone(),
external_customer_id: None,
// TODO: replace this with `None` once an inconsistency in the Orb API is fixed.
external_customer_id: Some("".into()),
event_name: "test".into(),
properties: BTreeMap::new(),
timestamp: timestamps[2],
timestamp: timestamps[0],
},
Event {
id: ids[1].clone(),
customer_id: customer.id.clone(),
external_customer_id: None,
// TODO: replace this with `None` once an inconsistency in the Orb API is fixed.
external_customer_id: Some("".into()),
event_name: "test".into(),
properties: BTreeMap::new(),
timestamp: timestamps[1],
},
Event {
id: ids[0].clone(),
id: ids[2].clone(),
customer_id: customer.id.clone(),
external_customer_id: None,
// TODO: replace this with `None` once an inconsistency in the Orb API is fixed.
external_customer_id: Some("".into()),
event_name: "test".into(),
properties: BTreeMap::new(),
timestamp: timestamps[0],
timestamp: timestamps[2],
},
]
);
Expand All @@ -427,26 +430,38 @@ async fn test_events() {
.await
.unwrap();

// Extremely sketchy sleep seems to be required for search results to
// reflect the amendment.
time::sleep(Duration::from_secs(60)).await;
// Orb takes its time registering the amendment in the search output. Let's try a few times
// before giving up.
for iteration in 0..5 {
// Extremely sketchy sleep.
time::sleep(Duration::from_secs(60)).await;

let events: Vec<_> = client
.search_events(&EventSearchParams::default().event_ids(&[&ids[0]]))
.try_collect()
.await
.unwrap();
assert_eq!(
events,
vec![Event {
id: ids[0].clone(),
customer_id: customer.id.clone(),
external_customer_id: None,
event_name: "new test".into(),
properties: properties.clone(),
timestamp: timestamps[0],
},]
);
let events: Vec<_> = client
.search_events(&EventSearchParams::default().event_ids(&[&ids[0]]))
.try_collect()
.await
.unwrap();
if events.get(0).map(|e| e.event_name.clone()) != Some("new test".into()) {
info!(" events list not updated after {iteration} attempts.");
if iteration < 5 {
continue;
}
}
assert_eq!(
events,
vec![Event {
id: ids[0].clone(),
customer_id: customer.id.clone(),
// TODO: replace this with `None` once an inconsistency in the Orb API is fixed.
external_customer_id: Some("".into()),
event_name: "new test".into(),
properties: properties.clone(),
timestamp: timestamps[0],
},]
);
// Exit the loop
break;
}

// Test that deprecating an event removes it from search results.
client.deprecate_event(&ids[0]).await.unwrap();
Expand Down Expand Up @@ -503,6 +518,10 @@ async fn test_subscriptions() {

assert_eq!(subscription.customer.id, customer.id);
assert_eq!(subscription.plan.external_id.as_deref(), Some("test"));
assert_eq!(
subscription.plan.metadata.get("purpose"),
Some(&"test".to_string())
);
assert_eq!(subscription.net_terms, 3);
assert!(subscription.auto_collection);

Expand Down

0 comments on commit e0b93b0

Please sign in to comment.