Skip to content

Commit

Permalink
Displaying registered company name and address (#1128)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/RUBY-1744

As per the improve legal entities data epic, here we have the registered company's name and address being pulled from the companies house API and displayed for the user to check.
  • Loading branch information
Beckyrose200 committed Mar 16, 2022
1 parent d7ebd86 commit 5a49156
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require "defra_ruby_companies_house"

module WasteCarriersEngine
class CheckRegisteredCompanyNameFormsController < ::WasteCarriersEngine::FormsController
def new
super(CheckRegisteredCompanyNameForm, "check_registered_company_name_form")
end

def create
super(CheckRegisteredCompanyNameForm, "check_registered_company_name_form")
end

private

def transient_registration_attributes
params.fetch(:check_registered_company_name_form, {}).permit(:temp_use_registered_company_details, :token)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module WasteCarriersEngine
class CheckRegisteredCompanyNameForm < ::WasteCarriersEngine::BaseForm
delegate :company_no, to: :transient_registration

def company_name
companies_house_service.company_name
end

def registered_office_address_lines
companies_house_service.registered_office_address_lines
end

private

def companies_house_service
@_companies_house_service ||= DefraRubyCompaniesHouse.new(company_no)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module CanUseNewRegistrationWorkflow

state :cbd_type_form
state :registration_number_form
state :check_registered_company_name_form

state :company_name_form
state :company_postcode_form
Expand Down Expand Up @@ -186,6 +187,9 @@ module CanUseNewRegistrationWorkflow
to: :registration_number_form

transitions from: :registration_number_form,
to: :check_registered_company_name_form

transitions from: :check_registered_company_name_form,
to: :company_name_form

transitions from: :company_name_form,
Expand Down Expand Up @@ -415,6 +419,9 @@ module CanUseNewRegistrationWorkflow
if: :skip_registration_number?

transitions from: :company_name_form,
to: :check_registered_company_name_form

transitions from: :check_registered_company_name_form,
to: :registration_number_form

transitions from: :other_businesses_form,
Expand Down
1 change: 1 addition & 0 deletions app/models/waste_carriers_engine/transient_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class TransientRegistration
field :temp_payment_method, type: String
field :temp_tier_check, type: String # 'yes' or 'no' - should refactor to boolean
field :temp_reuse_registered_address, type: String
field :temp_use_registered_company_details, type: String

scope :in_progress, -> { where(:workflow_state.nin => RenewingRegistration::SUBMITTED_STATES) }
scope :submitted, -> { where(:workflow_state.in => RenewingRegistration::SUBMITTED_STATES) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%= render("waste_carriers_engine/shared/back", back_path: back_check_registered_company_name_forms_path(@check_registered_company_name_form.token)) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
<%= t(".heading") %>
</h1>
<legend class="govuk-visually-hidden">
<%= t(".heading") %>
</legend>

<%= form_for @check_registered_company_name_form do |f| %>
<%= render partial: "waste_carriers_engine/shared/error_summary", locals: { f: f } %>

<h2 class="govuk-heading-m">
<%= @check_registered_company_name_form.company_name %>
</h2>

<p class="govuk-body">
<% @check_registered_company_name_form.registered_office_address_lines.each do |line| %>
<%= line %> <br>
<% end %>
</p>

<%= f.govuk_submit t(".next_button") %>
<% end %>

<p class="govuk-body">
<%= link_to t(".enter_a_different_number"), new_registration_number_form_path %>
</p>
</div>
</div>

18 changes: 18 additions & 0 deletions config/locales/forms/check_registered_company_name_forms/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
en:
waste_carriers_engine:
check_registered_company_name_forms:
new:
title: Is this your registered name and address?
heading: Is this your registered name and address?
options:
"yes": "Yes"
"no": "No"
next_button: Continue
enter_a_different_number: "Enter a different number"
activemodel:
errors:
models:
waste_carriers_engine/check_registered_company_name_form:
attributes:
temp_use_registered_company_details:
inclusion: "You must select yes or no"
10 changes: 10 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,16 @@
on: :collection
end

resources :check_registered_company_name_forms,
only: %i[new create],
path: "check-registered-company-name",
path_names: { new: "" } do
get "back",
to: "check_registered_company_name_forms#go_back",
as: "back",
on: :collection
end

resources :company_name_forms,
only: %i[new create],
path: "company-name",
Expand Down
9 changes: 9 additions & 0 deletions spec/factories/forms/check_registered_company_name_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

FactoryBot.define do
factory :check_registered_company_name_form, class: WasteCarriersEngine::CheckRegisteredCompanyNameForm do
trait :has_required_data do
initialize_with { new(create(:new_registration, :has_required_data, workflow_state: "check_registered_company_name_form")) }
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require "rails_helper"
require "defra_ruby_companies_house"

module WasteCarriersEngine
RSpec.describe CheckRegisteredCompanyNameForm, type: :model do
let(:company_name) { Faker::Company.name }
let(:company_address) { ["10 Downing St", "Horizon House", "Bristol", "BS1 5AH"] }

before do
allow_any_instance_of(DefraRubyCompaniesHouse).to receive(:load_company)
allow_any_instance_of(DefraRubyCompaniesHouse).to receive(:company_name).and_return(company_name)
allow_any_instance_of(DefraRubyCompaniesHouse).to receive(:registered_office_address_lines).and_return(company_address)
end

describe "#submit" do
let(:check_registered_company_name_form) { build(:check_registered_company_name_form, :has_required_data) }

context "when the form is valid" do
let(:valid_params) { { token: check_registered_company_name_form.token } }

it "should submit" do
expect(check_registered_company_name_form.submit(valid_params)).to be_truthy
end
end

context "when the form is not valid" do
before do
expect(check_registered_company_name_form).to receive(:valid?).and_return(false)
end

it "should not submit" do
expect(check_registered_company_name_form.submit({})).to be_falsey
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require "rails_helper"

module WasteCarriersEngine
RSpec.describe NewRegistration do
subject { build(:new_registration, workflow_state: "check_registered_company_name_form") }

describe "#workflow_state" do
context ":check_registered_company_name_form state transitions" do
context "on next" do
include_examples "has next transition", next_state: "company_name_form"
end

context "on back" do
include_examples "has back transition", previous_state: "registration_number_form"
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module WasteCarriersEngine
context "When the registration requires a company number" do
subject { build(:new_registration, workflow_state: "company_name_form", business_type: "limitedCompany") }

include_examples "has back transition", previous_state: "registration_number_form"
include_examples "has back transition", previous_state: "check_registered_company_name_form"
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module WasteCarriersEngine
describe "#workflow_state" do
context ":registration_number_form state transitions" do
context "on next" do
include_examples "has next transition", next_state: "company_name_form"
include_examples "has next transition", next_state: "check_registered_company_name_form"
end

context "on back" do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# frozen_string_literal: true

require "rails_helper"
require "defra_ruby_companies_house"

module WasteCarriersEngine
RSpec.describe "CheckRegisteredCompanyNameForms", type: :request do

let(:company_name) { Faker::Company.name }
let(:company_address) { ["10 Downing St", "Horizon House", "Bristol", "BS1 5AH"] }

before do
allow_any_instance_of(DefraRubyCompaniesHouse).to receive(:load_company)
allow_any_instance_of(DefraRubyCompaniesHouse).to receive(:company_name).and_return(company_name)
allow_any_instance_of(DefraRubyCompaniesHouse).to receive(:registered_office_address_lines).and_return(company_address)
end

include_examples "GET flexible form", "check_registered_company_name_form"

describe "GET check_registered_company_name_form_path" do
context "when a valid user is signed in" do
let(:user) { create(:user) }
before(:each) do
sign_in(user)
end

context "when check_registered_company_name_form is given a valid companies house number" do
let(:transient_registration) do
create(:new_registration,
:has_required_data,
account_email: user.email,
workflow_state: "check_registered_company_name_form")
end

it "displays the registered company name" do
get check_registered_company_name_forms_path(transient_registration[:token])
expect(response.body).to include(company_name)
end

it "displays the registered company address" do
get check_registered_company_name_forms_path(transient_registration[:token])

company_address.each do |line|
expect(response.body).to include(line)
end
end
end
end
end

describe "POST check_registered_company_name_form_path" do
let(:transient_registration) do
create(:new_registration, workflow_state: "check_registered_company_name_form")
end

it "redirects to company_name_form" do
post_form_with_params(:check_registered_company_name_form, transient_registration.token)

expect(response).to have_http_status(302)
expect(response).to redirect_to(new_company_name_form_path(transient_registration.token))
end
end

describe "GET back_check_registered_company_name_form_path" do
context "when a valid user is signed in" do
let(:user) { create(:user) }
before(:each) do
sign_in(user)
end

context "when a valid transient registration exists" do
let(:transient_registration) do
create(:new_registration,
:has_required_data,
account_email: user.email,
workflow_state: "check_registered_company_name_form")
end

context "when the back action is triggered" do
it "returns a 302 response and redirects to the registration_number_form" do
get back_check_registered_company_name_forms_path(transient_registration[:token])

expect(response).to have_http_status(302)
expect(response).to redirect_to(registration_number_forms_path(transient_registration[:token]))
end
end
end
end
end
end
end

0 comments on commit 5a49156

Please sign in to comment.