forked from arlyon/async-stripe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate old tests, add back from branch
- Loading branch information
1 parent
6ff0bac
commit 02ba0fa
Showing
24 changed files
with
354 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "async-stripe-tests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dev-dependencies] | ||
serde_json = "1" | ||
chrono = "0.4.26" | ||
httpmock = "0.6.7" | ||
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_billing = {path = "../generated/stripe_billing", features = ["invoice", "plan", "subscription", "subscription_item", "usage_record"]} | ||
stripe_core = {path = "../generated/stripe_core", features = ["customer", "charge"]} | ||
stripe_checkout = {path = "../generated/stripe_checkout", features = ["session"]} | ||
|
||
[features] | ||
async = [] | ||
blocking = [] | ||
|
||
runtime-tokio-hyper = ["async-stripe/runtime-tokio-hyper", "async"] | ||
runtime-tokio-hyper-rustls = ["async-stripe/runtime-tokio-hyper-rustls", "async"] | ||
runtime-tokio-hyper-rustls-webpki = ["async-stripe/runtime-tokio-hyper-rustls-webpki", "async"] | ||
runtime-blocking = ["async-stripe/runtime-blocking", "blocking"] | ||
runtime-blocking-rustls = ["async-stripe/runtime-blocking-rustls", "blocking"] | ||
runtime-blocking-rustls-webpki = ["async-stripe/runtime-blocking-rustls-webpki", "blocking"] | ||
runtime-async-std-surf = ["async-stripe/runtime-async-std-surf", "async"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod pagination; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use stripe::Client; | ||
use stripe_connect::account::ListAccount; | ||
use stripe_core::customer::ListCustomer; | ||
use stripe_types::AccountId; | ||
|
||
use crate::mock::get_client; | ||
|
||
#[tokio::test] | ||
async fn is_account_listable() { | ||
use futures_util::TryStreamExt; | ||
let client = get_client(); | ||
let expected_id: AccountId = "acct_1O8RSFF2YyVaukgl".parse().unwrap(); | ||
|
||
let result = | ||
ListAccount::new().paginate().stream(&client).try_collect::<Vec<_>>().await.unwrap(); | ||
assert_eq!(result.len(), 1); | ||
assert_eq!(result.first().unwrap().id, expected_id); | ||
} | ||
|
||
#[tokio::test] | ||
async fn stream() { | ||
use futures_util::StreamExt; | ||
use httpmock::Method::GET; | ||
use httpmock::MockServer; | ||
|
||
// Start a lightweight mock server. | ||
let server = MockServer::start_async().await; | ||
|
||
let client = Client::from_url(&*server.url("/"), "fake_key"); | ||
|
||
let next_item = server.mock(|when, then| { | ||
when.method(GET).path("/v1/customers").query_param("starting_after", "cus_1"); | ||
then.status(200).body( | ||
r#"{"object": "list", "data": [{ | ||
"id": "cus_2", | ||
"object": "customer", | ||
"balance": 0, | ||
"created": 1649316731, | ||
"currency": "gbp", | ||
"delinquent": false, | ||
"email": null, | ||
"invoice_prefix": "4AF7482", | ||
"invoice_settings": {}, | ||
"livemode": false, | ||
"metadata": {}, | ||
"preferred_locales": [], | ||
"tax_exempt": "none" | ||
}], "has_more": false, "url": "/v1/customers"}"#, | ||
); | ||
}); | ||
|
||
let first_item = server.mock(|when, then| { | ||
when.method(GET).path("/v1/customers"); | ||
then.status(200).body( | ||
r#"{"object": "list", "data": [{ | ||
"id": "cus_1", | ||
"object": "customer", | ||
"balance": 0, | ||
"created": 1649316731, | ||
"currency": "gbp", | ||
"delinquent": false, | ||
"invoice_prefix": "4AF7482", | ||
"invoice_settings": {}, | ||
"livemode": false, | ||
"metadata": {}, | ||
"preferred_locales": [], | ||
"tax_exempt": "none" | ||
}], "has_more": true, "url": "/v1/customers"}"#, | ||
); | ||
}); | ||
|
||
let paginator = ListCustomer::new().paginate(); | ||
|
||
let stream = paginator.stream(&client).collect::<Vec<_>>().await; | ||
|
||
assert_eq!(stream.len(), 2); | ||
|
||
first_item.assert_hits_async(1).await; | ||
next_item.assert_hits_async(1).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use stripe_connect::account::{CreateAccount, ListAccount}; | ||
use stripe_types::AccountId; | ||
|
||
use crate::mock; | ||
|
||
#[test] | ||
fn is_account_listable() { | ||
mock::with_client(|client| { | ||
let expected_id: AccountId = "acct_1O8RSFF2YyVaukgl".parse().unwrap(); | ||
let result = ListAccount::new().send(client).unwrap(); | ||
|
||
// Check to ensure we are deserializing _something_ and this test | ||
// actually validates something worthwhile. | ||
assert_eq!(result.data.len(), 1); | ||
assert_eq!(result.data.first().unwrap().id, expected_id); | ||
|
||
let result = ListAccount::new().paginate().get_all(client).unwrap(); | ||
assert_eq!(result.len(), 1); | ||
assert_eq!(result.first().unwrap().id, expected_id); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn create_account() { | ||
mock::with_client(|client| { | ||
let create = CreateAccount::new(); | ||
let result = create.send(client).unwrap(); | ||
assert_eq!(result.email, Some("[email protected]".to_string())); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use stripe_core::charge::RetrieveCharge; | ||
|
||
use crate::mock; | ||
|
||
#[test] | ||
fn is_charge_retrievable() { | ||
mock::with_client(|client| { | ||
let id = "ch_123".parse().unwrap(); | ||
let charge = RetrieveCharge::new().send(client, &id).unwrap(); | ||
assert_eq!(charge.id, "ch_123"); | ||
assert!(charge.customer.is_none()); | ||
assert!(charge.invoice.is_none()); | ||
assert_eq!(charge.refunds.data.len(), 1); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use stripe_checkout::session::RetrieveSession; | ||
|
||
use crate::mock; | ||
|
||
#[test] | ||
fn is_checkout_session_retrievable() { | ||
mock::with_client(|client| { | ||
let id = "cs_test_123".parse().unwrap(); | ||
let session = RetrieveSession::new().send(client, &id).unwrap(); | ||
assert_eq!(session.id, "cs_test_123"); | ||
}); | ||
} |
Oops, something went wrong.