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(customer-type): Update netsuite payload with new fields #2559

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 17 additions & 4 deletions app/services/integrations/aggregator/contacts/payloads/netsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ def create_body
'type' => 'customer', # Fixed value
'isDynamic' => true, # Fixed value
'columns' => {
'companyname' => customer.name,
'isperson' => isperson,
'subsidiary' => subsidiary_id,
'custentity_lago_id' => customer.id,
'custentity_lago_sf_id' => customer.external_salesforce_id,
'custentity_lago_customer_link' => customer_url,
'email' => email,
'phone' => phone
},
}.merge(names),
'options' => {
'ignoreMandatoryFields' => false # Fixed value
}
Expand All @@ -29,13 +29,13 @@ def update_body
'type' => 'customer',
'recordId' => integration_customer.external_customer_id,
'values' => {
'companyname' => customer.name,
'isperson' => isperson,
'subsidiary' => integration_customer.subsidiary_id,
'custentity_lago_sf_id' => customer.external_salesforce_id,
'custentity_lago_customer_link' => customer_url,
'email' => email,
'phone' => phone
},
}.merge(names),
'options' => {
'isDynamic' => false
}
Expand All @@ -44,6 +44,19 @@ def update_body

private

def names
# customer_type might be nil -> in that case it's a company so we better check for an individual type here
return {'companyname' => customer.name} unless customer.customer_type_individual?

names_hash = {'firstname' => customer.firstname, 'lastname' => customer.lastname}

customer.name.present? ? names_hash.merge('companyname' => customer.name) : names_hash
end

def isperson
customer.customer_type_individual? ? 'T' : 'F'
end

def include_lines?
!integration.legacy_script && !customer.empty_billing_and_shipping_address?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
'columns' => {
'companyname' => customer.name,
'subsidiary' => subsidiary_id,
'isperson' => 'F',
'custentity_lago_id' => customer.id,
'custentity_lago_sf_id' => customer.external_salesforce_id,
'custentity_lago_customer_link' => customer_link,
'email' => customer.email.to_s.split(',').first&.strip,
'phone' => customer.phone.to_s.split(',').first&.strip
},
}.merge(
customer.customer_type_individual? ? {'firstname' => customer.firstname, 'lastname' => customer.lastname} : {}
),
'options' => {
'ignoreMandatoryFields' => false
},
Expand Down Expand Up @@ -305,26 +308,53 @@
describe "#update_body" do
subject(:update_body_call) { payload.update_body }

let(:customer) { create(:customer, customer_type:) }
let(:isperson) { payload.__send__(:isperson) }

let(:payload_body) do
{
'type' => 'customer',
'recordId' => integration_customer.external_customer_id,
'values' => {
'companyname' => customer.name,
'isperson' => isperson,
'subsidiary' => integration_customer.subsidiary_id,
'custentity_lago_sf_id' => customer.external_salesforce_id,
'custentity_lago_customer_link' => customer_link,
'email' => customer.email.to_s.split(',').first&.strip,
'phone' => customer.phone.to_s.split(',').first&.strip
},
}.merge(names),
'options' => {
'isDynamic' => false
}
}
end

it "returns the payload body" do
expect(subject).to eq payload_body
context 'when customer is an individual' do
let(:customer_type) { :individual }

let(:names) do
{
'companyname' => customer.name,
'firstname' => customer.firstname,
'lastname' => customer.lastname
}
end

it "returns the payload body" do
expect(subject).to eq payload_body
end
end

context 'when customer is not an individual' do
let(:customer_type) { [nil, :company].sample }

let(:names) do
{'companyname' => customer.name}
end

it "returns the payload body" do
expect(subject).to eq payload_body
end
end
end

Expand Down Expand Up @@ -368,8 +398,93 @@
end
end

describe '#names' do
subject(:names_call) { payload.__send__(:names) }

let(:customer) { create(:customer, customer_type:, name:) }

context 'when customer type is nil' do
let(:customer_type) { nil }
let(:name) { Faker::TvShows::SiliconValley.character }
let(:names) { {'companyname' => customer.name} }

it 'returns the result hash' do
expect(subject).to eq(names)
end
end

context 'when customer type is company' do
let(:customer_type) { :company }
let(:name) { Faker::TvShows::SiliconValley.character }

let(:names) { {'companyname' => customer.name} }

it 'returns the result hash' do
expect(subject).to eq(names)
end
end

context 'when customer type is individual' do
let(:customer_type) { :individual }

context 'when name is present' do
let(:name) { Faker::TvShows::SiliconValley.character }

let(:names) do
{'companyname' => customer.name, 'firstname' => customer.firstname, 'lastname' => customer.lastname}
end

it 'returns the result hash' do
expect(subject).to eq(names)
end
end

context 'when name is not present' do
let(:name) { nil }

let(:names) do
{'firstname' => customer.firstname, 'lastname' => customer.lastname}
end

it 'returns the result hash' do
expect(subject).to eq(names)
end
end
end
end

describe '#isperson' do
subject(:isperson_call) { payload.__send__(:isperson) }

let(:customer) { create(:customer, customer_type:) }

context 'when customer type is nil' do
let(:customer_type) { nil }

it 'returns F' do
expect(subject).to eq('F')
end
end

context 'when customer type is company' do
let(:customer_type) { :company }

it 'returns F' do
expect(subject).to eq('F')
end
end

context 'when customer type is individual' do
let(:customer_type) { :individual }

it 'returns T' do
expect(subject).to eq('T')
end
end
end

describe '#phone' do
subject(:phone_call) { payload.__send__(:phone) }
subject { payload.__send__(:phone) }

let(:customer) { create(:customer, phone:) }

Expand Down
Loading