From 7cc6f110866324a5a9d5412285b756aca8c806ef Mon Sep 17 00:00:00 2001 From: Keith Lawrence Date: Thu, 30 May 2024 15:11:18 +0100 Subject: [PATCH] Remove unused files (and their unit tests) --- lib/assisted_digital_satisfaction_survey.rb | 11 -- lib/dictionary_presenter.rb | 15 -- lib/local_authority_slug_finder.rb | 42 ---- lib/local_transaction_location_identifier.rb | 60 ------ test/unit/local_authority_slug_finder_test.rb | 184 ------------------ ...al_transaction_location_identifier_test.rb | 113 ----------- 6 files changed, 425 deletions(-) delete mode 100644 lib/assisted_digital_satisfaction_survey.rb delete mode 100644 lib/dictionary_presenter.rb delete mode 100644 lib/local_authority_slug_finder.rb delete mode 100644 lib/local_transaction_location_identifier.rb delete mode 100644 test/unit/local_authority_slug_finder_test.rb delete mode 100644 test/unit/local_transaction_location_identifier_test.rb diff --git a/lib/assisted_digital_satisfaction_survey.rb b/lib/assisted_digital_satisfaction_survey.rb deleted file mode 100644 index 31420dfbd8..0000000000 --- a/lib/assisted_digital_satisfaction_survey.rb +++ /dev/null @@ -1,11 +0,0 @@ -module AssistedDigitalSatisfactionSurvey - SLUGS_IN_SURVEY = [ - "done/register-flood-risk-exemption", - "done/waste-carrier-or-broker-registration", - "done/register-waste-exemption", - ].freeze - - def self.show_survey?(slug) - SLUGS_IN_SURVEY.include? slug - end -end diff --git a/lib/dictionary_presenter.rb b/lib/dictionary_presenter.rb deleted file mode 100644 index 83ac5d174f..0000000000 --- a/lib/dictionary_presenter.rb +++ /dev/null @@ -1,15 +0,0 @@ -class DictionaryPresenter - def initialize(collection) - @collection = collection - end - - def as_dictionary - dictionary = ("A".."Z").index_with { |_l| [] } - - @collection.each do |p| - dictionary[p.title[0]] << p - end - - dictionary - end -end diff --git a/lib/local_authority_slug_finder.rb b/lib/local_authority_slug_finder.rb deleted file mode 100644 index 05aaa67846..0000000000 --- a/lib/local_authority_slug_finder.rb +++ /dev/null @@ -1,42 +0,0 @@ -class LocalAuthoritySlugFinder - AUTHORITY_TYPES = %w[DIS LBO UTA CTY LGD MTD COI].freeze - COUNTY_LOCAL_AUTHORITY_TYPE = "CTY".freeze - - def self.call(areas, county_requested: false) - new(areas, county_requested).find_slug - end - - def initialize(areas, county_requested) - @areas = areas - @county_requested = county_requested - end - - def find_slug - if county_requested && county_local_authority_with_slug - county_local_authority_with_slug["codes"]["govuk_slug"] - else - matching_authority_by_area_type_slug - end - end - -private - - attr_reader :areas, :county_requested - - def county_local_authority_with_slug - areas.detect { |a| a["type"] == COUNTY_LOCAL_AUTHORITY_TYPE && area_has_slug?(a) } - end - - def matching_authority_by_area_type_slug - AUTHORITY_TYPES.each do |type| - areas.each do |area| - return area["codes"]["govuk_slug"] if area["type"] == type && area_has_slug?(area) - end - end - nil - end - - def area_has_slug?(area) - area.try(:[], "codes").try(:[], "govuk_slug").present? - end -end diff --git a/lib/local_transaction_location_identifier.rb b/lib/local_transaction_location_identifier.rb deleted file mode 100644 index 2c4eb1d18f..0000000000 --- a/lib/local_transaction_location_identifier.rb +++ /dev/null @@ -1,60 +0,0 @@ -class LocalTransactionLocationIdentifier - def self.find_slug(areas, content_item, tier_override = nil) - new(areas, content_item, tier_override).find_slug - end - - def self.find_country(areas, content_item, tier_override = nil) - new(areas, content_item, tier_override).find_country - end - - attr_reader :areas, :content_item, :tier_override - - def initialize(areas, content_item, tier_override = nil) - @areas = areas - @content_item = content_item - @tier_override = tier_override - end - - def find_slug - matching_authority_by_tier_slug - end - - def find_country - matching_country_by_tier_slug - end - -private - - def matching_authority_by_tier_slug - matching_authority_by_tier.try(:[], "codes").try(:[], "govuk_slug") - end - - def matching_country_by_tier_slug - matching_authority_by_tier.try(:[], "country_name") - end - - def matching_authority_by_tier - return nil unless service_providing_tiers - - service_providing_tiers.each do |tier| - areas.each do |area| - return area if tier == identify_tier(area["type"]) - end - end - nil - end - - def identify_tier(type) - case type - when "DIS" then "district" - when "CTY" then "county" - when "LBO", "LGD", "MTD", "UTA", "COI" then "unitary" - end - end - - def service_providing_tiers - return unless content_item - - content_item["details"].try(:[], "service_tiers") - end -end diff --git a/test/unit/local_authority_slug_finder_test.rb b/test/unit/local_authority_slug_finder_test.rb deleted file mode 100644 index a48303fc44..0000000000 --- a/test/unit/local_authority_slug_finder_test.rb +++ /dev/null @@ -1,184 +0,0 @@ -require "test_helper" -require "local_authority_slug_finder" - -class LocalAuthoritySlugFinderTest < ActiveSupport::TestCase - setup do - @lancashire_county_council = { - "name" => "Lancashire County Council", - "type" => "CTY", - "codes" => { - "govuk_slug" => "lancashire-county-council", - }, - } - - @south_ribble_borough_council = { - "name" => "South Ribble Borough Council", - "type" => "DIS", - "codes" => { - "govuk_slug" => "south-ribble-borough-council", - }, - } - - @aylesbury_district_without_slug = { - "name" => "Aylesbury District", - "type" => "DIS", - } - - @shropshire_unitary_authority = { - "name" => "Shropshire Council", - "type" => "UTA", - "codes" => { - "govuk_slug" => "shropshire-council", - }, - } - - @belfast_council = { - "name" => "Belfast Council", - "type" => "LGD", - "codes" => { - "govuk_slug" => "belfast-council", - }, - } - - @sunderland_council = { - "name" => "Sunderland Council", - "type" => "MTD", - "codes" => { - "govuk_slug" => "sunderland-council", - }, - } - - @scilly_council = { - "name" => "Scilly Council", - "type" => "COI", - "codes" => { - "govuk_slug" => "scilly-council", - }, - } - - @islington_council = { - "name" => "Islington Council", - "type" => "LBO", - "codes" => { - "govuk_slug" => "islington-council", - }, - } - - @south_ribble_parliamentary_constituency = { - "name" => "South Ribble", - "type" => "WMC", - } - - @shrewsbury_civil_parish = { - "name" => "Shrewsbury_civil_parish", - "type" => "CPC", - } - - @leyland_county_ward = { - "name" => "Leyland South West", - "type" => "CED", - } - end - - context "for single tier lookup" do - context "for London Borough (LBO)" do - should "return the slug of the London Borough" do - areas = [@islington_council] - - slug = LocalAuthoritySlugFinder.call(areas) - assert_equal "islington-council", slug - end - end - - context "for Unitary Authority (UTA)" do - should "return the slug of the Unitary Authority" do - areas = [@shropshire_unitary_authority] - - slug = LocalAuthoritySlugFinder.call(areas) - assert_equal "shropshire-council", slug - end - end - - context "for Northern Ireland Council (LGD)" do - should "return the slug of the Northern Ireland Council" do - areas = [@belfast_council] - - slug = LocalAuthoritySlugFinder.call(areas) - assert_equal "belfast-council", slug - end - end - - context "for Metropolitan District (MTD)" do - should "return the slug of the Metropolitan District" do - areas = [@sunderland_council] - - slug = LocalAuthoritySlugFinder.call(areas) - assert_equal "sunderland-council", slug - end - end - - context "for Isles of Scilly (COI)" do - should "return the slug of the Isles of Scilly Council" do - areas = [@scilly_council] - - slug = LocalAuthoritySlugFinder.call(areas) - assert_equal "scilly-council", slug - end - end - - context "with other area type look ups" do - context "with valid area present" do - should "ignore other area types and return valid area slug" do - areas = [@south_ribble_borough_council, @south_ribble_parliamentary_constituency] - - slug = LocalAuthoritySlugFinder.call(areas) - assert_equal "south-ribble-borough-council", slug - end - end - - context "with only invalid areas present" do - should "return nil" do - areas = [@shrewsbury_civil_parish, @south_ribble_parliamentary_constituency] - - slug = LocalAuthoritySlugFinder.call(areas) - assert_nil slug - end - end - end - end - - context "for district (DIS)/county (CTY) tier lookup" do - setup do - @areas = [ - @south_ribble_borough_council, - @lancashire_county_council, - ] - end - - should "return District slug by default" do - slug = LocalAuthoritySlugFinder.call(@areas) - assert_equal "south-ribble-borough-council", slug - end - - should "return County slug if requested" do - slug = LocalAuthoritySlugFinder.call(@areas, county_requested: true) - assert_equal "lancashire-county-council", slug - end - end - - context "with areas missing govuk_slug" do - should "return nil" do - @areas = [@aylesbury_district_without_slug] - - slug = LocalAuthoritySlugFinder.call(@areas) - assert_nil slug - end - end - - context "with no areas present" do - should "return nil" do - slug = LocalAuthoritySlugFinder.call([]) - assert_nil slug - end - end -end diff --git a/test/unit/local_transaction_location_identifier_test.rb b/test/unit/local_transaction_location_identifier_test.rb deleted file mode 100644 index 1e52ab4c86..0000000000 --- a/test/unit/local_transaction_location_identifier_test.rb +++ /dev/null @@ -1,113 +0,0 @@ -require "test_helper" -require "local_transaction_location_identifier" - -class LocalTransactionLocationIdentifierTest < ActiveSupport::TestCase - setup do - @lancashire_county_council = { - "name" => "Lancashire County Council", - "type" => "CTY", - "codes" => { - "govuk_slug" => "lancashire-county-council", - }, - } - - @south_ribble_borough_council = { - "name" => "South Ribble Borough Council", - "type" => "DIS", - "codes" => { - "govuk_slug" => "south-ribble-borough-council", - }, - } - - @leyland_county_ward = { - "name" => "Leyland South West", - "type" => "CED", - } - - @south_ribble_parliamentary_constituency = { - "name" => "South Ribble", - "type" => "WMC", - } - - @shropshire_unitary_authority = { - "name" => "Shropshire Council", - "type" => "UTA", - "codes" => { - "govuk_slug" => "shropshire-council", - }, - } - - @shrewsbury_civil_parish = { - "name" => "Shrewsbury_civil_parish", - "type" => "CPC", - } - end - - context "given an content item exists with a local service for the district/unitary tiers" do - setup do - @content_item = { "details" => { "service_tiers" => %w[district county] } } - end - - should "select the correct tier authority from areas providing a district and county" do - areas = [ - @lancashire_county_council, - @south_ribble_borough_council, - @leyland_county_ward, - @south_ribble_parliamentary_constituency, - ] - slug = LocalTransactionLocationIdentifier.find_slug(areas, @content_item) - - assert_equal "south-ribble-borough-council", slug - end - - should "return nil if no authorities match" do - areas = [@leyland_county_ward, @south_ribble_parliamentary_constituency] - slug = LocalTransactionLocationIdentifier.find_slug(areas, @content_item) - - assert_nil slug - end - end - - context "given an content item exists with a local service for the county/unitary tiers" do - setup do - @content_item = { "details" => { "service_tiers" => %w[county unitary] } } - end - - should "select the correct tier authority from areas providing a district and county" do - areas = [ - @lancashire_county_council, - @south_ribble_borough_council, - @leyland_county_ward, - @south_ribble_parliamentary_constituency, - ] - slug = LocalTransactionLocationIdentifier.find_slug(areas, @content_item) - - assert_equal "lancashire-county-council", slug - end - - should "select the correct tier authority from areas providing a unitary authority" do - areas = [@shropshire_unitary_authority, @shrewsbury_civil_parish] - slug = LocalTransactionLocationIdentifier.find_slug(areas, @content_item) - - assert_equal "shropshire-council", slug - end - end - - context "given an content item exists with a local service for all tiers" do - setup do - @content_item = { "details" => { "service_tiers" => %w[district unitary county] } } - end - - should "select the correct tier authority from areas providing a district and county" do - areas = [ - @lancashire_county_council, - @south_ribble_borough_council, - @leyland_county_ward, - @south_ribble_parliamentary_constituency, - ] - slug = LocalTransactionLocationIdentifier.find_slug(areas, @content_item) - - assert_equal "south-ribble-borough-council", slug - end - end -end