-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit audit trail: - https://github.com/alphagov/government-frontend/blob/a938e4bee78b794e4e5303a1bde1dfd05e94b287/app/presenters/content_item/metadata.rb - https://github.com/alphagov/government-frontend/blob/a938e4bee78b794e4e5303a1bde1dfd05e94b287/test/presenters/content_item/metadata_test.rb
- Loading branch information
1 parent
9229225
commit 4b79f76
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Metadata | ||
extend ActiveSupport::Concern | ||
|
||
def details_display_date | ||
content_store_hash.dig("details", "display_date") | ||
end | ||
|
||
def pending_stats_announcement? | ||
details_display_date.present? && Time.zone.parse(details_display_date).future? | ||
end | ||
|
||
def publisher_metadata | ||
metadata = { | ||
from:, | ||
first_published: first_published_at, | ||
last_updated: updated, | ||
} | ||
|
||
unless pending_stats_announcement? | ||
metadata[:see_updates_link] = true | ||
end | ||
|
||
metadata | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
class DummyContentItem | ||
include Metadata | ||
attr_accessor :content_item | ||
|
||
def content_store_hash | ||
@content_item | ||
end | ||
|
||
def initialize | ||
@content_item = { | ||
"details" => { | ||
"display_date" => nil, | ||
}, | ||
} | ||
end | ||
end | ||
|
||
RSpec.describe Metadata, type: :model do | ||
let(:item) { DummyContentItem.new } | ||
|
||
describe "#details_display_date" do | ||
it "returns the display date from the content store hash" do | ||
item.content_item["details"]["display_date"] = "2023-10-01" | ||
expect(item.details_display_date).to eq("2023-10-01") | ||
end | ||
end | ||
|
||
describe "#pending_stats_announcement?" do | ||
it "returns true if display date is in the future" do | ||
item.content_item["details"]["display_date"] = (Time.zone.now + 1.day).iso8601 | ||
expect(item.pending_stats_announcement?).to be true | ||
end | ||
end | ||
|
||
describe "#publisher_metadata" do | ||
before do | ||
allow(item).to receive(:from).and_return("from_value") | ||
allow(item).to receive(:first_published_at).and_return("2023-01-01") | ||
allow(item).to receive(:updated).and_return("2023-10-01") | ||
end | ||
|
||
it "includes see_updates_link if not a pending stats announcement" do | ||
item.content_item["details"]["display_date"] = (Time.zone.now - 1.day).iso8601 | ||
expected_metadata = { | ||
from: "from_value", | ||
first_published: "2023-01-01", | ||
last_updated: "2023-10-01", | ||
see_updates_link: true, | ||
} | ||
expect(item.publisher_metadata).to eq(expected_metadata) | ||
end | ||
|
||
it "does not include see_updates_link if a pending stats announcement" do | ||
item.content_item["details"]["display_date"] = (Time.zone.now + 1.day).iso8601 | ||
expected_metadata = { | ||
from: "from_value", | ||
first_published: "2023-01-01", | ||
last_updated: "2023-10-01", | ||
} | ||
expect(item.publisher_metadata).to eq(expected_metadata) | ||
end | ||
end | ||
end |