mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #12299 from mkllnk/social-media-links
Publish full URLs of social media links on DFC API
This commit is contained in:
@@ -12,10 +12,16 @@ class SocialMediaBuilder < DfcBuilder
|
||||
def self.social_media(enterprise, name)
|
||||
return nil unless name.in?(NAMES)
|
||||
|
||||
url = enterprise.attributes[name]
|
||||
url = enterprise.public_send(name)
|
||||
|
||||
return nil if url.blank?
|
||||
|
||||
if name == "instagram"
|
||||
url = "https://www.instagram.com/#{url}/"
|
||||
end
|
||||
|
||||
url = "https://#{url}" unless url.starts_with?(%r{https?://})
|
||||
|
||||
DataFoodConsortium::Connector::SocialMedia.new(
|
||||
urls.enterprise_social_media_url(enterprise.id, name),
|
||||
name:, url:,
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "../spec_helper"
|
||||
|
||||
describe SocialMediaBuilder do
|
||||
let(:enterprise) do
|
||||
create(
|
||||
:enterprise,
|
||||
id: 10_000,
|
||||
|
||||
# These formats are requested by our UI:
|
||||
facebook: "www.facebook.com/user",
|
||||
instagram: "handle",
|
||||
linkedin: "www.linkedin.com/company/name",
|
||||
)
|
||||
end
|
||||
|
||||
describe ".social_media" do
|
||||
it "links to Facebook" do
|
||||
result = SocialMediaBuilder.social_media(enterprise, "facebook")
|
||||
expect(result.url).to eq "https://www.facebook.com/user"
|
||||
end
|
||||
|
||||
it "links to Instagram" do
|
||||
result = SocialMediaBuilder.social_media(enterprise, "instagram")
|
||||
expect(result.url).to eq "https://www.instagram.com/handle/"
|
||||
end
|
||||
|
||||
it "links to Linkedin" do
|
||||
result = SocialMediaBuilder.social_media(enterprise, "linkedin")
|
||||
expect(result.url).to eq "https://www.linkedin.com/company/name"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user