diff --git a/Gemfile b/Gemfile index 6e904513e..db3751b09 100644 --- a/Gemfile +++ b/Gemfile @@ -40,7 +40,9 @@ gem 'jrpc', github: 'didww/jrpc' gem 'active_admin_sidebar', '1.1.0' # XLS generation -gem 'excelinator', github: 'livingsocial/excelinator' +# can be switched back to the original repo after ruby 3 fix PR merged +# https://github.com/livingsocial/excelinator/pull/19 +gem 'excelinator', github: 'senid231/excelinator', branch: 'ruby3-fix' # REST API gem 'jsonapi-resources', '~> 0.9.12' diff --git a/Gemfile.lock b/Gemfile.lock index a378ceec4..6cc734929 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -56,13 +56,6 @@ GIT specs: prometheus_exporter (0.5.1) -GIT - remote: https://github.com/livingsocial/excelinator.git - revision: 51cd9dbdbcc0e610ff5bd31b85e4744ac379e8c5 - specs: - excelinator (1.3.1) - spreadsheet - GIT remote: https://github.com/nsarno/knock.git revision: 37e403a7c6d44f585b56a086245e41566a8d6fe1 @@ -72,6 +65,14 @@ GIT jwt (~> 2.2.1) rails (>= 5) +GIT + remote: https://github.com/senid231/excelinator.git + revision: 25afcc544a6f287a2ace9018adbe6fc96ea29cb2 + branch: ruby3-fix + specs: + excelinator (1.3.1) + spreadsheet + GIT remote: https://github.com/workgena/active_admin_date_range_preset.git revision: 1bfb64ceb9639bb76dcad2c8e2df4c5199b138f3 @@ -545,7 +546,7 @@ GEM rubocop (>= 1.33.0, < 2.0) rubocop-rspec (1.39.0) rubocop (>= 0.68.1) - ruby-ole (1.2.12.1) + ruby-ole (1.2.12.2) ruby-progressbar (1.13.0) ruby2_keywords (0.0.4) rubyzip (1.3.0) @@ -585,8 +586,8 @@ GEM simplecov (~> 0.19) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - spreadsheet (1.1.7) - ruby-ole (>= 1.0) + spreadsheet (1.3.0) + ruby-ole sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) diff --git a/spec/factories/billing/invoice_destination.rb b/spec/factories/billing/invoice_destination.rb index 31eec17b8..1c3ff8c6c 100644 --- a/spec/factories/billing/invoice_destination.rb +++ b/spec/factories/billing/invoice_destination.rb @@ -26,8 +26,21 @@ invoice trait :filled do - country - network + country { FactoryBot.create(:country, :uniq_name) } + network { FactoryBot.create(:network, :uniq_name) } + end + + trait :success do + filled + sequence(:dst_prefix, &:to_s) + rate { rand + rand(5) } + successful_calls_count { rand(1..1000) } + calls_duration { successful_calls_count + (successful_calls_count * rand(100)) } + amount { (successful_calls_count * rand(5)).round(6) } + first_call_at { 25.hours.ago } + first_successful_call_at { 24.hours.ago } + last_successful_call_at { 1.minute.ago } + last_call_at { 1.second.ago } end end end diff --git a/spec/fixtures/files/invoice_template.odt b/spec/fixtures/files/invoice_template.odt new file mode 100644 index 000000000..23fdf0537 Binary files /dev/null and b/spec/fixtures/files/invoice_template.odt differ diff --git a/spec/services/billing_invoice/generate_document_spec.rb b/spec/services/billing_invoice/generate_document_spec.rb new file mode 100644 index 000000000..0720fc7d6 --- /dev/null +++ b/spec/services/billing_invoice/generate_document_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +RSpec.describe BillingInvoice::GenerateDocument do + subject do + described_class.call(service_params) + end + + let(:service_params) { { invoice: invoice } } + + let!(:contractor) { FactoryBot.create(:vendor) } + let(:odt_fixture_binary) do + IO.binread Rails.root.join('spec/fixtures/files/invoice_template.odt') + end + let!(:invoice_template) do + FactoryBot.create(:invoice_template, data: odt_fixture_binary) + end + let!(:account) { FactoryBot.create(:account, account_attrs) } + let(:account_attrs) do + { + contractor: contractor, + vendor_invoice_template: invoice_template + } + end + let!(:invoice) { FactoryBot.create(:invoice, invoice_attrs) } + let(:invoice_attrs) do + { + account: account, + vendor_invoice: true, + type_id: Billing::InvoiceType::MANUAL, + state_id: Billing::InvoiceState::NEW, + start_date: Time.zone.parse('2020-01-01 00:00:00'), + end_date: Time.zone.parse('2020-02-01 00:00:00') + } + end + let!(:destinations) do + FactoryBot.create_list(:invoice_destination, 20, :success, invoice: invoice) + end + + it 'creates invoice document' do + expect { subject }.to change { Billing::InvoiceDocument.count }.by(1) + doc = Billing::InvoiceDocument.last! + expect(doc).to have_attributes( + invoice: invoice, + filename: invoice.file_name.to_s, + data: be_present, + csv_data: a_kind_of(String), + xls_data: a_kind_of(String) + ) + end +end