Skip to content

Commit

Permalink
feat(hubspot): Fix integration customer update service
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannovosad committed Oct 16, 2024
1 parent cb4bf98 commit 4dbb033
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 34 deletions.
15 changes: 4 additions & 11 deletions app/services/integration_customers/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@ def call
return result if integration_customer.type == 'IntegrationCustomers::AnrokCustomer'
return result.not_found_failure!(resource: 'integration_customer') unless integration_customer

if external_customer_id.present?
integration_customer.external_customer_id = external_customer_id
integration_customer.targeted_object = targeted_object if targeted_object.present?
integration_customer.save!
end

if sync_with_provider
integration_customer.subsidiary_id = subsidiary_id if subsidiary_id.present?
integration_customer.targeted_object = targeted_object if targeted_object.present?
integration_customer.external_customer_id = external_customer_id if external_customer_id.present?
integration_customer.targeted_object = targeted_object if targeted_object.present?
integration_customer.save!

if integration_customer.external_customer_id.present?
update_result = update_service_class.call(integration:, integration_customer:)
return update_result unless update_result.success?

integration_customer.save!
end

result.integration_customer = integration_customer
Expand Down
25 changes: 2 additions & 23 deletions spec/services/integration_customers/update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
expect(aggregator_contacts_update_service).to have_received(:call)
expect(result).to be_success
expect(result.integration_customer).to eq(integration_customer)
expect(result.integration_customer.subsidiary_id).to eq(subsidiary_id)
end
end
end
Expand All @@ -100,12 +99,6 @@
expect(result.integration_customer).to eq(integration_customer)
end
end

it 'updates integration customer' do
result = service_call

expect(result.integration_customer.subsidiary_id).to eq(subsidiary_id)
end
end

context 'with anrok customer' do
Expand All @@ -132,10 +125,10 @@
context 'when customer external id is present' do
let(:external_customer_id) { SecureRandom.uuid }

it 'does not calls aggregator update service' do
it 'calls aggregator update service' do
service_call

expect(aggregator_contacts_update_service).not_to have_received(:call)
expect(aggregator_contacts_update_service).to have_received(:call)
end

it 'updates integration customer' do
Expand All @@ -145,20 +138,6 @@
end
end

context 'when subsidiary id is present' do
it 'does not calls aggregator update service' do
service_call

expect(aggregator_contacts_update_service).not_to have_received(:call)
end

it 'does not save subsidiary id' do
result = service_call

expect(result.integration_customer.subsidiary_id).not_to eq(subsidiary_id)
end
end

context 'when customer external id is not present' do
let(:external_customer_id) { nil }

Expand Down

0 comments on commit 4dbb033

Please sign in to comment.