Skip to content

Commit 152258b

Browse files
Present social media accounts to publishing API
1 parent 5c90304 commit 152258b

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

app/models/editionable_topical_event.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class EditionableTopicalEvent < Edition
22
include Edition::SocialMediaAccounts
3-
3+
44
def display_type_key
55
"editionable_topical_event"
66
end

app/presenters/publishing_api/editionable_topical_event_presenter.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,22 @@ def links
3535
{}
3636
end
3737

38+
private
39+
3840
def details
39-
{}
41+
{}.tap do |details|
42+
details[:social_media_links] = social_media_links
43+
end
44+
end
45+
46+
def social_media_links
47+
item.social_media_accounts.map do |social_media_account|
48+
{
49+
href: social_media_account.url,
50+
service_type: social_media_account.service_name.parameterize,
51+
title: social_media_account.display_name,
52+
}
53+
end
4054
end
4155
end
4256
end

test/unit/app/presenters/publishing_api/editionable_topical_event_presenter_test.rb

+13-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@ def present(...)
66
end
77

88
test "presents a Topical Event ready for adding to the publishing API" do
9-
topical_event = create(:editionable_topical_event)
9+
topical_event = create(:editionable_topical_event,
10+
:with_social_media_account)
1011

1112
public_path = topical_event.public_path
1213

14+
expected_details = {
15+
social_media_links: [
16+
{
17+
href: topical_event.social_media_accounts.first.url,
18+
service_type: topical_event.social_media_accounts.first.service_name.parameterize,
19+
title: topical_event.social_media_accounts.first.display_name,
20+
},
21+
],
22+
}
23+
1324
expected_hash = {
1425
base_path: public_path,
1526
title: topical_event.title,
@@ -22,7 +33,7 @@ def present(...)
2233
public_updated_at: topical_event.updated_at,
2334
routes: [{ path: public_path, type: "exact" }],
2435
redirects: [],
25-
details: {},
36+
details: expected_details,
2637
update_type: "major",
2738
}
2839

0 commit comments

Comments
 (0)