Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: transaction split endpoints integration tests #27

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ name: Rust

on:
push:
branches: [ "main", "master" ]
branches: [ "main", "master", "test/transaction_split" ]
pull_request:
branches: [ "main", "master" ]

env:
CARGO_TERM_COLOR: always
PAYSTACK_API_KEY: ${{secrets.PAYSTACK_API_KEY}}
BANK_ACCOUNT: ${{secrets.BANK_ACCOUNT}}
BANK_CODE: ${{secrets.BANK_CODE}}
BANK_NAME: ${{secrets.BANK_NAME}}

jobs:
build:
Expand All @@ -20,6 +16,8 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: "Say Hello Mona it's Monday"
run: echo "$PAYSTACK_API_KEY $BANK_ACCOUNT $BANK_CODE $BANK_NAME"
- name: Build
run: cargo build --verbose
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion src/models/subaccounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use derive_builder::Builder;
use serde::{Deserialize, Serialize};

/// This struct is used to create the body for creating a subaccount on your integration.
#[derive(Serialize, Debug, Builder, Default)]
#[derive(Serialize, Debug, Builder, Default, Clone)]
pub struct CreateSubaccountBody<'a> {
/// Name of business for subaccount
business_name: &'a str,
Expand Down
8 changes: 4 additions & 4 deletions tests/api/subaccount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async fn fetch_subaccount_with_id_returns_a_valid_payload() {
let client = get_paystack_client();
let business_name: String = CompanyName().fake();
let description: String = Sentence(5..10).fake();
let (account_number, bank_code, bank_name) = get_bank_account_number_and_code();
let (account_number, bank_code, _bank_name) = get_bank_account_number_and_code();

// Act
let body = CreateSubaccountBodyBuilder::default()
Expand Down Expand Up @@ -127,7 +127,7 @@ async fn fetch_subaccount_with_subaccount_code_returns_a_valid_payload() {
let client = get_paystack_client();
let business_name: String = CompanyName().fake();
let description: String = Sentence(5..10).fake();
let (account_number, bank_code, bank_name) = get_bank_account_number_and_code();
let (account_number, bank_code, _bank_name) = get_bank_account_number_and_code();

// Act
let body = CreateSubaccountBodyBuilder::default()
Expand Down Expand Up @@ -164,7 +164,7 @@ async fn modify_subaccount_with_subaccount_id_returns_a_valid_payload() {
let client = get_paystack_client();
let business_name: String = CompanyName().fake();
let description: String = Sentence(5..10).fake();
let (account_number, bank_code, bank_name) = get_bank_account_number_and_code();
let (account_number, bank_code, _bank_name) = get_bank_account_number_and_code();

// Act
let body = CreateSubaccountBodyBuilder::default()
Expand Down Expand Up @@ -211,7 +211,7 @@ async fn modify_subaccount_with_subaccount_code_returns_a_valid_payload() {
let client = get_paystack_client();
let business_name: String = CompanyName().fake();
let description: String = Sentence(5..10).fake();
let (account_number, bank_code, bank_name) = get_bank_account_number_and_code();
let (account_number, bank_code, _bank_name) = get_bank_account_number_and_code();

// Act
let body = CreateSubaccountBodyBuilder::default()
Expand Down
46 changes: 38 additions & 8 deletions tests/api/transaction_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async fn create_transaction_split_passes_with_valid_data() {
let client = get_paystack_client();

let txn_split_name: String = FirstName().fake();
let (account_number, bank_code, bank_name) = get_bank_account_number_and_code();
let (account_number, bank_code, _) = get_bank_account_number_and_code();

// Create first subaccount
let first_business_name: String = CompanyName().fake();
Expand Down Expand Up @@ -50,14 +50,14 @@ async fn create_transaction_split_passes_with_valid_data() {

let second_subaccount = client
.subaccount
.create_subaccount(body)
.create_subaccount(body.clone())
.await
.expect("Unable to create a subaccount");

// Create subaccount bodies
let first_subaccount_body = SubaccountBodyBuilder::default()
.share(90.0)
.subaccount(first_subaccount.data.subaccount_code)
.subaccount(first_subaccount.data.subaccount_code.clone())
// .subaccount_code("ACCT_xv2cusld7thdw7r".to_string())
.build()
.unwrap();
Expand All @@ -69,6 +69,7 @@ async fn create_transaction_split_passes_with_valid_data() {
.unwrap();

// Create transaction split body
let subaccount_code: String = first_subaccount.data.subaccount_code;
let split_body = CreateTransactionSplitBodyBuilder::default()
.name(&txn_split_name)
.split_type(paystack::SplitType::Percentage)
Expand All @@ -79,22 +80,51 @@ async fn create_transaction_split_passes_with_valid_data() {
first_subaccount_body.clone(),
second_subaccount_body.clone(),
])
.bearer_subaccount(&first_subaccount_body.subaccount)
.bearer_subaccount(&subaccount_code)
.build()
.unwrap();

println!("{:#?}", split_body);

// Act
let res = client
let _res = client
.transaction_split
.create_transaction_split(split_body)
.await
.expect("Failed to create transaction split");

// dbg!(res);

// Assert
let subaccount = client
.subaccount
.create_subaccount(body)
.await
.expect("Unable to Create a subaccount");

let subaccount_body = SubaccountBodyBuilder::default()
.share(90.0)
.subaccount(subaccount.data.subaccount_code.clone())
.build()
.unwrap();

let split_body = CreateTransactionSplitBodyBuilder::default()
.name(&txn_split_name)
.split_type(paystack::SplitType::Percentage)
.currency(paystack::Currency::NGN)
.bearer_type(paystack::BearerType::Subaccount)
// .bearer_subaccount("ACCT_xv2cusld7thdw7r")
.subaccounts(vec![subaccount_body.clone()])
.bearer_subaccount(&subaccount_body.subaccount)
.build()
.unwrap();


// Act
let res = client
.transaction_split
.create_transaction_split(split_body)
.await
.expect("Failed to create transaction split");

// Assert
assert!(res.status);
assert_eq!(res.message, "Split created");
assert_eq!(res.data.currency, Currency::NGN.to_string());
Expand Down