Skip to content

Commit

Permalink
Merge pull request #3486 from alphagov/remove-schema-example-usage
Browse files Browse the repository at this point in the history
Using RandomExample generator from GovUK Schemas
  • Loading branch information
minhngocd authored Oct 3, 2024
2 parents 934adf1 + 2049df4 commit 8b09a4c
Show file tree
Hide file tree
Showing 5 changed files with 545 additions and 39 deletions.
24 changes: 11 additions & 13 deletions features/support/document_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ def stub_world_locations_api_request
end

def content_store_has_mosw_reports_finder
stub_content_store_has_item("/mosw-reports", govuk_content_schema_example("finder").to_json)
stub_content_store_has_item("/mosw-reports", example_finder.to_json)
end

def content_store_has_mosw_reports_finder_with_no_facets
finder = govuk_content_schema_example("finder")
finder = example_finder
finder["details"]["facets"] = []
stub_content_store_has_item("/mosw-reports", finder.to_json)
end
Expand All @@ -262,7 +262,7 @@ def content_store_has_news_and_communications_finder

def content_store_has_government_finder
base_path = "/government/policies/benefits-reform"
finder = govuk_content_schema_example("finder").merge("base_path" => base_path)
finder = example_finder.merge("base_path" => base_path)
finder["details"]["sort"] = [
{
"name": "Most viewed",
Expand All @@ -286,7 +286,7 @@ def content_store_has_services_finder

def content_store_has_government_finder_with_10_items
base_path = "/government/policies/benefits-reform"
content_item = govuk_content_schema_example("finder").merge("base_path" => base_path)
content_item = example_finder.merge("base_path" => base_path)
content_item["details"]["default_documents_per_page"] = 10
stub_content_store_has_item(base_path, content_item.to_json)
end
Expand Down Expand Up @@ -322,7 +322,7 @@ def search_params(params = {})
end

def stub_content_store_with_cma_cases_finder
schema = govuk_content_schema_example("cma-cases", "finder")
schema = example_cma_cases_finder

stub_content_store_has_item(
schema.fetch("base_path"),
Expand All @@ -331,7 +331,7 @@ def stub_content_store_with_cma_cases_finder
end

def stub_content_store_with_a_taxon_tagged_finder
schema = govuk_content_schema_example("cma-cases", "finder").merge(
schema = example_cma_cases_finder.merge(
"links" => {
"taxons" => [
{
Expand Down Expand Up @@ -372,7 +372,7 @@ def stub_rummager_with_cma_cases
end

def stub_content_store_with_cma_cases_finder_with_description
schema = govuk_content_schema_example("cma-cases", "finder")
schema = example_cma_cases_finder
.merge("description" => "Find reports and updates on current and historical CMA investigations")

stub_content_store_has_item(
Expand All @@ -382,7 +382,7 @@ def stub_content_store_with_cma_cases_finder_with_description
end

def stub_content_store_with_cma_cases_finder_with_no_index
schema = govuk_content_schema_example("cma-cases", "finder")
schema = example_cma_cases_finder
schema["details"]["no_index"] = true

stub_content_store_has_item(
Expand All @@ -392,8 +392,7 @@ def stub_content_store_with_cma_cases_finder_with_no_index
end

def stub_content_store_with_cma_cases_finder_with_metadata
schema = govuk_content_schema_example("cma-cases", "finder")
.merge("from" => "An authority")
schema = example_cma_cases_finder.merge("from" => "An authority")

stub_content_store_has_item(
schema.fetch("base_path"),
Expand All @@ -402,8 +401,7 @@ def stub_content_store_with_cma_cases_finder_with_metadata
end

def stub_content_store_with_cma_cases_finder_with_metadata_with_topic_param
schema = govuk_content_schema_example("cma-cases", "finder")
.merge("from" => "An authority")
schema = example_cma_cases_finder.merge("from" => "An authority")
schema["content_id"] = "c58fdadd-7743-46d6-9629-90bb3ccc4ef0"

stub_content_store_has_item(
Expand All @@ -413,7 +411,7 @@ def stub_content_store_with_cma_cases_finder_with_metadata_with_topic_param
end

def stub_content_store_with_cma_cases_finder_for_supergroup_checkbox_filter
schema = govuk_content_schema_example("cma-cases", "finder")
schema = example_cma_cases_finder
schema["details"]["facets"].map! do |facet|
if facet["key"] == "case_state"
{
Expand Down
34 changes: 13 additions & 21 deletions spec/controllers/finders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,18 @@
render_views

let(:lunch_finder) do
finder = govuk_content_schema_example("finder").to_hash.merge(
"title" => "Lunch Finder",
"base_path" => "/lunch-finder",
)

finder = example_finder
finder["title"] = "Lunch Finder"
finder["base_path"] = "/lunch-finder"
finder["details"]["default_documents_per_page"] = 10
finder["details"]["sort"] = nil
finder
end

let(:all_content_finder) do
finder = govuk_content_schema_example("finder").to_hash.merge(
"base_path" => "/search/all",
"content_id" => "dd395436-9b40-41f3-8157-740a453ac972",
)

finder = example_finder
finder["base_path"] = "/search/all"
finder["content_id"] = "dd395436-9b40-41f3-8157-740a453ac972"
finder["details"]["default_documents_per_page"] = 10
finder["details"]["sort"] = nil
finder
Expand Down Expand Up @@ -300,12 +296,10 @@

describe "Spelling suggestions" do
let(:breakfast_finder) do
finder = govuk_content_schema_example("finder").to_hash.merge(
"title" => "Breakfast Finder",
"base_path" => "/breakfast-finder",
"content_id" => "42ce66de-04f3-4192-bf31-8394538e0734",
)

finder = example_finder
finder["title"] = "Breakfast Finder"
finder["base_path"] = "/breakfast-finder"
finder["content_id"] = "42ce66de-04f3-4192-bf31-8394538e0734"
finder["details"]["default_documents_per_page"] = 10
finder["details"]["sort"] = nil
finder
Expand Down Expand Up @@ -371,11 +365,9 @@
before do
search_api_request

news_finder = govuk_content_schema_example("finder").to_hash.merge(
"base_path" => "/search/news-and-communications",
"content_id" => "622e9691-4b4f-4e9c-bce1-098b0c4f5ee2",
)

news_finder = example_finder
news_finder["base_path"] = "/search/news-and-communications"
news_finder["content_id"] = "622e9691-4b4f-4e9c-bce1-098b0c4f5ee2"
news_finder["details"]["default_documents_per_page"] = 10
news_finder["details"]["sort"] = nil

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/facets_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
end

let(:content_item_hash) do
govuk_content_schema_example("finder").merge(detail_hash).deep_stringify_keys
example_finder.merge(detail_hash).deep_stringify_keys
end

let(:content_item) do
Expand Down
2 changes: 1 addition & 1 deletion spec/presenters/sort_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
private

def content_item(sort_options: nil)
finder_example = govuk_content_schema_example("finder")
finder_example = example_finder
finder_example["details"]["sort"] = sort_options
ContentItem.new(finder_example)
end
Expand Down
Loading

0 comments on commit 8b09a4c

Please sign in to comment.