-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3631: Refactor Facebook testing (#388)
* 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
1 parent
f474ab0
commit 2235899
Showing
4 changed files
with
535 additions
and
317 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,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 |
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,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 | ||
|
Oops, something went wrong.