From 7cf858afbc04c74f9f4c746def9299fa3c2e4345 Mon Sep 17 00:00:00 2001 From: Ivan Novosad Date: Wed, 10 Jul 2024 08:32:55 +0200 Subject: [PATCH] fix(integrations): Fix creating a deleted customer (#2265) ## Context We were getting a lot of dead jobs when trying to sync a deleted customer to nango (netsuite). ## Description This PR fixes the issue by not trying to sync a non-existent (deleted) customer. --- .../create_or_update_service.rb | 2 +- .../create_or_update_service_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/services/integration_customers/create_or_update_service.rb b/app/services/integration_customers/create_or_update_service.rb index 41cd56f9f83..fcbdfd8698f 100644 --- a/app/services/integration_customers/create_or_update_service.rb +++ b/app/services/integration_customers/create_or_update_service.rb @@ -11,7 +11,7 @@ def initialize(integration_customers:, customer:, new_customer:) end def call - return if integration_customers.nil? + return if integration_customers.nil? || customer.nil? sanitize_integration_customers diff --git a/spec/services/integration_customers/create_or_update_service_spec.rb b/spec/services/integration_customers/create_or_update_service_spec.rb index bd9d30826b2..678c54f6d0b 100644 --- a/spec/services/integration_customers/create_or_update_service_spec.rb +++ b/spec/services/integration_customers/create_or_update_service_spec.rb @@ -38,6 +38,22 @@ end end + context 'without customer' do + let(:integration_code) { integration.code } + let(:sync_with_provider) { true } + let(:external_customer_id) { nil } + let(:new_customer) { true } + let(:customer) { nil } + + it 'does not call create job' do + expect { service_call }.not_to have_enqueued_job(IntegrationCustomers::CreateJob) + end + + it 'does not call update job' do + expect { service_call }.not_to have_enqueued_job(IntegrationCustomers::UpdateJob) + end + end + context 'without external fields set' do let(:integration_code) { integration.code } let(:sync_with_provider) { false }