From 1f83a151da6b1a1f92a5c97ff4a4a7ab994473fa Mon Sep 17 00:00:00 2001 From: Matthew Zeitlin <37011898+mzeitlin11@users.noreply.github.com> Date: Sun, 26 Nov 2023 14:24:26 -0500 Subject: [PATCH] Add more tests for closable issues --- async-stripe/src/client/base/tokio.rs | 5 +++- openapi/id_prefixes.json | 2 +- tests/Cargo.toml | 5 ++-- tests/tests/it/blocking/invoice.rs | 34 ++++++++++++++++++++++- tests/tests/it/blocking/mod.rs | 3 ++ tests/tests/it/blocking/price.rs | 26 +++++++++++++++++ tests/tests/it/blocking/product.rs | 18 ++++++++++++ tests/tests/it/blocking/promotion_code.rs | 15 ++++++++++ tests/tests/it/blocking/subscription.rs | 6 +++- 9 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 tests/tests/it/blocking/price.rs create mode 100644 tests/tests/it/blocking/product.rs create mode 100644 tests/tests/it/blocking/promotion_code.rs diff --git a/async-stripe/src/client/base/tokio.rs b/async-stripe/src/client/base/tokio.rs index a285c659a..32fb354da 100644 --- a/async-stripe/src/client/base/tokio.rs +++ b/async-stripe/src/client/base/tokio.rs @@ -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"); @@ -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), diff --git a/openapi/id_prefixes.json b/openapi/id_prefixes.json index 4b186e92f..2d8b3b5a4 100644 --- a/openapi/id_prefixes.json +++ b/openapi/id_prefixes.json @@ -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", diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 5bd376f9e..c9aa65c15 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -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 = [] diff --git a/tests/tests/it/blocking/invoice.rs b/tests/tests/it/blocking/invoice.rs index 84b278b4c..44c3eaea1 100644 --- a/tests/tests/it/blocking/invoice.rs +++ b/tests/tests/it/blocking/invoice.rs @@ -1,4 +1,7 @@ -use stripe_billing::invoice::{PayInvoice, RetrieveInvoice}; +use stripe_billing::invoice::{ + FinalizeInvoiceInvoice, PayInvoice, RetrieveInvoice, UpcomingInvoice, + UpcomingInvoiceSubscriptionItems, +}; use crate::mock; @@ -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); }) } diff --git a/tests/tests/it/blocking/mod.rs b/tests/tests/it/blocking/mod.rs index ed8457b8d..bdfde9e88 100644 --- a/tests/tests/it/blocking/mod.rs +++ b/tests/tests/it/blocking/mod.rs @@ -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; diff --git a/tests/tests/it/blocking/price.rs b/tests/tests/it/blocking/price.rs new file mode 100644 index 000000000..f8f995db3 --- /dev/null +++ b/tests/tests/it/blocking/price.rs @@ -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(¤cy_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)); + }) +} diff --git a/tests/tests/it/blocking/product.rs b/tests/tests/it/blocking/product.rs new file mode 100644 index 000000000..722e4ec3a --- /dev/null +++ b/tests/tests/it/blocking/product.rs @@ -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())); + }) +} diff --git a/tests/tests/it/blocking/promotion_code.rs b/tests/tests/it/blocking/promotion_code.rs new file mode 100644 index 000000000..486a7b789 --- /dev/null +++ b/tests/tests/it/blocking/promotion_code.rs @@ -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); + }) +} diff --git a/tests/tests/it/blocking/subscription.rs b/tests/tests/it/blocking/subscription.rs index 75c53cab0..2a758e2eb 100644 --- a/tests/tests/it/blocking/subscription.rs +++ b/tests/tests/it/blocking/subscription.rs @@ -1,4 +1,6 @@ -use stripe_billing::subscription::{CancelSubscription, RetrieveSubscription}; +use stripe_billing::subscription::{ + CancelSubscription, CancelSubscriptionCancellationDetails, RetrieveSubscription, +}; use crate::mock; @@ -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);