Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Iulian Masar committed Oct 28, 2024
1 parent 39867b9 commit edf8944
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/mangopay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module MangoPay
autoload :Deposit, 'mangopay/deposit'
autoload :Conversion, 'mangopay/conversion'
autoload :PaymentMethodMetadata, 'mangopay/payment_method_metadata'
autoload :VirtualAccount, 'mangopay/virtual_account'

# temporary
autoload :Temp, 'mangopay/temp'
Expand Down
13 changes: 7 additions & 6 deletions lib/mangopay/virtual_account.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
module MangoPay

class VirtualAccount < Resource
include HTTPCalls::Create
include HTTPCalls::Update
include HTTPCalls::Fetch

class << self
# Creates a new virtual account
def create(wallet_id, params, idempotency_key = nil)
url = "#{MangoPay.api_path}/wallets/#{wallet_id}/virtual-accounts"
MangoPay.request(:post, url, params, {}, idempotency_key)
end

# Updates:
# - irreversibly deactivates a virtual account with +virtual_account_id+
# see https://docs.mangopay.com/api-reference/virtual-accounts/deactivate-virtual-account
def deactivate(wallet_id, virtual_account_id)
def deactivate(wallet_id, virtual_account_id, idempotency_key = nil)
url = "#{MangoPay.api_path}/wallets/#{wallet_id}/virtual-accounts/#{virtual_account_id}"
MangoPay.request(:put, url)
MangoPay.request(:put, url, {}, {}, idempotency_key)
end

# Fetches:
Expand Down
17 changes: 17 additions & 0 deletions spec/mangopay/shared_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -998,4 +998,21 @@ def get_payment_method_metadata
Bin: pay_in['CardInfo']['BIN']
)
end
end

###############################################
shared_context 'virtual_account' do
###############################################
include_context 'users'
include_context 'wallets'

def new_virtual_account(wallet_id)
create_virtual_account = {
Country: 'FR',
VirtualAccountPurpose: 'Collection',
Tag: 'create virtual account tag'
}

MangoPay::VirtualAccount.create(wallet_id, create_virtual_account)
end
end
52 changes: 52 additions & 0 deletions spec/mangopay/virtual_account_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
describe MangoPay::VirtualAccount do
include_context 'virtual_account'
include_context 'wallets'

describe 'CREATE' do
it 'can create a Virtual Account' do
wallet = new_wallet
virtual_account = new_virtual_account(wallet['Id'])
expect(virtual_account).not_to be_nil
end
end

describe 'DEACTIVATE' do
it 'deactivates a Virtual Account' do
wallet = new_wallet
virtual_account = new_virtual_account(wallet['Id'])
deactivated = MangoPay::VirtualAccount.deactivate(wallet['Id'], virtual_account['Id'])
expect(deactivated).not_to be_nil
expect(deactivated['Status']).to eq 'CLOSED'
expect(deactivated['Id']).to eq(virtual_account['Id'])
end
end

describe 'FETCH' do
it 'can get a Virtual Account' do
wallet = new_wallet
virtual_account = new_virtual_account(wallet['Id'])
fetched = MangoPay::VirtualAccount.fetch(wallet['Id'], virtual_account['Id'])
expect(fetched).not_to be_nil
expect(fetched['Id']).to eq(virtual_account['Id'])
end
end

describe 'FETCH ALL' do
it 'can get all Virtual Accounts for a wallet' do
wallet = new_wallet
virtual_account = new_virtual_account(wallet['Id'])
fetched_list = MangoPay::VirtualAccount.fetch_all(wallet['Id'])
expect(fetched_list).not_to be_nil
expect(fetched_list[0]['Id']).to eq(virtual_account['Id'])
end
end

describe 'FETCH AVAILABILITIES' do
it 'get availabilities' do
availabilities = MangoPay::VirtualAccount.fetch_availabilities
expect(availabilities).not_to be_nil
expect(availabilities['Collection']).not_to be_nil
expect(availabilities['UserOwned']).not_to be_nil
end
end
end

0 comments on commit edf8944

Please sign in to comment.