|
2 | 2 |
|
3 | 3 | shared_examples 'Balance Transaction API' do
|
4 | 4 |
|
| 5 | + let(:stripe_helper) { StripeMock.create_test_helper } |
| 6 | + |
5 | 7 | it "returns an error if balance transaction does not exist" do
|
6 | 8 | txn_id = 'txn_xxxxxxxxxxxxxxxxxxxxxxxx'
|
7 | 9 |
|
|
32 | 34 |
|
33 | 35 | end
|
34 | 36 |
|
| 37 | + it 'retrieves balance transactions for an automated transfer' do |
| 38 | + transfer_id = Stripe::Transfer.create({ amount: 2730, currency: "usd" }) |
| 39 | + |
| 40 | + # verify transfer currently has no balance transactions |
| 41 | + transfer_transactions = Stripe::BalanceTransaction.all({transfer: transfer_id}) |
| 42 | + expect(transfer_transactions.count).to eq(0) |
| 43 | + |
| 44 | + # verify we can create a new balance transaction associated with the transfer |
| 45 | + new_txn_id = stripe_helper.upsert_stripe_object(:balance_transaction, {amount: 12300, transfer: transfer_id}) |
| 46 | + new_txn = Stripe::BalanceTransaction.retrieve(new_txn_id) |
| 47 | + expect(new_txn).to be_a(Stripe::BalanceTransaction) |
| 48 | + expect(new_txn.amount).to eq(12300) |
| 49 | + # although transfer was specified as an attribute on the balance_transaction, it should not be returned in the object |
| 50 | + expect{new_txn.transfer}.to raise_error(NoMethodError) |
| 51 | + |
| 52 | + # verify we can update an existing balance transaction to associate with the transfer |
| 53 | + existing_txn_id = 'txn_05RsQX2eZvKYlo2C0FRTGSSA' |
| 54 | + existing_txn = Stripe::BalanceTransaction.retrieve(existing_txn_id) |
| 55 | + stripe_helper.upsert_stripe_object(:balance_transaction, {id: existing_txn_id, transfer: transfer_id}) |
| 56 | + |
| 57 | + # now verify that only these balance transactions are retrieved with the transfer |
| 58 | + transfer_transactions = Stripe::BalanceTransaction.all({transfer: transfer_id}) |
| 59 | + expect(transfer_transactions.count).to eq(2) |
| 60 | + expect(transfer_transactions.map &:id).to include(new_txn_id, existing_txn_id) |
| 61 | + end |
| 62 | + |
35 | 63 | end
|
0 commit comments