Skip to content

Commit

Permalink
Renable test/contracts/govuk_content_schemas_test.rb
Browse files Browse the repository at this point in the history
There was a typo in the support file, such that
GovukSchemas::Example.find_all(supported_schemas) was returning []
because the `find_all` method expects a single string param.
https://github.com/alphagov/govuk_schemas/blob/4fef0aa95be24c3534a00b622a59ea7f1e8175fa/lib/govuk_schemas/example.rb#L5

Also removes redirect, as there is no frontend rendering.
https://github.com/alphagov/publishing-api/tree/main/content_schemas/examples/redirect

Minitest won't not run tests of the same name, and multiple schema examples have
the same basepath. Hence adding in the index to the iterator.
  • Loading branch information
hannako committed Jan 17, 2023
1 parent 8a69e71 commit f4a41c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions test/contracts/govuk_content_schemas_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
class GovukContentSchemasTest < ActionDispatch::IntegrationTest
include GovukContentSchemaExamples

all_examples_for_supported_schemas.each do |content_item|
test "can successfully render #{content_item['base_path']} schema example" do
all_examples_for_supported_schemas.each_with_index do |content_item, index|
test "can successfully render #{content_item['document_type']} #{index} example" do
stub_content_store_has_item(content_item["base_path"], content_item)
stub_parent_breadcrumbs(content_item, content_item["document_type"])

get content_item["base_path"]

Expand Down
10 changes: 8 additions & 2 deletions test/support/govuk_content_schema_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,23 @@ def govuk_content_schema_example(schema_name, example_name)
GovukSchemas::Example.find(schema_name, example_name:)
end

def stub_parent_breadcrumbs(document, schema)
parents = document.dig("links", "parent")
return if parents.nil?

stub_content_store_has_item(parents.first["base_path"], document) if schema == "html_publication"
end

module ClassMethods
def all_examples_for_supported_schemas
GovukSchemas::Example.find_all(supported_schemas)
supported_schemas.flat_map { |format| GovukSchemas::Example.find_all(format) }
end

def supported_schemas
%w[
case_study
coming_soon
html_publication
redirect
statistics_announcement
take_part
topical_event_about_page
Expand Down

0 comments on commit f4a41c3

Please sign in to comment.