Skip to content

Commit

Permalink
feat(salesforce): Sync with provider always true (#2976)
Browse files Browse the repository at this point in the history
## Context

This PR updates the link_customer! method to ensure that the
sync_with_provider attribute is always set to true when the integration
type is SalesforceIntegration. Previously, the value for
sync_with_provider was hardcoded as false, regardless of the integration
type.
  • Loading branch information
brunomiguelpinto authored Dec 18, 2024
1 parent dd3e9f7 commit a483306
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/services/integration_customers/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ def sync_customer!
end

def link_customer!
sync_with_provider = integration&.type&.to_s == 'Integrations::SalesforceIntegration'

new_integration_customer = IntegrationCustomers::BaseCustomer.create!(
integration:,
customer:,
external_customer_id: params[:external_customer_id],
type: customer_type,
sync_with_provider: false
sync_with_provider: sync_with_provider
)

if integration&.type&.to_s == 'Integrations::NetsuiteIntegration'
Expand Down
20 changes: 19 additions & 1 deletion spec/services/integration_customers/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
let(:organization) { membership.organization }
let(:membership) { create(:membership) }
let(:customer) { create(:customer, organization:) }
let(:integration_type) { 'netsuite' }

describe '#call' do
subject(:service_call) { described_class.call(params:, integration:, customer:) }

let(:params) do
{
integration_type: 'netsuite',
integration_type:,
integration_code:,
sync_with_provider:,
external_customer_id:,
Expand Down Expand Up @@ -72,6 +73,23 @@
it 'creates integration customer' do
expect { service_call }.to change(IntegrationCustomers::BaseCustomer, :count).by(1)
end

context 'when the integration type is salesforce' do
let(:integration) { create(:salesforce_integration, organization:) }
let(:integration_type) { 'salesforce' }

it 'returns integration customer with sync_with_provider true' do
result = service_call

aggregate_failures do
expect(aggregator_contacts_create_service).not_to have_received(:call)
expect(result).to be_success
expect(result.integration_customer).to eq(integration_customer)
expect(result.integration_customer.external_customer_id).to eq(external_customer_id)
expect(result.integration_customer.sync_with_provider).to eq(true)
end
end
end
end

context 'when customer external id is not present' do
Expand Down

0 comments on commit a483306

Please sign in to comment.