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

Deduplicate "trading as" in business name #1136

Merged
merged 5 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,25 @@ def upper_tier_sole_trader?

def legal_name_and_or_trading_name(legal_name)
if company_name.present?
trading_name = truncate_trading_as_name(company_name)
if legal_name.present?
"#{legal_name} trading as #{company_name}"
"#{legal_name} trading as #{trading_name}"
else
company_name
trading_name
end
else
legal_name
end
end

# If the name includes " trading as " or " t/a ", drop all text up to and including that.
def truncate_trading_as_name(name)
["trading as", "t/a"].each do |term|
includes_trading_as = name.match(/^.*\s#{term}\s+(.*)/i)
return includes_trading_as[1] if includes_trading_as && includes_trading_as.length > 1
end

name
end
end
end
107 changes: 68 additions & 39 deletions spec/support/shared_examples/can_present_entity_display_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,97 @@

subject { described_class.new(registration, view) }

context "when the registration is lower tier" do
let(:tier) { "LOWER" }
shared_examples "trading as" do
it "returns entity name trading as business name" do
expect(subject.entity_display_name).to eq "#{entity_name} trading as #{trading_as_name}"
end
end

shared_examples "with and without a business name" do
context "without a business name" do
let(:company_name) { nil }

it "returns the entity name" do
expect(subject.entity_display_name).to eq entity_name
end
end

context "with a business name" do
let(:trading_as_name) { Faker::Company.name }

context "without 'trading as' detail" do
let(:company_name) { trading_as_name }
it_behaves_like "trading as"
end

context "with 'trading as' detail" do
let(:company_name) { "#{Faker::Company.name} trading as #{trading_as_name}" }
it_behaves_like "trading as"
end

it "returns the company name" do
expect(subject.entity_display_name).to eq(company_name)
context "with 't/a' detail" do
let(:company_name) { "#{Faker::Company.name} t/a #{trading_as_name}" }
it_behaves_like "trading as"
end
end
end

context "when the registration is upper tier" do
context "when the registration business type is 'soleTrader'" do
let(:business_type) { "soleTrader" }
let(:key_people) { [person_a] }
let(:trader_name) { "#{key_people[0].first_name} #{key_people[0].last_name}" }
shared_examples "limited company or limited liability partnership" do
let(:entity_name) { registered_name }

context "with a registered name" do
let(:registered_name) { Faker::Company.name }

context "without a business name" do
let(:company_name) { nil }

it "returns the trader's name" do
expect(subject.entity_display_name).to eq trader_name
end
it_behaves_like "with and without a business name"
end

context "with a business name" do
let(:company_name) { Faker::Company.name }

it "returns the sole trader name and the business name" do
expect(subject.entity_display_name).to eq "#{trader_name} trading as #{company_name}"
end
it_behaves_like "with and without a business name"
end
end

context "when the registration business type is NOT 'sole trader'" do
it "returns the company name" do
expect(subject.entity_display_name).to eq(company_name)
context "without a registered name and with a business name" do
let(:registered_name) { nil }

it "returns the business name" do
expect(subject.entity_display_name).to eq company_name
end
end
end
end

context "with a registered name and without a trading name" do
let(:registered_name) { Faker::Company.name }
let(:company_name) { nil }
describe "#entity_display_name" do
let(:company_name) { Faker::Lorem.sentence(word_count: 3) }

context "when the registration is lower tier" do
let(:tier) { "LOWER" }

it "returns the registered name" do
expect(subject.entity_display_name).to eq registered_name
it "returns the business name" do
expect(subject.entity_display_name).to eq company_name
end
end
end

context "without a registered name and with a trading name" do
let(:registered_name) { nil }
let(:company_name) { Faker::Lorem.sentence(word_count: 3) }
context "when the registration is upper tier" do

it "returns the trading name" do
expect(subject.entity_display_name).to eq company_name
end
end
context "when the registration business type is 'soleTrader'" do
let(:business_type) { "soleTrader" }
let(:key_people) { [person_a] }
let(:entity_name) { "#{key_people[0].first_name} #{key_people[0].last_name}" }

context "with both a registered name and a trading name" do
let(:registered_name) { Faker::Company.name }
let(:company_name) { Faker::Lorem.sentence(word_count: 3) }
it_behaves_like "with and without a business name"
end

it "returns the entity display name" do
expect(subject.entity_display_name).to eq "#{registered_name} trading as #{company_name}"
context "when the registration business type is 'limitedCompany'" do
let(:business_type) { "limitedCompany" }
it_behaves_like "limited company or limited liability partnership"
end

context "when the registration business type is 'limitedLiabilityPartnership'" do
let(:business_type) { "limitedLiabilityPartnership" }
it_behaves_like "limited company or limited liability partnership"
end
end
end
end