Skip to content

Commit

Permalink
feat(minimum-commitment): Add minimum commitment (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannovosad authored Mar 19, 2024
1 parent f6b7e86 commit e657a0e
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
lago-ruby-client (0.56.0.pre.beta)
lago-ruby-client (1.0.0)
jwt
openssl

Expand Down
12 changes: 12 additions & 0 deletions lib/lago/api/resources/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@ def whitelist_params(params)
result_hash[:charges] = charges unless charges.empty?
end

whitelist_minimum_commitment(params[:minimum_commitment]).tap do |minimum_commitment|
result_hash[:minimum_commitment] = minimum_commitment
end

{ root_name => result_hash }
end

def whitelist_minimum_commitment(minimum_commitment)
minimum_commitment.slice(
:amount_cents,
:invoice_display_name,
:tax_codes,
)
end

def whitelist_charges(charges)
processed_charges = []

Expand Down
8 changes: 8 additions & 0 deletions spec/factories/minimum_commitment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FactoryBot.define do
factory :minimum_commitment, class: OpenStruct do
invoice_display_name { 'Minimum commitment (C1)' }
plan_code { 'plan_code' }
interval { 'monthly' }
amount_cents { 200 }
end
end
6 changes: 6 additions & 0 deletions spec/factories/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@
},
]
end
minimum_commitment do
{
invoice_display_name: 'Minimum commitment (C1)',
amount_cents: 100,
}
end
end
end
14 changes: 14 additions & 0 deletions spec/fixtures/api/plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@
}
}
],
"minimum_commitment": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"plan_code": "plan_code",
"invoice_display_name": "Minimum commitment (C1)",
"amount_cents": 200,
"interval": "monthly",
"created_at": "2022-04-29T08:59:51Z",
"updated_at": "2022-04-29T08:59:51Z",
"taxes": [
{
"code": "tax_code"
}
]
},
"taxes": [
{
"code": "tax_code"
Expand Down
14 changes: 14 additions & 0 deletions spec/fixtures/api/plans.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@
}
}
],
"minimum_commitment": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"plan_code": "plan_code",
"invoice_display_name": "Minimum commitment (C1)",
"amount_cents": 200,
"interval": "monthly",
"created_at": "2022-04-29T08:59:51Z",
"updated_at": "2022-04-29T08:59:51Z",
"taxes": [
{
"code": "tax_code"
}
]
},
"taxes": [
{
"code": "tax_code"
Expand Down
7 changes: 7 additions & 0 deletions spec/lago/api/resources/plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

describe '#create' do
let(:tax_codes) { ['tax_code'] }
let(:minimum_commitment) { create(:minimum_commitment) }
let(:params) { create(:create_plan).to_h.merge(tax_codes: tax_codes) }
let(:body) do
{ 'plan' => params }
Expand All @@ -43,6 +44,9 @@
expect(plan.name).to eq(plan_name)
expect(plan.invoice_display_name).to eq(plan_dsplay_name)
expect(plan.taxes.map(&:code)).to eq(tax_codes)

expect(plan.minimum_commitment.invoice_display_name).to eq(minimum_commitment.invoice_display_name)
expect(plan.minimum_commitment.taxes.map(&:code)).to eq(tax_codes)
end
end

Expand Down Expand Up @@ -75,6 +79,7 @@
expect(plan.lago_id).to eq(plan_id)
expect(plan.name).to eq(plan_name)
expect(plan.invoice_display_name).to eq(plan_dsplay_name)
expect(plan.minimum_commitment.invoice_display_name).to eq('Minimum commitment (C1)')
end
end

Expand Down Expand Up @@ -104,6 +109,7 @@
expect(plan.lago_id).to eq(plan_id)
expect(plan.name).to eq(plan_name)
expect(plan.invoice_display_name).to eq(plan_dsplay_name)
expect(plan.minimum_commitment.invoice_display_name).to eq('Minimum commitment (C1)')
end
end

Expand Down Expand Up @@ -164,6 +170,7 @@
expect(response['plans'].first['invoice_display_name']).to eq(plan_dsplay_name)
expect(response['plans'].first['charges'].first['invoice_display_name']).to eq('Charge 1')
expect(response['plans'].first['charges'].first['properties']['grouped_by']).to eq(['agent_name'])
expect(response['plans'].first['minimum_commitment']['invoice_display_name']).to eq('Minimum commitment (C1)')
expect(response['meta']['current_page']).to eq(1)
end
end
Expand Down
8 changes: 6 additions & 2 deletions spec/lago/api/resources/subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
ending_at: factory_subscription.ending_at,
plan_overrides: {
amount_cents: 1000,
minimum_commitment: {
amount_cents: 2000,
invoice_display_name: 'Minimum commitment (C1)',
},
}
}
end
Expand Down Expand Up @@ -99,8 +103,8 @@
stub_request(:delete, 'https://api.getlago.com/api/v1/subscriptions/456?status=pending')
.to_return(body: response_with_pending, status: 200)
end
it 'returns subscription' do

it 'returns subscription' do
subscription = resource.destroy('456', options: { status: 'pending' })

expect(subscription.external_customer_id).to eq(pending_subscription.external_customer_id)
Expand Down

0 comments on commit e657a0e

Please sign in to comment.