-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Ensure correct integration customer is used when syncing netsuit…
…e payments (#2785) ## Context When syncing netsuite payments we need to ensure that correct `integration_customer` object is used in the payload since there can be attached integration_customers of other kinds as well
- Loading branch information
1 parent
a24db07
commit 57b87d4
Showing
2 changed files
with
53 additions
and
1 deletion.
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
52 changes: 52 additions & 0 deletions
52
spec/services/integrations/aggregator/payments/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,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Integrations::Aggregator::Payments::Payloads::BasePayload, type: :service do | ||
let(:payload) { described_class.new(integration:, payment:) } | ||
let(:payment) { create(:payment, payable: invoice) } | ||
let(:invoice) { create(:invoice, customer:, organization:) } | ||
let(:integration) { create(:netsuite_integration, organization:) } | ||
let(:integration_customer) { create(:netsuite_customer, integration:, customer:) } | ||
let(:customer) { create(:customer, organization:) } | ||
let(:organization) { create(:organization) } | ||
|
||
describe '#initialize' do | ||
it 'assigns the payment' do | ||
expect(payload.instance_variable_get(:@payment)).to eq(payment) | ||
end | ||
end | ||
|
||
describe '#integration_customer' do | ||
subject(:method_call) { payload.__send__(:integration_customer) } | ||
|
||
before do | ||
integration_customer | ||
create(:hubspot_customer, customer:) | ||
end | ||
|
||
it 'returns the first accounting kind integration customer' do | ||
expect(subject).to eq(integration_customer) | ||
end | ||
|
||
it 'memoizes the integration customer' do | ||
subject | ||
expect(payload.instance_variable_get(:@integration_customer)).to eq(integration_customer) | ||
end | ||
end | ||
|
||
describe '#body' do | ||
it 'returns correct body' do | ||
expect(payload.body).to eq( | ||
[ | ||
{ | ||
'invoice_id' => nil, | ||
'account_code' => nil, | ||
'date' => payment.created_at.utc.iso8601, | ||
'amount_cents' => payment.amount_cents | ||
} | ||
] | ||
) | ||
end | ||
end | ||
end |