-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(analytics): Add overdue balance endpoint
- Loading branch information
Showing
6 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lago | ||
module Api | ||
module Resources | ||
class OverdueBalance < Base | ||
def api_resource | ||
'analytics/overdue_balance' | ||
end | ||
|
||
def root_name | ||
'overdue_balance' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"overdue_balances": [ | ||
{ | ||
"month": "2023-11-01T00:00:00.000Z", | ||
"amount_cents": 100, | ||
"currency": "EUR", | ||
"lago_invoice_ids": ["1a901a90-1a90-1a90-1a90-1a901a901a90"] | ||
}, | ||
{ | ||
"month": "2023-12-01T00:00:00.000Z", | ||
"amount_cents": 200, | ||
"currency": "USD", | ||
"lago_invoice_ids": ["1a901a90-1a90-1a90-1a90-1a901a901a90"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Lago::Api::Resources::OverdueBalance do | ||
subject(:resource) { described_class.new(client) } | ||
|
||
let(:client) { Lago::Api::Client.new } | ||
|
||
let(:error_response) do | ||
{ | ||
'status' => 422, | ||
'error' => 'Unprocessable Entity', | ||
'message' => 'Validation error on the record', | ||
}.to_json | ||
end | ||
|
||
describe '#get_all' do | ||
let(:overdue_balances_response) { load_fixture('overdue_balance_index') } | ||
|
||
context 'when there is no options' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/overdue_balance') | ||
.to_return(body: overdue_balances_response, status: 200) | ||
end | ||
|
||
it 'returns overdue balance' do | ||
response = resource.get_all | ||
|
||
expect(response['overdue_balances'].first['currency']).to eq('EUR') | ||
expect(response['overdue_balances'].first['amount_cents']).to eq(100) | ||
end | ||
end | ||
|
||
context 'when options are present' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/overdue_balance?currency=EUR') | ||
.to_return(body: overdue_balances_response, status: 200) | ||
end | ||
|
||
it 'returns overdue balance' do | ||
response = resource.get_all({ currency: 'EUR' }) | ||
|
||
expect(response['overdue_balances'].first['currency']).to eq('EUR') | ||
expect(response['overdue_balances'].first['amount_cents']).to eq(100) | ||
end | ||
end | ||
|
||
context 'when there is an issue' do | ||
before do | ||
stub_request(:get, 'https://api.getlago.com/api/v1/analytics/overdue_balance') | ||
.to_return(body: error_response, status: 422) | ||
end | ||
|
||
it 'raises an error' do | ||
expect { resource.get_all }.to raise_error Lago::Api::HttpError | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters