Skip to content

Commit

Permalink
Migrate old tests, add back from branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mzeitlin11 committed Nov 25, 2023
1 parent 6ff0bac commit 02ba0fa
Show file tree
Hide file tree
Showing 24 changed files with 354 additions and 330 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
members = [
"async-stripe",
"stripe_types",
"stripe_webhook"
"stripe_webhook",
"tests",
"generated/*",
]
resolver = "2"
# Makes dependency management simpler to allow codegen crate to use whichever dep versions
Expand Down
30 changes: 30 additions & 0 deletions tests/Cargo.toml
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"]
17 changes: 0 additions & 17 deletions tests/account.rs

This file was deleted.

41 changes: 0 additions & 41 deletions tests/charge.rs

This file was deleted.

16 changes: 0 additions & 16 deletions tests/checkout.rs

This file was deleted.

14 changes: 0 additions & 14 deletions tests/mock/mod.rs

This file was deleted.

44 changes: 0 additions & 44 deletions tests/plan_interval.rs

This file was deleted.

43 changes: 0 additions & 43 deletions tests/subscription.rs

This file was deleted.

21 changes: 0 additions & 21 deletions tests/subscription_item.rs

This file was deleted.

1 change: 1 addition & 0 deletions tests/tests/it/async_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod pagination;
80 changes: 80 additions & 0 deletions tests/tests/it/async_tests/pagination.rs
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;
}
30 changes: 30 additions & 0 deletions tests/tests/it/blocking/account.rs
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()));
});
}
15 changes: 15 additions & 0 deletions tests/tests/it/blocking/charge.rs
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);
});
}
12 changes: 12 additions & 0 deletions tests/tests/it/blocking/checkout.rs
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");
});
}
Loading

0 comments on commit 02ba0fa

Please sign in to comment.