Skip to content

Commit

Permalink
Replace lib/defra_ruby_companies_house with the new companies house gem
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDoyle-EA committed Dec 23, 2024
1 parent 8422a04 commit 951c1fb
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 238 deletions.
17 changes: 12 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ PATH
countries (~> 5.5.0)
defra_ruby_address (~> 0.1.0)
defra_ruby_alert (~> 2.2.1)
defra_ruby_companies_house
defra_ruby_email (~> 1.3.0)
defra_ruby_govpay
defra_ruby_validators (~> 2.6)
defra_ruby_validators (~> 3.0)
high_voltage (~> 3.1.2)
jbuilder (~> 2.11.5)
mongo_session_store (~> 3.2.1)
Expand Down Expand Up @@ -143,6 +144,9 @@ GEM
rest-client (~> 2.0)
defra_ruby_alert (2.2.1)
airbrake
defra_ruby_companies_house (1.0.0)
i18n
rest-client (~> 2.0)
defra_ruby_email (1.3.0)
notifications-ruby-client
rails
Expand All @@ -152,8 +156,9 @@ GEM
defra_ruby_style (0.3.0)
rubocop (>= 1.0, < 2.0)
defra_ruby_template (5.4.1)
defra_ruby_validators (2.6.0)
defra_ruby_validators (3.0.0)
activemodel
defra_ruby_companies_house
i18n
matrix
os_map_ref
Expand Down Expand Up @@ -271,7 +276,7 @@ GEM
parser (3.2.2.4)
ast (~> 2.4.1)
racc
phonelib (0.8.6)
phonelib (0.10.1)
protocol-hpack (1.4.2)
protocol-http (0.25.0)
protocol-http1 (0.16.0)
Expand Down Expand Up @@ -400,6 +405,7 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
simpleidn (0.2.3)
spring (4.1.3)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
Expand Down Expand Up @@ -428,8 +434,9 @@ GEM
uk_postcode (2.1.8)
unaccent (0.4.0)
unicode-display_width (2.5.0)
validates_email_format_of (1.7.2)
i18n
validates_email_format_of (1.8.2)
i18n (>= 0.8.0)
simpleidn
vcr (6.2.0)
web-console (4.2.1)
actionview (>= 6.0.0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "defra_ruby_companies_house"
require "defra_ruby/companies_house"

module WasteCarriersEngine
class CheckRegisteredCompanyNameFormsController < ::WasteCarriersEngine::FormsController
Expand All @@ -26,7 +26,8 @@ def transient_registration_attributes
end

def company_name
DefraRubyCompaniesHouse.new(@transient_registration.company_no).company_name
company_details = DefraRuby::CompaniesHouse::API.run(company_number: @transient_registration.company_no)
company_details[:company_name]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class CheckRegisteredCompanyNameForm < ::WasteCarriersEngine::BaseForm
validates :temp_use_registered_company_details, "waste_carriers_engine/yes_no": true

def registered_company_name
companies_house_service.company_name
@registered_company_name ||= companies_house_details[:company_name]
end

def registered_office_address_lines
companies_house_service.registered_office_address_lines
@registered_office_address_lines ||= companies_house_details[:registered_office_address]
end

def submit(params)
Expand All @@ -26,8 +26,8 @@ def submit(params)

private

def companies_house_service
@_companies_house_service ||= DefraRubyCompaniesHouse.new(company_no)
def companies_house_details
@_companies_house_details ||= DefraRuby::CompaniesHouse::API.run(company_number: company_no)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "defra_ruby_companies_house"
require "defra_ruby/companies_house"

module WasteCarriersEngine
# rubocop:disable Metrics/ModuleLength
Expand Down Expand Up @@ -258,9 +258,11 @@ def company_status_invalid?
return false if company_no.blank? || overseas?

begin
company_status = DefraRubyCompaniesHouse.new(company_no).company_status
company_status = DefraRuby::CompaniesHouse::API.run(company_number: company_no)[:company_status]
!%w[active voluntary-arrangement].include?(company_status)
rescue StandardError
rescue StandardError => e
Rails.logger.error "Error checking company status: #{e}"
Airbrake.notify(e)
true
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# frozen_string_literal: true

require "defra_ruby_companies_house"
require "defra_ruby/companies_house"

module WasteCarriersEngine
class RefreshCompaniesHouseNameService < WasteCarriersEngine::BaseService
def run(reg_identifier:)
registration = Registration.find_by(reg_identifier: reg_identifier)

company_name = DefraRubyCompaniesHouse.new(registration.company_no).company_name
registration.registered_company_name = company_name
company_details = DefraRuby::CompaniesHouse::API.run(company_number: registration.company_no)

registration.registered_company_name = company_details[:company_name]
registration.companies_house_updated_at = Time.current
registration.save!

Expand Down
55 changes: 0 additions & 55 deletions lib/defra_ruby_companies_house.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/waste_carriers_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def initialize
end

def companies_house_host=(value)
DefraRuby::Validators.configure do |configuration|
DefraRuby::CompaniesHouse.configure do |configuration|
configuration.companies_house_host = value
end
end

def companies_house_api_key=(value)
DefraRuby::Validators.configure do |configuration|
DefraRuby::CompaniesHouse.configure do |configuration|
configuration.companies_house_api_key = value
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Application < Rails::Application
config.airbrake_key = ENV["WCRS_RENEWALS_AIRBRAKE_PROJECT_KEY"] || "dummy"

# Companies House config
config.companies_house_host = ENV["WCRS_COMPANIES_HOUSE_URL"] || "https://api.companieshouse.gov.uk/company/"
config.companies_house_host = ENV["WCRS_COMPANIES_HOUSE_URL"] || "https://api.companieshouse.gov.uk/"
config.companies_house_api_key = ENV["WCRS_COMPANIES_HOUSE_API_KEY"]

# Paths
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/initializers/waste_carriers_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

WasteCarriersEngine.configure do |config|
# Companies House API config
config.companies_house_host = ENV["WCRS_COMPANIES_HOUSE_URL"] || "https://api.companieshouse.gov.uk/company/"
config.companies_house_host = ENV["WCRS_COMPANIES_HOUSE_URL"] || "https://api.companieshouse.gov.uk/"
config.companies_house_api_key = ENV["WCRS_COMPANIES_HOUSE_API_KEY"]

# Airbrake config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# frozen_string_literal: true

require "rails_helper"
require "defra_ruby_companies_house"
require "defra_ruby/companies_house"

module WasteCarriersEngine
RSpec.describe CheckRegisteredCompanyNameForm do
let(:registered_company_name) { Faker::Company.name }
let(:company_address) { ["10 Downing St", "Horizon House", "Bristol", "BS1 5AH"] }
let(:companies_house_service) { instance_double(DefraRubyCompaniesHouse) }
let(:companies_house_api) { instance_double(DefraRuby::CompaniesHouse::API) }
let(:companies_house_api_response) do
{
company_name: registered_company_name,
registered_office_address: company_address
}
end

before do
allow(DefraRubyCompaniesHouse).to receive(:new).and_return(companies_house_service)
allow(companies_house_service).to receive(:company_name).and_return(registered_company_name)
allow(companies_house_service).to receive(:registered_office_address_lines).and_return(company_address)
allow(DefraRuby::CompaniesHouse::API).to receive(:new).and_return(companies_house_api)
allow(companies_house_api).to receive(:run).and_return(companies_house_api_response)
end

describe "#submit" do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "rails_helper"
require "defra_ruby_companies_house"

module WasteCarriersEngine
RSpec.describe UseTradingNameForm do
Expand Down
Loading

0 comments on commit 951c1fb

Please sign in to comment.