From 696841643ca07fc1c1193c4b13e3138462d1a5f6 Mon Sep 17 00:00:00 2001 From: BeckaL Date: Fri, 23 Jun 2023 14:18:49 +0100 Subject: [PATCH] Remove code relating to publishing special routes These have now all been moved into special routes publisher. The code to publish these is therefore now redundant and can be removed. --- lib/homepage_publisher.rb | 42 ------------- lib/special_route_publisher.rb | 73 ----------------------- lib/tasks/publishing_api.rake | 18 ------ test/unit/homepage_publisher_test.rb | 41 ------------- test/unit/special_route_publisher_test.rb | 42 ------------- 5 files changed, 216 deletions(-) delete mode 100644 lib/homepage_publisher.rb delete mode 100644 lib/special_route_publisher.rb delete mode 100644 test/unit/homepage_publisher_test.rb delete mode 100644 test/unit/special_route_publisher_test.rb diff --git a/lib/homepage_publisher.rb b/lib/homepage_publisher.rb deleted file mode 100644 index 713a140d45..0000000000 --- a/lib/homepage_publisher.rb +++ /dev/null @@ -1,42 +0,0 @@ -module HomepagePublisher - CONTENT_ID = "f3bbdec2-0e62-4520-a7fd-6ffd5d36e03a".freeze - GDS_ORGANISATION_CONTENT_ID = "af07d5a5-df63-4ddc-9383-6a666845ebe9".freeze - - def self.homepage_content_item - { - "base_path": "/", - "document_type": "homepage", - "schema_name": "homepage", - "title": "GOV.UK homepage", - "description": "", - "locale": "en", - "details": {}, - "routes": [ - { - "path": "/", - "type": "exact", - }, - ], - "publishing_app": "frontend", - "rendering_app": "frontend", - "public_updated_at": Time.zone.now.iso8601, - "update_type": "major", - } - end - - def self.links - { - links: { - "organisations" => [GDS_ORGANISATION_CONTENT_ID], - "primary_publishing_organisation" => [GDS_ORGANISATION_CONTENT_ID], - }, - } - end - - def self.publish!(publishing_api, logger) - logger.info("Publishing exact route /, routing to frontend") - publishing_api.put_content(CONTENT_ID, homepage_content_item) - publishing_api.publish(CONTENT_ID) - publishing_api.patch_links(CONTENT_ID, links) - end -end diff --git a/lib/special_route_publisher.rb b/lib/special_route_publisher.rb deleted file mode 100644 index 1ac6da0df8..0000000000 --- a/lib/special_route_publisher.rb +++ /dev/null @@ -1,73 +0,0 @@ -require "gds_api/publishing_api/special_route_publisher" - -class SpecialRoutePublisher - def initialize(publisher_options) - @publisher = GdsApi::PublishingApi::SpecialRoutePublisher.new(publisher_options) - end - - def publish(route_type, route) - @publisher.publish( - route.merge( - format: "special_route", - publishing_app: "frontend", - rendering_app: "frontend", - type: route_type, - public_updated_at: Time.zone.now.iso8601, - update_type: "major", - ), - ) - end - - def self.routes - { - exact: [ - { - content_id: "caf90fb7-11e3-4f8e-9a5d-b83283c91533", - base_path: "/tour", - title: "GOV.UK introductory page", - description: "A description of the various sections of GOV.UK and their uses.", - }, - { - content_id: "3c7060f7-9efa-47be-bd36-0326f3fa4f04", - base_path: "/help", - title: "Help using GOV.UK", - description: "Find out about GOV.UK, including the use of cookies, accessibility of the site, the privacy notice and terms and conditions of use.", - links: { - ordered_related_items: %w[58b05bc2-fde5-4a0b-af73-8edc532674f8], # /contact - }, - }, - { - content_id: "a4d4e755-3d75-4b19-b120-a638a6d79ba8", - base_path: "/help/ab-testing", - title: "A/B testing on GOV.UK", - description: "This page is being used internally by GOV.UK to make sure A/B testing works.", - }, - { - content_id: "220f39ad-d4ad-4b0c-9d40-6c417a1341c0", - base_path: "/help/cookies", - title: "Cookies on GOV.UK", - description: "You can choose which cookies you're happy for GOV.UK to use.", - }, - { - content_id: "3c991cea-cdee-4e58-b8d1-d38e7c0e6327", - base_path: "/random", - title: "GOV.UK random page", - }, - { - content_id: "9a86495d-663f-46f8-b4ce-fc9153579338", - base_path: "/roadmap", - title: "GOV.UK Roadmap", - description: "This is GOV.UK's current roadmap. We plan to update it again in the new financial year.", - }, - ], - prefix: [ - { - content_id: "622fda2b-5fa6-4c84-bc3b-22cd3ff08828", - base_path: "/find-local-council", - title: "Find your local council", - description: "Find your local authority in England, Wales, Scotland and Northern Ireland", - }, - ], - } - end -end diff --git a/lib/tasks/publishing_api.rake b/lib/tasks/publishing_api.rake index ecdcccf381..b68ff1de7a 100644 --- a/lib/tasks/publishing_api.rake +++ b/lib/tasks/publishing_api.rake @@ -1,22 +1,4 @@ namespace :publishing_api do - desc "Publish special routes such as the homepage" - task publish_special_routes: :environment do - logger = Logger.new($stdout) - - publisher = SpecialRoutePublisher.new( - logger:, - publishing_api: GdsApi.publishing_api, - ) - - SpecialRoutePublisher.routes.each do |route_type, routes_for_type| - routes_for_type.each do |route| - publisher.publish(route_type, route) - end - end - - HomepagePublisher.publish!(GdsApi.publishing_api, logger) - end - desc "Publish calendars" task publish_calendars: :environment do %w[bank-holidays when-do-the-clocks-change].each do |calender_name| diff --git a/test/unit/homepage_publisher_test.rb b/test/unit/homepage_publisher_test.rb deleted file mode 100644 index 7cb1f4a00a..0000000000 --- a/test/unit/homepage_publisher_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require "test_helper" -require "govuk_schemas/assert_matchers" - -class HomepagePublisherTest < ActiveSupport::TestCase - include GovukSchemas::AssertMatchers - - test ".publish! works without errors" do - # TODO: add test helpers to govuk_schemas and use that - content_request = stub_request(:put, "http://publishing-api.dev.gov.uk/v2/content/f3bbdec2-0e62-4520-a7fd-6ffd5d36e03a") - .to_return(status: 200) - publish_request = stub_request(:post, "http://publishing-api.dev.gov.uk/v2/content/f3bbdec2-0e62-4520-a7fd-6ffd5d36e03a/publish") - .to_return(status: 200) - patch_links_request = stub_request(:patch, "http://publishing-api.dev.gov.uk/v2/links/f3bbdec2-0e62-4520-a7fd-6ffd5d36e03a") - .to_return(status: 200) - - stub_api = GdsApi::PublishingApi.new(Plek.find("publishing-api")) - - mock_logger = mock - mock_logger.expects(:info).returns("Publishing exact route /, routing to frontend") - - HomepagePublisher.publish!(stub_api, mock_logger) - - assert_requested( - content_request.with do |req| - assert_valid_against_publisher_schema(JSON.parse(req.body), "homepage") - end, - ) - - assert_requested(publish_request) - - expected_links = { - "organisations" => %w[af07d5a5-df63-4ddc-9383-6a666845ebe9], - "primary_publishing_organisation" => %w[af07d5a5-df63-4ddc-9383-6a666845ebe9], - } - assert_requested( - patch_links_request.with do |req| - assert_equal expected_links, JSON.parse(req.body)["links"] - end, - ) - end -end diff --git a/test/unit/special_route_publisher_test.rb b/test/unit/special_route_publisher_test.rb deleted file mode 100644 index 01e4d338e2..0000000000 --- a/test/unit/special_route_publisher_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require "test_helper" - -class SpecialRoutePublisherTest < ActiveSupport::TestCase - setup do - @publishing_api = Object.new - - logger = Logger.new($stdout) - logger.level = Logger::WARN - - @publisher = SpecialRoutePublisher.new( - publishing_api: @publishing_api, - logger:, - ) - end - - SpecialRoutePublisher.routes.each do |route_type, routes_for_type| - routes_for_type.each do |route| - should "should publish valid content item for #{route_type} route '#{route[:base_path]}'" do - @publishing_api.expects(:put_content).with do |_, payload| - assert_valid_content_item(payload) - end - @publishing_api.expects(:publish) - - if route[:links] - @publishing_api.expects(:patch_links) - end - - @publisher.publish(route_type, route) - end - end - end - - def assert_valid_content_item(payload) - validator = GovukSchemas::Validator.new( - "special_route", - "publisher", - payload, - ) - - assert validator.valid?, validator.error_message - end -end