Skip to content

Commit

Permalink
Merge pull request #1171 from alphagov/rescue-missing-content-items
Browse files Browse the repository at this point in the history
Handle items that are in search but not content-store gracefully
  • Loading branch information
KludgeKML authored Sep 5, 2024
2 parents d0e5c4a + c97afff commit 1a23671
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/services/govuk_site_lookup_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def public_url_info
ci = content_store_api.content_item(pp["link"])
slug = ci["details"]["place_type"]
hash[slug] = { link: Plek.website_root + pp["link"], title: pp["title"] }
rescue GdsApi::HTTPNotFound => e
Rails.logger.warn("Search result for place does not exist in content store: #{e}")
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion spec/services/govuk_site_lookup_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require "rails_helper"

RSpec.describe(GovukSiteLookupService, type: :model) do
let(:search_results) { { results: [{ title: "Test Service", link: "/test-service-page" }] } }

before do
search_results = { results: [{ title: "Test Service", link: "/test-service-page" }] }
stub_request(:get, "http://search-api.dev.gov.uk/search.json?count=200&fields=title,link&filter_format=place").to_return(status: 200, body: search_results.to_json, headers: {})
content_item = { details: { place_type: "test-service" } }
stub_request(:get, "http://content-store.dev.gov.uk/content/test-service-page").to_return(status: 200, body: content_item.to_json, headers: {})
stub_request(:get, "http://content-store.dev.gov.uk/content/foooo").to_return(status: 404, body: "", headers: {})
end

describe "#govuk_page?" do
Expand All @@ -29,4 +31,12 @@
expect(GovukSiteLookupService.new.page_title("test-service")).to(eq("Test Service"))
end
end

context "with items that are in search but missing from content-store" do
let(:search_results) { { results: [{ title: "foo", link: "/foooo" }, { title: "Test Service", link: "/test-service-page" }] } }

it "returns title of frontend page, ignoring the broken item" do
expect(GovukSiteLookupService.new.page_title("test-service")).to(eq("Test Service"))
end
end
end

0 comments on commit 1a23671

Please sign in to comment.