Skip to content

Commit

Permalink
Merge pull request #3041 from alphagov/misleading-last-updated-date
Browse files Browse the repository at this point in the history
Document collections are showing misleading "last updated" data for mainstream content
  • Loading branch information
georges1996 authored Feb 2, 2024
2 parents 8610965 + 027fc60 commit 53c7a4a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/presenters/document_collection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions test/presenters/document_collection_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 53c7a4a

Please sign in to comment.