Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lasantosr committed Sep 2, 2024
1 parent b7e82e0 commit 6004aec
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 43 deletions.
14 changes: 14 additions & 0 deletions async-stripe-types/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ macro_rules! def_id {
}
}

impl From<&str> for $struct_name {
#[inline]
fn from(text: &str) -> Self {
Self(smol_str::SmolStr::from(text))
}
}

impl From<$struct_name> for String {
#[inline]
fn from(id: $struct_name) -> Self {
Expand All @@ -120,6 +127,13 @@ macro_rules! def_id {
}
}

impl From<&$struct_name> for $struct_name {
#[inline]
fn from(id: &$struct_name) -> Self {
id.clone()
}
}

#[cfg(feature = "deserialize")]
impl<'de> serde::Deserialize<'de> for $struct_name {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/it/blocking/charge.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use stripe_core::charge::RetrieveCharge;
use stripe_core::{charge::RetrieveCharge, ChargeId};

#[test]
fn is_charge_retrievable() {
let client = super::get_client();

let id = "ch_123".parse().unwrap();
let charge = RetrieveCharge::new(&id).send_blocking(&client).unwrap();
let id = ChargeId::from("ch_123");
let charge = RetrieveCharge::new(id).send_blocking(&client).unwrap();
assert_eq!(charge.id, "ch_123");
assert!(charge.customer.is_none());
assert!(charge.invoice.is_none());
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/it/blocking/checkout.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use stripe_checkout::checkout_session::RetrieveCheckoutSession;
use stripe_checkout::{checkout_session::RetrieveCheckoutSession, CheckoutSessionId};

use super::get_client;

#[test]
fn is_checkout_session_retrievable() {
let client = get_client();

let id = "cs_test_123".parse().unwrap();
let session = RetrieveCheckoutSession::new(&id).send_blocking(&client).unwrap();
let id = CheckoutSessionId::from("cs_test_123");
let session = RetrieveCheckoutSession::new(id).send_blocking(&client).unwrap();
assert_eq!(session.id, "cs_test_123");
}
7 changes: 4 additions & 3 deletions tests/tests/it/blocking/customer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use stripe_core::customer::{
CreateCustomer, DeleteCustomer, RetrieveCustomer, RetrieveCustomerReturned,
use stripe_core::{
customer::{CreateCustomer, DeleteCustomer, RetrieveCustomer, RetrieveCustomerReturned},
CustomerId,
};

use super::{get_base_test_config, get_client};
Expand Down Expand Up @@ -30,7 +31,7 @@ fn customer_create_and_delete_with_account() {
#[test]
fn retrieve_customer() {
let client = get_client();
let id = "cus_123".parse().unwrap();
let id = CustomerId::from("cus_123");
let ret = RetrieveCustomer::new(&id).send_blocking(&client).unwrap();
match ret {
RetrieveCustomerReturned::Customer(cust) => {
Expand Down
17 changes: 10 additions & 7 deletions tests/tests/it/blocking/invoice.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use stripe_billing::invoice::{
FinalizeInvoiceInvoice, PayInvoice, RetrieveInvoice, UpcomingInvoice,
UpcomingInvoiceSubscriptionItems,
use stripe_billing::{
invoice::{
FinalizeInvoiceInvoice, PayInvoice, RetrieveInvoice, UpcomingInvoice,
UpcomingInvoiceSubscriptionItems,
},
InvoiceId,
};
use stripe_core::ChargeId;

Expand All @@ -10,9 +13,9 @@ use super::get_client;
#[test]
fn is_invoice_retrievable() {
let client = get_client();
let id = "in_123".parse().unwrap();
let result = RetrieveInvoice::new(&id)
.expand(&["charge.balance_transaction"])
let id = InvoiceId::from("in_123");
let result = RetrieveInvoice::new(id)
.expand([String::from("charge.balance_transaction")])
.send_blocking(&client)
.unwrap();
let charge = result.charge.unwrap();
Expand All @@ -28,7 +31,7 @@ fn is_invoice_retrievable() {
fn is_invoice_payable() {
let client = get_client();

let id = "in_123".parse().unwrap();
let id = InvoiceId::from("in_123");

let result = PayInvoice::new(&id)
.forgive(true)
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/it/blocking/plan_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use stripe_billing::subscription_item::{
CreateSubscriptionItem, CreateSubscriptionItemPriceData,
CreateSubscriptionItemPriceDataRecurring, CreateSubscriptionItemPriceDataRecurringInterval,
};
use stripe_billing::PlanInterval;
use stripe_billing::{PlanId, PlanInterval};
use stripe_types::Currency;

use super::get_client;
Expand All @@ -15,8 +15,8 @@ use super::get_client;
fn can_create_plan() {
let client = get_client();

let id = "price_123".parse().unwrap();
let plan = RetrievePlan::new(&id).send_blocking(&client).unwrap();
let id = PlanId::from("price_123");
let plan = RetrievePlan::new(id).send_blocking(&client).unwrap();
assert_eq!(plan.interval, PlanInterval::Month);
assert_eq!(plan.amount, Some(2000));
}
Expand Down
10 changes: 4 additions & 6 deletions tests/tests/it/blocking/price.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use stripe_product::price::{UpdatePrice, UpdatePriceCurrencyOptions};
use stripe_product::PriceTaxBehavior;
use stripe_product::{PriceId, PriceTaxBehavior};
use stripe_types::Currency;

use super::get_client;
Expand All @@ -16,11 +16,9 @@ fn update_price() {
opt.unit_amount = Some(4);
currency_opts.insert(Currency::USD, opt);

let price_id = "price_123".parse().unwrap();
let price = UpdatePrice::new(&price_id)
.currency_options(&currency_opts)
.send_blocking(&client)
.unwrap();
let price_id = PriceId::from("price_123");
let price =
UpdatePrice::new(&price_id).currency_options(currency_opts).send_blocking(&client).unwrap();

assert_eq!(price.id, price_id);
assert_eq!(price.tax_behavior, Some(PriceTaxBehavior::Unspecified));
Expand Down
3 changes: 1 addition & 2 deletions tests/tests/it/blocking/product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use super::get_client;
fn create_product() {
let client = get_client();

let features = vec![Features::new("great feature")];
let product = CreateProduct::new("my product")
.marketing_features(&features)
.marketing_features([Features::new("great feature")])
.send_blocking(&client)
.unwrap();
assert_eq!(product.marketing_features.first().unwrap().name, Some("great feature".into()));
Expand Down
21 changes: 13 additions & 8 deletions tests/tests/it/blocking/subscription.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use stripe_billing::subscription::{
CancelSubscription, CancelSubscriptionCancellationDetails, RetrieveSubscription,
use stripe_billing::{
subscription::{
CancelSubscription, CancelSubscriptionCancellationDetails, RetrieveSubscription,
},
SubscriptionId,
};

use super::get_client;
Expand All @@ -11,8 +14,8 @@ use super::get_client;
fn is_subscription_retrievable() {
let client = get_client();

let id = "sub_123".parse().unwrap();
let subscription = RetrieveSubscription::new(&id).send_blocking(&client).unwrap();
let id = SubscriptionId::from("sub_123");
let subscription = RetrieveSubscription::new(id).send_blocking(&client).unwrap();
assert_eq!(subscription.id, "sub_123");
assert!(!subscription.customer.is_object());
}
Expand All @@ -22,9 +25,11 @@ fn is_subscription_retrievable() {
fn is_subscription_expandable() {
let client = get_client();

let id = "sub_123".parse().unwrap();
let subscription =
RetrieveSubscription::new(&id).expand(&["customer"]).send_blocking(&client).unwrap();
let id = SubscriptionId::from("sub_123");
let subscription = RetrieveSubscription::new(&id)
.expand([String::from("customer")])
.send_blocking(&client)
.unwrap();
assert_eq!(subscription.id, "sub_123");
assert!(subscription.customer.is_object());
}
Expand All @@ -37,7 +42,7 @@ fn can_prorate_when_cancelling_subscription() {
let client = get_client();

let details = CancelSubscriptionCancellationDetails::new();
let id = "sub_123".parse().unwrap();
let id = SubscriptionId::from("sub_123");
let result = CancelSubscription::new(&id)
.prorate(true)
.cancellation_details(details)
Expand Down
13 changes: 8 additions & 5 deletions tests/tests/it/blocking/subscription_item.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use chrono::Utc;
use stripe_billing::usage_record::{
CreateSubscriptionItemUsageRecord, CreateSubscriptionItemUsageRecordAction,
CreateSubscriptionItemUsageRecordTimestamp,
use stripe_billing::{
usage_record::{
CreateSubscriptionItemUsageRecord, CreateSubscriptionItemUsageRecordAction,
CreateSubscriptionItemUsageRecordTimestamp,
},
SubscriptionItemId,
};

use super::get_client;
Expand All @@ -10,8 +13,8 @@ use super::get_client;
fn can_create_usage_record() {
let client = get_client();

let subscription_item_id = "si_JVbsG8wiy20ycs".parse().unwrap();
let usage_record = CreateSubscriptionItemUsageRecord::new(&subscription_item_id, 42)
let subscription_item_id = SubscriptionItemId::from("si_JVbsG8wiy20ycs");
let usage_record = CreateSubscriptionItemUsageRecord::new(&subscription_item_id, 42u64)
.action(CreateSubscriptionItemUsageRecordAction::Increment)
.timestamp(CreateSubscriptionItemUsageRecordTimestamp::Timestamp(Utc::now().timestamp()))
.send_blocking(&client)
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/it/blocking/transfer_reversal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use stripe_connect::transfer_reversal::CreateIdTransferReversal;
use stripe_connect::{transfer_reversal::CreateIdTransferReversal, TransferId};

use super::get_client;

Expand All @@ -7,8 +7,8 @@ use super::get_client;
fn create_transfer_reversal() {
let client = get_client();

let id = "tr_Ll53U0VONALFk36".parse().unwrap();
let created = CreateIdTransferReversal::new(&id)
let id = TransferId::from("tr_Ll53U0VONALFk36");
let created = CreateIdTransferReversal::new(id)
.refund_application_fee(true)
.amount(4)
.send_blocking(&client)
Expand Down

0 comments on commit 6004aec

Please sign in to comment.