Skip to content

Commit

Permalink
Don't show failed translation message for missing document types
Browse files Browse the repository at this point in the history
With the update to Whitehall that allows adding any GOV.UK page to a
document collection there is the potential users could add documents
with types the Government Frontend knows nothing about. For these cases
this will return a nil value rather than raise a failed translation
message.

At this point in time it seems unlikely users would use a document type
that is not known about as the expected usage is Content Publisher
document types. However there is nothing to prevent wider usage of
document types.
  • Loading branch information
kevindew committed Aug 13, 2019
1 parent 5d40d5a commit 0d98a26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/presenters/document_collection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def group_document_links(group, group_index)
},
metadata: {
public_updated_at: Time.zone.parse(link["public_updated_at"]),
document_type: I18n.t("content_item.schema_name.#{link['document_type']}", count: 1)
document_type: I18n.t("content_item.schema_name.#{link['document_type']}",
count: 1,
default: nil),
},
}
end
Expand Down
15 changes: 15 additions & 0 deletions test/presenters/document_collection_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ class PresentedDocumentCollection < TestCase

assert_equal documents, presented_item.group_document_links({ "documents" => [document_ids.first] }, 0)
end

test 'it handles the document type lacking a translation' do
schema_data = schema_item

document = schema_data["links"]["documents"].first.tap do |link|
link["document_type"] = "non-existant"
end

grouped = present_example(schema_data).group_document_links(
{ "documents" => [document["content_id"]] },
0,
)

assert_nil grouped.first[:metadata][:document_type]
end
end

class GroupWithMissingDocument < TestCase
Expand Down

0 comments on commit 0d98a26

Please sign in to comment.