Skip to content

Commit

Permalink
fix: Ensure correct integration customer is used when syncing netsuit…
Browse files Browse the repository at this point in the history
…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
lovrocolic authored Nov 6, 2024
1 parent a24db07 commit 57b87d4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def integration_invoice
end

def integration_customer
@integration_customer ||= invoice.customer&.integration_customers&.first
@integration_customer ||= invoice.customer&.integration_customers&.accounting_kind&.first
end
end
end
Expand Down
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

0 comments on commit 57b87d4

Please sign in to comment.