Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def recurring_rules_params(rules)
:transaction_metadata,
:transaction_name,
:ignore_paid_top_up_limits,
:grants_target_top_up,
)

payment_method = payment_method_params(r[:payment_method])
Expand Down
68 changes: 68 additions & 0 deletions spec/lago/api/resources/customers/wallets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,40 @@
end
end

context 'when grants_target_top_up is provided in a target recurring rule' do
let(:params_with_grants) do
params.deep_merge(
recurring_transaction_rules: [
factory_wallet.recurring_transaction_rules.first.merge(
method: 'target',
target_ongoing_balance: '200',
grants_target_top_up: true,
),
],
)
end
let(:body_with_grants) do
body['wallet']['recurring_transaction_rules'].first.merge!(
'method' => 'target',
'target_ongoing_balance' => '200',
'grants_target_top_up' => true,
)
body
end

before do
stub_request(:post, "https://api.getlago.com/api/v1/customers/#{customer_id}/wallets")
.with(body: body_with_grants)
.to_return(body: response, status: 200)
end

it 'forwards grants_target_top_up in the request' do
wallet = resource.create(customer_id, params_with_grants)

expect(wallet.lago_id).to eq('this-is-lago-id')
end
end

context 'when wallet failed to create' do
before do
stub_request(:post, "https://api.getlago.com/api/v1/customers/#{customer_id}/wallets")
Expand Down Expand Up @@ -225,6 +259,40 @@
end
end

context 'when grants_target_top_up is provided in a target recurring rule' do
let(:params_with_grants) do
params.deep_merge(
recurring_transaction_rules: [
factory_wallet.recurring_transaction_rules.first.merge(
method: 'target',
target_ongoing_balance: '200',
grants_target_top_up: true,
),
],
)
end
let(:body_with_grants) do
body['wallet']['recurring_transaction_rules'].first.merge!(
'method' => 'target',
'target_ongoing_balance' => '200',
'grants_target_top_up' => true,
)
body
end

before do
stub_request(:put, "https://api.getlago.com/api/v1/customers/#{customer_id}/wallets/#{code}")
.with(body: body_with_grants)
.to_return(body: response, status: 200)
end

it 'forwards grants_target_top_up in the request' do
wallet = resource.update(customer_id, code, params_with_grants)

expect(wallet.lago_id).to eq('this-is-lago-id')
end
end

context 'when wallet failed to update' do
before do
stub_request(:put, "https://api.getlago.com/api/v1/customers/#{customer_id}/wallets/#{code}")
Expand Down
Loading