diff --git a/lib/lago-ruby-client.rb b/lib/lago-ruby-client.rb index 33b4904..b2785e5 100644 --- a/lib/lago-ruby-client.rb +++ b/lib/lago-ruby-client.rb @@ -23,10 +23,10 @@ require 'lago/api/resources/gross_revenue' require 'lago/api/resources/group' require 'lago/api/resources/invoice' +require 'lago/api/resources/invoice_collection' require 'lago/api/resources/invoiced_usage' require 'lago/api/resources/mrr' require 'lago/api/resources/organization' -require 'lago/api/resources/outstanding_invoice' require 'lago/api/resources/plan' require 'lago/api/resources/subscription' require 'lago/api/resources/tax' diff --git a/lib/lago/api/resources/outstanding_invoice.rb b/lib/lago/api/resources/invoice_collection.rb similarity index 61% rename from lib/lago/api/resources/outstanding_invoice.rb rename to lib/lago/api/resources/invoice_collection.rb index 9d4ce6b..3efd8aa 100644 --- a/lib/lago/api/resources/outstanding_invoice.rb +++ b/lib/lago/api/resources/invoice_collection.rb @@ -3,13 +3,13 @@ module Lago module Api module Resources - class OutstandingInvoice < Base + class InvoiceCollection < Base def api_resource - 'analytics/outstanding_invoices' + 'analytics/invoice_collection' end def root_name - 'outstanding_invoice' + 'invoice_collection' end end end diff --git a/spec/fixtures/api/outstanding_invoice_index.json b/spec/fixtures/api/invoice_collection_index.json similarity index 92% rename from spec/fixtures/api/outstanding_invoice_index.json rename to spec/fixtures/api/invoice_collection_index.json index fd809fd..4ce58b5 100644 --- a/spec/fixtures/api/outstanding_invoice_index.json +++ b/spec/fixtures/api/invoice_collection_index.json @@ -1,5 +1,5 @@ { - "outstanding_invoices": [ + "invoice_collections": [ { "month": "2023-11-01T00:00:00.000Z", "payment_status": "pending", diff --git a/spec/lago/api/resources/outstanding_invoice_spec.rb b/spec/lago/api/resources/outstanding_invoice_spec.rb index 50ad702..b46f13b 100644 --- a/spec/lago/api/resources/outstanding_invoice_spec.rb +++ b/spec/lago/api/resources/outstanding_invoice_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Lago::Api::Resources::OutstandingInvoice do +RSpec.describe Lago::Api::Resources::InvoiceCollection do subject(:resource) { described_class.new(client) } let(:client) { Lago::Api::Client.new } @@ -16,39 +16,39 @@ end describe '#get_all' do - let(:outstanding_invoices_response) { load_fixture('outstanding_invoice_index') } + let(:invoice_collections_response) { load_fixture('invoice_collection_index') } context 'when there is no options' do before do - stub_request(:get, 'https://api.getlago.com/api/v1/analytics/outstanding_invoices') - .to_return(body: outstanding_invoices_response, status: 200) + stub_request(:get, 'https://api.getlago.com/api/v1/analytics/invoice_collection') + .to_return(body: invoice_collections_response, status: 200) end it 'returns gross revenue' do response = resource.get_all - expect(response['outstanding_invoices'].first['currency']).to eq('EUR') - expect(response['outstanding_invoices'].first['amount_cents']).to eq(100) + expect(response['invoice_collections'].first['currency']).to eq('EUR') + expect(response['invoice_collections'].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/outstanding_invoices?currency=EUR') - .to_return(body: outstanding_invoices_response, status: 200) + stub_request(:get, 'https://api.getlago.com/api/v1/analytics/invoice_collection?currency=EUR') + .to_return(body: invoice_collections_response, status: 200) end - it 'returns gross revenue' do + it 'returns invoice collection' do response = resource.get_all({ currency: 'EUR' }) - expect(response['outstanding_invoices'].first['currency']).to eq('EUR') - expect(response['outstanding_invoices'].first['amount_cents']).to eq(100) + expect(response['invoice_collections'].first['currency']).to eq('EUR') + expect(response['invoice_collections'].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/outstanding_invoices') + stub_request(:get, 'https://api.getlago.com/api/v1/analytics/invoice_collection') .to_return(body: error_response, status: 422) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 17f128b..f397ec8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,10 +19,10 @@ require 'lago/api/resources/gross_revenue' require 'lago/api/resources/group' require 'lago/api/resources/invoice' +require 'lago/api/resources/invoice_collection' require 'lago/api/resources/invoiced_usage' require 'lago/api/resources/mrr' require 'lago/api/resources/organization' -require 'lago/api/resources/outstanding_invoice' require 'lago/api/resources/plan' require 'lago/api/resources/subscription' require 'lago/api/resources/tax'