Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document collections are showing misleading "last updated" data for mainstream content #3041

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
georges1996 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading