-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(intergrations): Fix fees in invoices payload (#2656)
## Context Netsuite raises an error when creating an invoice with 0 lines items (fees). ## Description This PR fixes a situation where we're about to sync an invoice with empty line items array.
- Loading branch information
1 parent
49bf8dd
commit 8ddfc76
Showing
4 changed files
with
50 additions
and
6 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
44 changes: 44 additions & 0 deletions
44
spec/services/integrations/aggregator/invoices/payloads/base_payload_spec.rb
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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Integrations::Aggregator::Invoices::Payloads::BasePayload do | ||
let(:payload) { described_class.new(integration_customer:, invoice:) } | ||
let(:integration_customer) { create(:xero_customer, integration:, customer:) } | ||
let(:integration) { create(:xero_integration, organization:) } | ||
let(:customer) { create(:customer, organization:) } | ||
let(:organization) { create(:organization) } | ||
let(:invoice) { create(:invoice, customer:, organization:) } | ||
|
||
describe '#fees' do | ||
subject(:fees_call) { payload.__send__(:fees) } | ||
|
||
context 'when there are fees with positive amount_cents' do | ||
let(:fee1) { create(:fee, invoice:, amount_cents: 1000, created_at: 1.day.ago) } | ||
let(:fee2) { create(:fee, invoice:, amount_cents: 2000, created_at: 2.days.ago) } | ||
|
||
it 'returns fees with positive amount_cents ordered by created_at' do | ||
expect(fees_call).to eq([fee2, fee1]) | ||
end | ||
end | ||
|
||
context 'when there are no fees with positive amount_cents' do | ||
let(:fee1) { create(:fee, invoice:, amount_cents: 0, created_at: 1.day.ago) } | ||
let(:fee2) { create(:fee, invoice:, amount_cents: -1000, created_at: 2.days.ago) } | ||
|
||
it 'returns all fees ordered by created_at' do | ||
expect(fees_call).to eq([fee2, fee1]) | ||
end | ||
end | ||
|
||
context 'when there are fees with positive and zero amount_cents' do | ||
let(:fee1) { create(:fee, invoice:, amount_cents: 0, created_at: 1.day.ago) } | ||
let(:fee2) { create(:fee, invoice:, amount_cents: 100, created_at: 2.days.ago) } | ||
let(:fee3) { create(:fee, invoice:, amount_cents: 200, created_at: 3.days.ago) } | ||
|
||
it 'returns only positive fees ordered by created_at' do | ||
expect(fees_call).to eq([fee2, fee1]) | ||
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