Skip to content

Commit

Permalink
dry up test code (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
montdidier authored Dec 25, 2023
1 parent d61f071 commit 77d8a0c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 53 deletions.
11 changes: 3 additions & 8 deletions tests/balance.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
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);
mod common;

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")
}
static SERVER_POOL: ServerPool = ServerPool::new(1);

#[tokio::test]
async fn get_balance_test() {
let json = get_fixture("tests/fixtures/get-balance.json");
let json = common::get_fixture("tests/fixtures/get-balance.json");

println!("{json}");

Expand Down
11 changes: 3 additions & 8 deletions tests/card.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
use pinpayments::{Client, CardParams, Card};
use std::fs::File;
use httptest::{ServerPool, Expectation, matchers::*, responders::*};
use surf::http::auth::BasicAuth;

static SERVER_POOL: ServerPool = ServerPool::new(2);
mod common;

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")
}
static SERVER_POOL: ServerPool = ServerPool::new(2);

#[tokio::test]
async fn card_create_test() {
let json = get_fixture("tests/fixtures/create-card.json");
let json = common::get_fixture("tests/fixtures/create-card.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down
21 changes: 8 additions & 13 deletions tests/charge.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
use pinpayments::{Client, Currency, CreateCharge, Charge, CardParams};
use std::fs::File;
use httptest::{ServerPool, Expectation, matchers::*, responders::*};
use surf::http::auth::BasicAuth;
use time::macros::datetime;

static SERVER_POOL: ServerPool = ServerPool::new(2);
mod common;

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")
}
static SERVER_POOL: ServerPool = ServerPool::new(2);

#[tokio::test]
async fn charge_create_test() {
let json = get_fixture("tests/fixtures/create-charge.json");
let json = common::get_fixture("tests/fixtures/create-charge.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down Expand Up @@ -92,7 +87,7 @@ async fn charge_create_test() {

#[tokio::test]
async fn get_charge_test() {
let json = get_fixture("tests/fixtures/get-charge.json");
let json = common::get_fixture("tests/fixtures/get-charge.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand All @@ -119,7 +114,7 @@ async fn get_charge_test() {

#[tokio::test]
async fn charge_void_test() {
let json = get_fixture("tests/fixtures/charge-void.json");
let json = common::get_fixture("tests/fixtures/charge-void.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down Expand Up @@ -148,7 +143,7 @@ async fn charge_void_test() {

#[tokio::test]
async fn charge_capture_test() {
let json = get_fixture("tests/fixtures/charge-capture.json");
let json = common::get_fixture("tests/fixtures/charge-capture.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down Expand Up @@ -180,7 +175,7 @@ async fn charge_capture_test() {

#[tokio::test]
async fn charge_list_test() {
let json = get_fixture("tests/fixtures/get-charges.json");
let json = common::get_fixture("tests/fixtures/get-charges.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand All @@ -206,7 +201,7 @@ async fn charge_list_test() {

#[tokio::test]
async fn charge_verify_test() {
let json = get_fixture("tests/fixtures/charge-verify.json");
let json = common::get_fixture("tests/fixtures/charge-verify.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down
7 changes: 7 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::fs::File;

pub 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")
}
21 changes: 8 additions & 13 deletions tests/customer.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
use pinpayments::{Client, Currency, CreateCustomer, Customer, CardParams};
use std::fs::File;
use httptest::{ServerPool, Expectation, matchers::*, responders::*};
use surf::http::auth::BasicAuth;
use time::macros::datetime;
use http::StatusCode;

static SERVER_POOL: ServerPool = ServerPool::new(2);
mod common;

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")
}
static SERVER_POOL: ServerPool = ServerPool::new(2);

#[tokio::test]
async fn customer_create_test() {
let json = get_fixture("tests/fixtures/create-customer.json");
let json = common::get_fixture("tests/fixtures/create-customer.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down Expand Up @@ -80,7 +75,7 @@ async fn customer_create_test() {

#[tokio::test]
async fn customer_retrieve_test() {
let json = get_fixture("tests/fixtures/get-customer.json");
let json = common::get_fixture("tests/fixtures/get-customer.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down Expand Up @@ -119,7 +114,7 @@ async fn customer_retrieve_test() {

#[tokio::test]
async fn customer_list_test() {
let json = get_fixture("tests/fixtures/get-customers.json");
let json = common::get_fixture("tests/fixtures/get-customers.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down Expand Up @@ -183,7 +178,7 @@ async fn customer_delete_test() {

#[tokio::test]
async fn customer_list_charges_test() {
let json = get_fixture("tests/fixtures/get-customer-charges.json");
let json = common::get_fixture("tests/fixtures/get-customer-charges.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down Expand Up @@ -219,7 +214,7 @@ async fn customer_list_charges_test() {

#[tokio::test]
async fn customer_list_cards_test() {
let json = get_fixture("tests/fixtures/get-customer-cards.json");
let json = common::get_fixture("tests/fixtures/get-customer-cards.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down Expand Up @@ -253,7 +248,7 @@ async fn customer_list_cards_test() {

#[tokio::test]
async fn customer_create_card_test() {
let json = get_fixture("tests/fixtures/create-customer-card.json");
let json = common::get_fixture("tests/fixtures/create-customer-card.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down
17 changes: 6 additions & 11 deletions tests/refund.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
use pinpayments::{Client, Currency, CreateRefund, Refund};
use std::fs::File;
use httptest::{ServerPool, Expectation, matchers::*, responders::*};
use surf::http::auth::BasicAuth;
use time::macros::datetime;

static SERVER_POOL: ServerPool = ServerPool::new(2);
mod common;

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")
}
static SERVER_POOL: ServerPool = ServerPool::new(2);

#[tokio::test]
async fn charge_refund_test() {
let json = get_fixture("tests/fixtures/create-refund.json");
let json = common::get_fixture("tests/fixtures/create-refund.json");

let auth = BasicAuth::new("sk_test_12345", "");

Expand Down Expand Up @@ -53,7 +48,7 @@ async fn charge_refund_test() {

#[tokio::test]
async fn refund_list_test() {
let json = get_fixture("tests/fixtures/get-refunds.json");
let json = common::get_fixture("tests/fixtures/get-refunds.json");

let server = SERVER_POOL.get_server();

Expand All @@ -77,7 +72,7 @@ async fn refund_list_test() {

#[tokio::test]
async fn charge_refunds_test() {
let json = get_fixture("tests/fixtures/get-refunds.json");
let json = common::get_fixture("tests/fixtures/get-refunds.json");

let server = SERVER_POOL.get_server();

Expand All @@ -103,7 +98,7 @@ async fn charge_refunds_test() {

#[tokio::test]
async fn get_refund_test() {
let json = get_fixture("tests/fixtures/get-refund.json");
let json = common::get_fixture("tests/fixtures/get-refund.json");

let server = SERVER_POOL.get_server();

Expand Down

0 comments on commit 77d8a0c

Please sign in to comment.