-
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.
move twitter parser integration test to a dedicated folder
We want to separate the integration tests from the unit tests, so that in the future it can be easier for us to choose when we want to run them We want to do this to all parsers
- Loading branch information
1 parent
67a113e
commit 54a5b73
Showing
1 changed file
with
55 additions
and
0 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,55 @@ | ||
require 'test_helper' | ||
|
||
class TwitterItemIntegrationTest < ActiveSupport::TestCase | ||
test "should parse tweet" do | ||
# skip("twitter api key is not currently working") | ||
m = create_media url: 'https://twitter.com/caiosba/status/742779467521773568' | ||
data = m.as_json | ||
assert_match 'I\'ll be talking in @rubyconfbr this year! More details soon...', data['title'] | ||
assert_match 'Caio Almeida', data['author_name'] | ||
assert_match '@caiosba', data['username'] | ||
assert_nil data['picture'] | ||
assert_not_nil data['author_picture'] | ||
end | ||
|
||
test "should parse valid link with spaces" do | ||
# skip("twitter api key is not currently working") | ||
m = create_media url: ' https://twitter.com/caiosba/status/742779467521773568 ' | ||
data = m.as_json | ||
assert_match 'I\'ll be talking in @rubyconfbr this year! More details soon...', data['title'] | ||
assert_match 'Caio Almeida', data['author_name'] | ||
assert_match '@caiosba', data['username'] | ||
assert_nil data['picture'] | ||
assert_not_nil data['author_picture'] | ||
end | ||
|
||
test "should fill in html when html parsing fails but API works" do | ||
# skip("twitter api key is not currently working") | ||
url = 'https://twitter.com/codinghorror/status/1276934067015974912' | ||
OpenURI.stubs(:open_uri).raises(OpenURI::HTTPError.new('','429 Too Many Requests')) | ||
m = create_media url: url | ||
data = m.as_json | ||
assert_match /twitter-tweet.*#{url}/, data[:html] | ||
end | ||
|
||
test "should not parse a twitter post when passing the twitter api bearer token is missing" do | ||
# skip("this might be broke befcause of twitter api changes - needs fixing") | ||
key = create_api_key application_settings: { config: { twitter_bearer_token: '' } } | ||
m = create_media url: 'https://twitter.com/cal_fire/status/919029734847025152', key: key | ||
assert_equal '', PenderConfig.get(:twitter_bearer_token) | ||
data = m.as_json | ||
assert_equal m.url, data['title'] | ||
assert_match "401 Unauthorized", data['error']['message'] | ||
end | ||
|
||
test "should store oembed data of a twitter profile" do | ||
# skip("twitter api key is not currently working") | ||
m = create_media url: 'https://twitter.com/meedan' | ||
data = m.as_json | ||
|
||
assert data['raw']['oembed'].is_a? Hash | ||
assert_equal "https:\/\/twitter.com", data['raw']['oembed']['provider_url'] | ||
assert_equal "Twitter", data['raw']['oembed']['provider_name'] | ||
end | ||
end | ||
|