Skip to content

Commit

Permalink
3631: Refactor Facebook testing (#388)
Browse files Browse the repository at this point in the history
* item tests: split integration and unit tests

* item tests: move integration tests to unit

* item tests: add failed attempt to integration tests

* item tests: update integration tests

- data['html'] started to be returned as an empty string for the first test, which is extra weird since we get it even when the page does not exist

* item tests: clean up

* profile tests: split integration and unit tests

* profile tests: move integration tests to unit

* profile tests: add failed attempt to integration tests

* profile tests: clean up
  • Loading branch information
vasconsaurus authored Sep 19, 2023
1 parent f474ab0 commit 2235899
Show file tree
Hide file tree
Showing 4 changed files with 535 additions and 317 deletions.
60 changes: 60 additions & 0 deletions test/integration/parsers/facebook_item_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require 'test_helper'

class FacebookItemIntegrationTest < ActiveSupport::TestCase
test "should get facebook post with valid data from crowdtangle" do
m = create_media url: 'https://www.facebook.com/144585402276277/posts/1127489833985824'
data = m.as_json

assert_equal 'facebook', data['provider']
assert_equal 'item', data['type']
assert_equal '144585402276277_1127489833985824', data['external_id']
assert data['error'].nil?
assert !data['title'].blank?
assert !data['username'].blank?
assert !data['author_name'].blank?
assert !data['author_picture'].blank?
assert !data['author_url'].blank?
assert !data['description'].blank?
assert !data['text'].blank?
assert !data['picture'].blank?
assert !data['published_at'].blank?
# data['html'] started to be returned as an empty string for this test
# which is extra weird since we get it even when the page does not exist
# will come back to this
# assert !data['html'].blank?
end

test "should get facebook data even if crowdtangle fails" do
m = create_media url: 'https://www.facebook.com/ECRG.TheBigO/posts/pfbid036xece5JjgLH7rD9RnCr1ASnjETq7QThCHiH1HqYAcfUZNHav4gFJdYUY7nGU8JB6l'
data = m.as_json

assert_equal 'facebook', data['provider']
assert_equal 'item', data['type']
assert data['external_id'].blank?
assert data['error'].nil?
assert !data['raw']['crowdtangle']['error'].blank?
assert !data['title'].blank?
assert !data['description'].blank?
assert !data['picture'].blank?
assert !data['html'].blank?
end

test "should return data even if post does not exist" do
m = create_media url: 'https://www.facebook.com/111111111111111/posts/1111111111111111'
data = m.as_json

assert_equal 'facebook', data['provider']
assert_equal 'item', data['type']
assert_equal '111111111111111_1111111111111111', data['external_id']
assert_equal 'https://www.facebook.com/111111111111111/posts/1111111111111111', data['title']
assert !data['raw']['crowdtangle']['error'].blank?
assert_equal '', data['username']
assert_equal '', data['author_name']
assert_equal '', data['author_picture']
assert_equal '', data['author_url']
assert_equal '', data['description']
assert_equal '', data['picture']
assert_equal '', data['published_at']
assert !data['html'].blank?
end
end
48 changes: 48 additions & 0 deletions test/integration/parsers/facebook_profile_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'test_helper'

class FacebookProfileIntegrationTest < ActiveSupport::TestCase
test "should parse Facebook page" do
media = create_media url: 'https://www.facebook.com/ironmaiden/?fref=ts'
data = media.as_json

assert !data['title'].blank?
assert_equal 'ironmaiden', data['username']
assert_equal 'facebook', data['provider']
assert_equal 'profile', data['type']

# Requires login, so cannot fetch ID from HTML
assert data['id'].blank?
assert data['external_id'].blank?
end

test "should parse Facebook page with numeric id" do
media = create_media url: 'https://www.facebook.com/pages/Meedan/105510962816034?fref=ts'
data = media.as_json

assert !data['title'].blank?
assert_equal 'Meedan', data['username']
assert_not_nil data['description']
assert_not_nil data['picture']
assert_not_nil data['published_at']
assert_equal 'facebook', data['provider']
assert_equal 'profile', data['type']

# Parsed from URL
assert_equal '105510962816034', data['id']
assert_equal '105510962816034', data['external_id']
end

test "should return data even if Facebook page does not exist" do
media = create_media url: 'https://www.facebook.com/pages/fakepage/1111111111111'
data = media.as_json

assert_equal 'https://www.facebook.com/pages/fakepage/1111111111111', data['title']
assert_equal 'fakepage', data['username']
assert data['description'].blank?
assert data['picture'].blank?
assert data['published_at'].blank?
assert_equal 'facebook', data['provider']
assert_equal 'profile', data['type']
end
end

Loading

0 comments on commit 2235899

Please sign in to comment.