Skip to content

Commit

Permalink
Correctly show facebook embed
Browse files Browse the repository at this point in the history
Change conditions for when fb embed is shown, and add tests to ensure all viable URLs return embeds.
  • Loading branch information
jayjay-w committed Sep 20, 2024
1 parent 4740bf1 commit 945bcb9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
1 change: 0 additions & 1 deletion app/models/parser/facebook_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def parse_data_for_parser(doc, original_url, _jsonld_array)

def html_for_facebook_post(username, html_page, request_url)
return unless html_page
return if username && !['groups', 'flx'].include?(username)
return unless not_an_event_page && not_a_group_post

'<script>
Expand Down
38 changes: 38 additions & 0 deletions test/models/parser/facebook_item_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,4 +485,42 @@ def apify_response_not_found
assert_match /facebook.com/, data['oembed']['provider_url']
assert_equal "facebook", data['oembed']['provider_name'].downcase
end

test "html_for_facebook_post returns expected embed HTML for valid post" do
username = "test_user"
request_url = "https://www.facebook.com/test_user/posts/12345"
html_page = Nokogiri::HTML("<html></html>") # Simulate a valid HTML page

parser = Parser::FacebookItem.new(request_url)

parser.stub(:not_an_event_page, true) do
parser.stub(:not_a_group_post, true) do
embed_html = parser.send(:html_for_facebook_post, username, html_page, request_url)

assert_includes embed_html, '<script>'
assert_includes embed_html, 'FB.init({ xfbml: true, version: "v2.6" });'
assert_includes embed_html, '<div class="fb-post" data-href="https://www.facebook.com/test_user/posts/12345"></div>'
end
end
end

test "html_for_facebook_post returns nil for group or event post" do
username = "test_user"
request_url = "https://www.facebook.com/test_user/posts/12345"
html_page = Nokogiri::HTML("<html></html>") # Simulate a valid HTML page

parser = Parser::FacebookItem.new(request_url)

parser.stub(:not_an_event_page, false) do
embed_html = parser.send(:html_for_facebook_post, username, html_page, request_url)
assert_nil embed_html
end

parser.stub(:not_an_event_page, true) do
parser.stub(:not_a_group_post, false) do
embed_html = parser.send(:html_for_facebook_post, username, html_page, request_url)
assert_nil embed_html
end
end
end
end

0 comments on commit 945bcb9

Please sign in to comment.