Skip to content

Commit

Permalink
Revert "feat(netsuite): Add shipping and billing address to create co…
Browse files Browse the repository at this point in the history
…ntact payload (#2439)"

This reverts commit 04f0211.
  • Loading branch information
ivannovosad committed Aug 21, 2024
1 parent cb9755c commit c5e28ce
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 277 deletions.
11 changes: 0 additions & 11 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,6 @@ def shipping_address
}
end

def same_billing_and_shipping_address?
return true if shipping_address.values.all?(&:blank?)

address_line1 == shipping_address_line1 &&
address_line2 == shipping_address_line2 &&
city == shipping_city &&
zipcode == shipping_zipcode &&
state == shipping_state &&
country == shipping_country
end

private

def ensure_slug
Expand Down
64 changes: 2 additions & 62 deletions app/services/integrations/aggregator/contacts/payloads/netsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Netsuite < BasePayload
def create_body
{
'type' => 'customer', # Fixed value
'isDynamic' => true, # Fixed value
'isDynamic' => false, # Fixed value
'columns' => {
'companyname' => customer.name,
'subsidiary' => subsidiary_id,
Expand All @@ -21,8 +21,7 @@ def create_body
},
'options' => {
'ignoreMandatoryFields' => false # Fixed value
},
'lines' => lines
}
}
end

Expand All @@ -47,65 +46,6 @@ def update_body

private

def lines
if customer.same_billing_and_shipping_address?
[
{
'lineItems' => [
{
'defaultshipping' => true,
'defaultbilling' => true,
'subObjectId' => 'addressbookaddress',
'subObject' => {
'addr1' => customer.address_line1,
'addr2' => customer.address_line2,
'city' => customer.city,
'zip' => customer.zipcode,
'state' => customer.state,
'country' => customer.country
}
}
],
'sublistId' => 'addressbook'
}
]
else
[
{
'lineItems' => [
{
'defaultshipping' => false,
'defaultbilling' => true,
'subObjectId' => 'addressbookaddress',
'subObject' => {
'addr1' => customer.address_line1,
'addr2' => customer.address_line2,
'city' => customer.city,
'zip' => customer.zipcode,
'state' => customer.state,
'country' => customer.country
}
},
{
'defaultshipping' => true,
'defaultbilling' => false,
'subObjectId' => 'addressbookaddress',
'subObject' => {
'addr1' => customer.shipping_address_line1,
'addr2' => customer.shipping_address_line2,
'city' => customer.shipping_city,
'zip' => customer.shipping_zipcode,
'state' => customer.shipping_state,
'country' => customer.shipping_country
}
}
],
'sublistId' => 'addressbook'
}
]
end
end

def customer_url
url = ENV["LAGO_FRONT_URL"].presence || "https://app.getlago.com"

Expand Down
18 changes: 0 additions & 18 deletions spec/factories/customers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,5 @@
legal_name { Faker::Company.name }
legal_number { Faker::Company.duns_number }
currency { 'EUR' }

trait :with_shipping_address do
shipping_address_line1 { Faker::Address.street_address }
shipping_address_line2 { Faker::Address.secondary_address }
shipping_city { Faker::Address.city }
shipping_zipcode { Faker::Address.zip_code }
shipping_state { Faker::Address.state }
shipping_country { Faker::Address.country_code }
end

trait :with_same_billing_and_shipping_address do
shipping_address_line1 { address_line1 }
shipping_address_line2 { address_line2 }
shipping_city { city }
shipping_zipcode { zipcode }
shipping_state { state }
shipping_country { country }
end
end
end
30 changes: 0 additions & 30 deletions spec/models/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,34 +290,4 @@
end
end
end

describe '#same_billing_and_shipping_address?' do
subject(:method_call) { customer.same_billing_and_shipping_address? }

context 'when shipping address is present' do
context 'when shipping address is not the same as billing address' do
let(:customer) { build_stubbed(:customer, :with_shipping_address) }

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

context 'when shipping address is the same as billing address' do
let(:customer) { build_stubbed(:customer, :with_same_billing_and_shipping_address) }

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

context 'when shipping address is not present' do
let(:customer) { build_stubbed(:customer) }

it 'returns true' do
expect(subject).to eq(true)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RSpec.describe Integrations::Aggregator::Contacts::CreateService do
subject(:service_call) { described_class.call(integration:, customer:, subsidiary_id:) }

let(:customer) { create(:customer, :with_same_billing_and_shipping_address, organization:) }
let(:customer) { create(:customer, organization:) }
let(:subsidiary_id) { '1' }
let(:organization) { create(:organization) }
let(:lago_client) { instance_double(LagoHttpClient::Client) }
Expand Down Expand Up @@ -46,7 +46,7 @@
let(:params) do
{
'type' => 'customer',
'isDynamic' => true,
'isDynamic' => false,
'columns' => {
'companyname' => customer.name,
'subsidiary' => subsidiary_id,
Expand All @@ -59,27 +59,7 @@
},
'options' => {
'ignoreMandatoryFields' => false
},
'lines' => [
{
'lineItems' => [
{
'defaultshipping' => true,
'defaultbilling' => true,
'subObjectId' => 'addressbookaddress',
'subObject' => {
'addr1' => customer.address_line1,
'addr2' => customer.address_line2,
'city' => customer.city,
'zip' => customer.zipcode,
'state' => customer.state,
'country' => customer.country
}
}
],
'sublistId' => 'addressbook'
}
]
}
}
end

Expand Down Expand Up @@ -179,7 +159,7 @@
let(:params) do
{
'type' => 'customer',
'isDynamic' => true,
'isDynamic' => false,
'columns' => {
'companyname' => customer.name,
'subsidiary' => subsidiary_id,
Expand All @@ -192,27 +172,7 @@
},
'options' => {
'ignoreMandatoryFields' => false
},
'lines' => [
{
'lineItems' => [
{
'defaultshipping' => true,
'defaultbilling' => true,
'subObjectId' => 'addressbookaddress',
'subObject' => {
'addr1' => customer.address_line1,
'addr2' => customer.address_line2,
'city' => customer.city,
'zip' => customer.zipcode,
'state' => customer.state,
'country' => customer.country
}
}
],
'sublistId' => 'addressbook'
}
]
}
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

RSpec.describe Integrations::Aggregator::Contacts::Payloads::Netsuite do
let(:integration) { integration_customer.integration }
let(:integration_customer) { FactoryBot.create(:netsuite_customer, customer:) }
let(:customer) { create(:customer) }
let(:customer) { integration_customer.customer }
let(:integration_customer) { FactoryBot.create(:netsuite_customer) }
let(:subsidiary_id) { Faker::Number.number(digits: 2) }
let(:payload) { described_class.new(integration:, customer:, integration_customer:, subsidiary_id:) }
let(:customer_link) { payload.__send__(:customer_url) }
Expand All @@ -16,7 +16,7 @@
let(:payload_body) do
{
'type' => 'customer',
'isDynamic' => true,
'isDynamic' => false,
'columns' => {
'companyname' => customer.name,
'subsidiary' => subsidiary_id,
Expand All @@ -29,117 +29,12 @@
},
'options' => {
'ignoreMandatoryFields' => false
},
'lines' => lines
}
}
end

context 'when shipping address is present' do
context 'when shipping address is not the same as billing address' do
let(:customer) { create(:customer, :with_shipping_address) }

let(:lines) do
[
{
'lineItems' => [
{
'defaultshipping' => false,
'defaultbilling' => true,
'subObjectId' => 'addressbookaddress',
'subObject' => {
'addr1' => customer.address_line1,
'addr2' => customer.address_line2,
'city' => customer.city,
'zip' => customer.zipcode,
'state' => customer.state,
'country' => customer.country
}
},
{
'defaultshipping' => true,
'defaultbilling' => false,
'subObjectId' => 'addressbookaddress',
'subObject' => {
'addr1' => customer.shipping_address_line1,
'addr2' => customer.shipping_address_line2,
'city' => customer.shipping_city,
'zip' => customer.shipping_zipcode,
'state' => customer.shipping_state,
'country' => customer.shipping_country
}
}
],
'sublistId' => 'addressbook'
}
]
end

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

context 'when shipping address is the same as billing address' do
let(:customer) { create(:customer, :with_same_billing_and_shipping_address) }

let(:lines) do
[
{
'lineItems' => [
{
'defaultshipping' => true,
'defaultbilling' => true,
'subObjectId' => 'addressbookaddress',
'subObject' => {
'addr1' => customer.address_line1,
'addr2' => customer.address_line2,
'city' => customer.city,
'zip' => customer.zipcode,
'state' => customer.state,
'country' => customer.country
}
}
],
'sublistId' => 'addressbook'
}
]
end

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

context 'when shipping address is not present' do
let(:customer) { create(:customer) }

let(:lines) do
[
{
'lineItems' => [
{
'defaultshipping' => true,
'defaultbilling' => true,
'subObjectId' => 'addressbookaddress',
'subObject' => {
'addr1' => customer.address_line1,
'addr2' => customer.address_line2,
'city' => customer.city,
'zip' => customer.zipcode,
'state' => customer.state,
'country' => customer.country
}
}
],
'sublistId' => 'addressbook'
}
]
end

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

Expand Down

0 comments on commit c5e28ce

Please sign in to comment.