diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4cb90b4..ad2dd42 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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: @@ -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 diff --git a/src/models/subaccounts.rs b/src/models/subaccounts.rs index 6d85031..a83b09c 100644 --- a/src/models/subaccounts.rs +++ b/src/models/subaccounts.rs @@ -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, diff --git a/tests/api/subaccount.rs b/tests/api/subaccount.rs index 432d5bb..e3433a5 100644 --- a/tests/api/subaccount.rs +++ b/tests/api/subaccount.rs @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/tests/api/transaction_split.rs b/tests/api/transaction_split.rs index f360619..440fc7a 100644 --- a/tests/api/transaction_split.rs +++ b/tests/api/transaction_split.rs @@ -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(); @@ -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(); @@ -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) @@ -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());