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 anrok and xero payloads with new fields #2563

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ def self.ransackable_attributes(_auth_object = nil)
%w[id name firstname lastname external_id email]
end

def display_name
names = [legal_name.presence || name.presence]
def display_name(prefer_legal_name: true)
names = prefer_legal_name ? [legal_name.presence || name.presence] : [name.presence]

if firstname.present? || lastname.present?
names << '-' if names.compact.present?
names << firstname
Expand Down
28 changes: 28 additions & 0 deletions app/services/integrations/aggregator/contacts/payloads/anrok.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ module Aggregator
module Contacts
module Payloads
class Anrok < BasePayload
def create_body
[
{
'name' => customer.display_name(prefer_legal_name: false),
'city' => customer.city,
'zip' => customer.zipcode,
'country' => customer.country,
'state' => customer.state,
'email' => email,
'phone' => phone
}
]
end

def update_body
[
{
'id' => integration_customer.external_customer_id,
'name' => customer.display_name(prefer_legal_name: false),
'city' => customer.city,
'zip' => customer.zipcode,
'country' => customer.country,
'state' => customer.state,
'email' => email,
'phone' => phone
}
]
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def create_body
[
{
'name' => customer.name,
'firstname' => customer.firstname,
'lastname' => customer.lastname,
'city' => customer.city,
'zip' => customer.zipcode,
'country' => customer.country,
Expand All @@ -32,6 +34,8 @@ def update_body
{
'id' => integration_customer.external_customer_id,
'name' => customer.name,
'firstname' => customer.firstname,
'lastname' => customer.lastname,
'city' => customer.city,
'zip' => customer.zipcode,
'country' => customer.country,
Expand Down
17 changes: 13 additions & 4 deletions spec/models/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,30 @@
let(:legal_name) { nil }

it 'returns name with firstname and lastname' do
expect(customer.display_name).to eq('ACME Inc - Thomas Anderson')
aggregate_failures do
expect(customer.display_name).to eq('ACME Inc - Thomas Anderson')
expect(customer.display_name(prefer_legal_name: false)).to eq('ACME Inc - Thomas Anderson')
end
end
end

context 'when legal_name is present and both firstname and lastname are present' do
let(:name) { nil }

it 'returns legal_name with firstname and lastname' do
expect(customer.display_name).to eq('ACME International Corporation - Thomas Anderson')
aggregate_failures do
expect(customer.display_name).to eq('ACME International Corporation - Thomas Anderson')
expect(customer.display_name(prefer_legal_name: false)).to eq('Thomas Anderson')
end
end
end

context 'when all fields are present' do
it 'returns legal_name with firstname and lastname' do
expect(customer.display_name).to eq('ACME International Corporation - Thomas Anderson')
it 'returns display name' do
aggregate_failures do
expect(customer.display_name).to eq('ACME International Corporation - Thomas Anderson')
expect(customer.display_name(prefer_legal_name: false)).to eq('ACME Inc - Thomas Anderson')
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
[
{
'name' => customer.name,
'firstname' => customer.firstname,
'lastname' => customer.lastname,
'email' => customer.email,
'city' => customer.city,
'zip' => customer.zipcode,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Integrations::Aggregator::Contacts::Payloads::Anrok do
let(:integration) { integration_customer.integration }
let(:integration_customer) { FactoryBot.create(:anrok_customer, customer:) }
let(:customer) { create(:customer) }
let(:payload) { described_class.new(integration:, customer:, integration_customer:) }
let(:customer_link) { payload.__send__(:customer_url) }

describe "#create_body" do
subject(:create_body_call) { payload.create_body }

let(:payload_body) do
[
{
'name' => customer.display_name(prefer_legal_name: false),
'city' => customer.city,
'zip' => customer.zipcode,
'country' => customer.country,
'state' => customer.state,
'email' => customer.email,
'phone' => customer.phone
}
]
end

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

describe "#update_body" do
subject(:update_body_call) { payload.update_body }

let(:payload_body) do
[
{
'id' => integration_customer.external_customer_id,
'name' => customer.display_name(prefer_legal_name: false),
'city' => customer.city,
'zip' => customer.zipcode,
'country' => customer.country,
'state' => customer.state,
'email' => customer.email,
'phone' => customer.phone
}
]
end

it "returns the payload body" do
expect(subject).to eq payload_body
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
let(:integration_customer) { FactoryBot.create(:anrok_customer) }

it 'returns payload body' do
expect(subject.first['name']).to eq(customer.name)
expect(subject.first['name']).to eq(customer.display_name(prefer_legal_name: false))
end
end
end
Expand Down Expand Up @@ -100,7 +100,7 @@
it 'returns payload body' do
aggregate_failures do
expect(subject.first['id']).to eq(integration_customer.external_customer_id)
expect(subject.first['name']).to eq(customer.name)
expect(subject.first['name']).to eq(customer.display_name(prefer_legal_name: false))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Integrations::Aggregator::Contacts::Payloads::Xero do
let(:integration) { integration_customer.integration }
let(:integration_customer) { FactoryBot.create(:xero_customer, customer:) }
let(:customer) { create(:customer) }
let(:payload) { described_class.new(integration:, customer:, integration_customer:) }
let(:customer_link) { payload.__send__(:customer_url) }

describe "#create_body" do
subject(:create_body_call) { payload.create_body }

let(:payload_body) do
[
{
'name' => customer.name,
'firstname' => customer.firstname,
'lastname' => customer.lastname,
'city' => customer.city,
'zip' => customer.zipcode,
'country' => customer.country,
'state' => customer.state,
'email' => customer.email,
'phone' => customer.phone
}
]
end

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

describe "#update_body" do
subject(:update_body_call) { payload.update_body }

let(:payload_body) do
[
{
'id' => integration_customer.external_customer_id,
'name' => customer.name,
'firstname' => customer.firstname,
'lastname' => customer.lastname,
'city' => customer.city,
'zip' => customer.zipcode,
'country' => customer.country,
'state' => customer.state,
'email' => customer.email,
'phone' => customer.phone
}
]
end

it "returns the payload body" do
expect(subject).to eq payload_body
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
{
'id' => integration_customer.external_customer_id,
'name' => customer.name,
'firstname' => customer.firstname,
'lastname' => customer.lastname,
'email' => customer.email,
'city' => customer.city,
'zip' => customer.zipcode,
Expand Down