-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Displaying registered company name and address (#1128)
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
1 parent
d7ebd86
commit 5a49156
Showing
13 changed files
with
273 additions
and
2 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
app/controllers/waste_carriers_engine/check_registered_company_name_forms_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
21 changes: 21 additions & 0 deletions
21
app/forms/waste_carriers_engine/check_registered_company_name_form.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/views/waste_carriers_engine/check_registered_company_name_forms/new.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
config/locales/forms/check_registered_company_name_forms/en.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
39 changes: 39 additions & 0 deletions
39
spec/forms/waste_carriers_engine/check_registered_company_name_forms_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
21 changes: 21 additions & 0 deletions
21
...aste_carriers_engine/new_registration_workflow/check_registered_company_name_form_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
spec/requests/waste_carriers_engine/check_registered_company_name_forms_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |