-
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.
- Loading branch information
1 parent
079bda0
commit 4bee3ed
Showing
8 changed files
with
110 additions
and
6 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
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
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,23 @@ | ||
use serde::{Deserialize}; | ||
|
||
use crate::client::{Client, Response}; | ||
use crate::params::{unpack_contained}; | ||
use crate::resources::{Currency}; | ||
|
||
#[derive(Clone, Debug, Deserialize)] | ||
pub struct AmountCurrency { | ||
pub amount: i64, | ||
pub currency: Currency | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize)] | ||
pub struct Balance { | ||
pub available: Vec<AmountCurrency>, | ||
pub pending: Vec<AmountCurrency> | ||
} | ||
|
||
impl Balance { | ||
pub fn retrieve(client: &Client) -> Response<Balance> { | ||
unpack_contained(client.get("/balance")) | ||
} | ||
} |
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,45 @@ | ||
use pinpayments::{Client, Currency, Balance}; | ||
use std::fs::File; | ||
use httptest::{ServerPool, Expectation, matchers::*, responders::*}; | ||
use surf::http::auth::BasicAuth; | ||
|
||
static SERVER_POOL: ServerPool = ServerPool::new(1); | ||
|
||
fn get_fixture(path: &str) -> serde_json::Value { | ||
let file = File::open(path) | ||
.expect("file should open read only"); | ||
serde_json::from_reader(file).expect("file should be JSON") | ||
} | ||
|
||
#[tokio::test] | ||
async fn get_balance_test() { | ||
let json = get_fixture("tests/fixtures/get-balance.json"); | ||
|
||
println!("{json}"); | ||
|
||
let auth = BasicAuth::new("sk_test_12345", ""); | ||
|
||
let server = SERVER_POOL.get_server(); | ||
|
||
server.expect( | ||
Expectation::matching( | ||
all_of![ | ||
request::method_path("GET", "/1/balance"), | ||
request::headers( | ||
contains((String::from(auth.name().as_str()), String::from(auth.value().as_str()))) | ||
), | ||
]). | ||
respond_with(json_encoded(json)) | ||
); | ||
|
||
let client = Client::from_url(server.url_str("/1/").as_str(), "sk_test_12345"); | ||
|
||
let balance = Balance::retrieve(&client) | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!(balance.available[0].amount, 400); | ||
assert_eq!(balance.available[0].currency, Currency::AUD); | ||
assert_eq!(balance.pending[0].amount, 1200); | ||
assert_eq!(balance.pending[0].currency, Currency::AUD); | ||
} |
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,16 @@ | ||
{ | ||
"response": { | ||
"available": [ | ||
{ | ||
"amount": 400, | ||
"currency": "AUD" | ||
} | ||
], | ||
"pending": [ | ||
{ | ||
"amount": 1200, | ||
"currency": "AUD" | ||
} | ||
] | ||
} | ||
} |