Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(salesforce): Add create customer without external id #2887

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/services/integration_customers/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def self.service_class(integration)
IntegrationCustomers::XeroService
when 'Integrations::HubspotIntegration'
IntegrationCustomers::HubspotService
when 'Integrations::SalesforceIntegration'
brunomiguelpinto marked this conversation as resolved.
Show resolved Hide resolved
IntegrationCustomers::SalesforceService
else
raise(NotImplementedError)
end
Expand Down
30 changes: 30 additions & 0 deletions app/services/integration_customers/salesforce_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module IntegrationCustomers
class SalesforceService < ::BaseService
def initialize(integration:, customer:, subsidiary_id:, **params)
@customer = customer
@subsidiary_id = subsidiary_id
@integration = integration
@params = params&.with_indifferent_access

super(nil)
end

def create
new_integration_customer = IntegrationCustomers::BaseCustomer.create!(
integration:,
customer:,
type: 'IntegrationCustomers::SalesforceCustomer',
sync_with_provider: true
)

result.integration_customer = new_integration_customer
result
end

private

attr_reader :integration, :customer, :subsidiary_id, :params
end
end
64 changes: 64 additions & 0 deletions spec/services/integration_customers/factory_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

# spec/factories/integration_customers/factory_spec.rb
require 'rails_helper'

RSpec.describe IntegrationCustomers::Factory do
describe '.new_instance' do
subject { described_class.new_instance(integration:, customer:, subsidiary_id:, **params) }

let(:organization) { membership.organization }
let(:membership) { create(:membership) }
let(:customer) { create(:customer, organization:) }
let(:subsidiary_id) {}
let(:params) {{}}

context 'when the integration is NetsuiteIntegration' do
let(:integration) { create(:netsuite_integration, organization:) }

it 'returns an instance of IntegrationCustomers::NetsuiteService' do
expect(subject).to be_an_instance_of(IntegrationCustomers::NetsuiteService)
end
end

context 'when the integration is AnrokIntegration' do
let(:integration) { create(:anrok_integration, organization:) }

it 'returns an instance of IntegrationCustomers::AnrokService' do
expect(subject).to be_an_instance_of(IntegrationCustomers::AnrokService)
end
end

context 'when the integration is XeroIntegration' do
let(:integration) { create(:xero_integration, organization:) }

it 'returns an instance of IntegrationCustomers::XeroService' do
expect(subject).to be_an_instance_of(IntegrationCustomers::XeroService)
end
end

context 'when the integration is HubspotIntegration' do
let(:integration) { create(:hubspot_integration, organization:) }

it 'returns an instance of IntegrationCustomers::HubspotService' do
expect(subject).to be_an_instance_of(IntegrationCustomers::HubspotService)
end
end

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

it 'returns an instance of IntegrationCustomers::SalesforceService' do
expect(subject).to be_an_instance_of(IntegrationCustomers::SalesforceService)
end
end

context 'when integration is nil' do
let(:integration) { nil }

it 'raises a NotImplementedError' do
expect { subject }.to raise_error(NotImplementedError)
end
end
end
end
29 changes: 29 additions & 0 deletions spec/services/integration_customers/salesforce_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe IntegrationCustomers::SalesforceService, type: :service do
let(:integration) { create(:salesforce_integration, organization:) }
let(:organization) { membership.organization }
let(:membership) { create(:membership) }
let(:customer) { create(:customer, organization:, customer_type: 'individual') }

describe '#create' do
subject(:service_call) { described_class.new(integration:, customer:, subsidiary_id: nil).create }

it 'returns integration customer' do
result = service_call

aggregate_failures do
expect(result).to be_success
expect(result.integration_customer.integration_id).to eq(integration.id)
expect(result.integration_customer.customer_id).to eq(customer.id)
expect(result.integration_customer.type).to eq('IntegrationCustomers::SalesforceCustomer')
end
end

it 'creates integration customer' do
expect { service_call }.to change(IntegrationCustomers::SalesforceCustomer, :count).by(1)
end
end
end
Loading