Skip to content

Commit

Permalink
Add more tests for closable issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mzeitlin11 committed Nov 26, 2023
1 parent 0b46685 commit 1f83a15
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 6 deletions.
5 changes: 4 additions & 1 deletion async-stripe/src/client/base/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ mod tests {

// Start a lightweight mock server.
let server = MockServer::start_async().await;
let message ="Your destination account needs to have at least one of the following capabilities enabled: transfers, crypto_transfers, legacy_payments";
let message = "Your destination account needs to have at least one of the following capabilities enabled: transfers, crypto_transfers, legacy_payments";
let log_url = "https://dashboard.stripe.com/logs/req_nIhlutaV4amLEs?t=1685040634";
let mock = server.mock(|when, then| {
when.method(GET).path("/v1/transfers");
Expand All @@ -412,6 +412,9 @@ mod tests {
assert_eq!(err.type_, ApiErrorsType::InvalidRequestError);
assert_eq!(err.message.as_deref(), Some(message));
assert_eq!(err.request_log_url.as_deref(), Some(log_url));
// NB: `Unknown` here because the error code reported in the issue is not
// present in the OpenAPI spec. Reporting unknown instead of an error seems
// better regardless so that stripe adding new variants is not a breaking change
assert_eq!(err.code, Some(ApiErrorsCode::Unknown));
}
_ => panic!("Expected stripe error, got {:?}", res),
Expand Down
2 changes: 1 addition & 1 deletion openapi/id_prefixes.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"subscription_item": "si",
"subscription_schedule": "sub_sched",
"tax_code": "txcd",
"tax_id": "txi",
"tax_id": ["txi", "atxi"],
"tax_rate": "txr",
"tax_deducted_at_source": "itds",
"terminal.reader": "tmr",
Expand Down
5 changes: 3 additions & 2 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ futures-util = { version = "0.3.21" }
tokio = { version = "1.24.1", features = ["rt", "macros"] }
stripe_types = {path = "../stripe_types"}
async-stripe = {path = "../async-stripe"}
stripe_connect = {path = "../generated/stripe_connect", features = ["account"]}
stripe_connect = {path = "../generated/stripe_connect", features = ["account", "transfer_reversal"]}
stripe_billing = {path = "../generated/stripe_billing", features = ["invoice", "plan", "subscription", "subscription_item", "usage_record"]}
stripe_core = {path = "../generated/stripe_core", features = ["customer", "charge"]}
stripe_core = {path = "../generated/stripe_core", features = ["customer", "charge", "token"]}
stripe_checkout = {path = "../generated/stripe_checkout", features = ["session"]}
stripe_product = {path = "../generated/stripe_product", features = ["product", "price", "promotion_code"]}

[features]
async = []
Expand Down
34 changes: 33 additions & 1 deletion tests/tests/it/blocking/invoice.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use stripe_billing::invoice::{PayInvoice, RetrieveInvoice};
use stripe_billing::invoice::{
FinalizeInvoiceInvoice, PayInvoice, RetrieveInvoice, UpcomingInvoice,
UpcomingInvoiceSubscriptionItems,
};

use crate::mock;

Expand All @@ -16,14 +19,43 @@ fn is_invoice_retrievable() {
}

// https://github.com/arlyon/async-stripe/issues/446
// https://github.com/arlyon/async-stripe/issues/352
#[test]
fn is_invoice_payable() {
mock::with_client(|client| {
let mut payer = PayInvoice::new();
payer.forgive = Some(true);
payer.off_session = Some(true);
payer.paid_out_of_band = Some(true);
let id = "in_123".parse().unwrap();
let result = payer.send(client, &id).unwrap();
assert_eq!(result.id, Some(id));
assert_eq!(result.paid_out_of_band, true);
})
}

#[test]
// https://github.com/arlyon/async-stripe/issues/442
fn finalize_invoice() {
mock::with_client(|client| {
let mut finalize = FinalizeInvoiceInvoice::new();
finalize.auto_advance = Some(true);
let id = "in_123".parse().unwrap();
let result = finalize.send(client, &id).unwrap();
assert_eq!(result.id, Some(id));
assert_eq!(result.auto_advance, Some(true));
})
}

#[test]
// https://github.com/arlyon/async-stripe/blob/ca5269ebcf9cbd7005f3fecedc63cc31718680a6/src/resources/invoice_ext.rs#L35
fn upcoming_invoice() {
mock::with_client(|client| {
let mut upcoming = UpcomingInvoice::new();
let items = vec![UpcomingInvoiceSubscriptionItems::new()];
upcoming.subscription_items = Some(&items);
let result = upcoming.send(client).unwrap();
assert_eq!(result.subtotal, 1000);
assert_eq!(result.amount_due, 1000);
})
}
3 changes: 3 additions & 0 deletions tests/tests/it/blocking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ mod checkout;
mod customer;
mod invoice;
mod plan_interval;
mod price;
mod product;
mod promotion_code;
mod subscription;
mod subscription_item;
mod token;
Expand Down
26 changes: 26 additions & 0 deletions tests/tests/it/blocking/price.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::collections::HashMap;

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

use crate::mock;

#[test]
// https://github.com/arlyon/async-stripe/issues/417
fn update_price() {
mock::with_client(|client| {
let mut update = UpdatePrice::new();
let mut currency_opts = HashMap::new();
let mut opt = UpdatePriceCurrencyOptions::new();
opt.unit_amount = Some(4);
currency_opts.insert(Currency::USD, opt);
update.currency_options = Some(&currency_opts);

let price_id = "price_123".parse().unwrap();

let price = update.send(client, &price_id).unwrap();
assert_eq!(price.id, price_id);
assert_eq!(price.tax_behavior, Some(PriceTaxBehavior::Unspecified));
})
}
18 changes: 18 additions & 0 deletions tests/tests/it/blocking/product.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use stripe_product::product::{CreateProduct, CreateProductFeatures};

use crate::mock;

#[test]
// FIXME: stripe-mock is missing required `type` field
#[ignore]
// https://github.com/arlyon/async-stripe/issues/437
fn create_product() {
mock::with_client(|client| {
let mut create = CreateProduct::new("my product");
let features = vec![CreateProductFeatures::new("great feature")];
create.features = Some(&features);

let product = create.send(client).unwrap();
assert_eq!(product.features.first().unwrap().name, Some("great feature".into()));
})
}
15 changes: 15 additions & 0 deletions tests/tests/it/blocking/promotion_code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use stripe_product::promotion_code::CreatePromotionCode;

use crate::mock;

#[test]
// https://github.com/arlyon/async-stripe/issues/389
fn create_promotion_code() {
mock::with_client(|client| {
let mut create = CreatePromotionCode::new("code");
create.active = Some(true);

let result = create.send(client).unwrap();
assert!(result.active);
})
}
6 changes: 5 additions & 1 deletion tests/tests/it/blocking/subscription.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use stripe_billing::subscription::{CancelSubscription, RetrieveSubscription};
use stripe_billing::subscription::{
CancelSubscription, CancelSubscriptionCancellationDetails, RetrieveSubscription,
};

use crate::mock;

Expand Down Expand Up @@ -31,10 +33,12 @@ fn is_subscription_expandable() {
#[test]
#[ignore]
/// https://github.com/arlyon/async-stripe/issues/394
/// https://github.com/arlyon/async-stripe/issues/419
fn can_prorate_when_cancelling_subscription() {
mock::with_client(|client| {
let id = "sub_123".parse().unwrap();
let mut cancel = CancelSubscription::new();
cancel.cancellation_details = Some(CancelSubscriptionCancellationDetails::new());
cancel.prorate = Some(true);
let result = cancel.send(client, &id).unwrap();
assert_eq!(result.id, id);
Expand Down

0 comments on commit 1f83a15

Please sign in to comment.