diff --git a/app/presenters/document_collection_presenter.rb b/app/presenters/document_collection_presenter.rb index def96cd3d..79be8e2bb 100644 --- a/app/presenters/document_collection_presenter.rb +++ b/app/presenters/document_collection_presenter.rb @@ -41,7 +41,7 @@ def group_document_links(group, group_index) }, }, metadata: { - public_updated_at: link["public_updated_at"]&.then { |time| Time.zone.parse(time) }, + public_updated_at: group_document_link_public_updated_at(link), document_type: I18n.t( "content_item.schema_name.#{link['document_type']}", count: 1, @@ -69,6 +69,22 @@ def taxonomy_topic_email_override_base_path private + def group_document_link_public_updated_at(link) + disallowed_document_types = %w[answer + completed_transaction + guide + help_page + local_transaction + place + simple_smart_answer + transaction + smart_answer] + + return nil if disallowed_document_types.include?(link["document_type"]) + + link["public_updated_at"]&.then { |time| Time.zone.parse(time) } + end + def group_documents(group) group["documents"].map { |id| documents_hash[id] }.compact end diff --git a/test/presenters/document_collection_presenter_test.rb b/test/presenters/document_collection_presenter_test.rb index bcc6c51db..7251ef175 100644 --- a/test/presenters/document_collection_presenter_test.rb +++ b/test/presenters/document_collection_presenter_test.rb @@ -103,6 +103,34 @@ class PresentedDocumentCollection < TestCase assert_nil grouped.first[:metadata][:public_updated_at] end + + test "it returns nil if specfic document_type is in the disallowed_document_types list" do + schema_data = schema_item + + disallowed_document_types = %w[answer + completed_transaction + guide + help_page + local_transaction + place + simple_smart_answer + transaction + smart_answer] + + disallowed_document_types.each do |document_type| + document = schema_data["links"]["documents"].first + document["document_type"] = document_type + + grouped = present_example(schema_data).group_document_links( + { "documents" => [document["content_id"]] }, + 0, + ) + + public_updated_at = grouped[0][:metadata][:public_updated_at] + + assert_equal nil, public_updated_at + end + end end class GroupWithMissingDocument < TestCase