Skip to content

Commit

Permalink
3019 - add safe operator to avoid NoMethodError (kwai) (#364)
Browse files Browse the repository at this point in the history
* add safe operator

* removed test that checks for NoMethodError

This test only worked when the two selectors we look for don't exist,
but sometimes a link might not have those specific selectors and still
have relevant information to be returned.

By adding a safe operator we are not getting the NoMethodError anymore,
and are returning relevant data. But this test stops making sense.
We thought about adding tests to specific links or errors, but in the end
we think those are not necessary.
  • Loading branch information
vasconsaurus authored Jul 19, 2023
1 parent e82abb4 commit 3bef6c0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
2 changes: 1 addition & 1 deletion app/models/parser/kwai_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def parse_data_for_parser(doc, _original_url, _jsonld_array)
end

def get_kwai_text_from_tag(doc, selector)
doc&.at_css(selector)&.text&.to_s.strip
doc&.at_css(selector)&.text&.to_s&.strip
end
end
end
16 changes: 0 additions & 16 deletions test/models/parser/kwai_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

class KwaiIntegrationTest < ActiveSupport::TestCase
test "should parse Kwai URL" do
skip "Kwai parsing is not currently working; pending until we look into"

m = create_media url: 'https://s.kw.ai/p/1mCb9SSh'
data = m.as_json
assert_equal 'Reginaldo Silva2871', data['username']
Expand Down Expand Up @@ -47,18 +45,4 @@ def teardown
assert_equal 'Reginaldo Silva2871', data[:author_name]
assert_equal 'Reginaldo Silva2871', data[:username]
end

test "returns a hash with error message and sends error to Errbit if there is an error parsing" do
mocked_sentry = MiniTest::Mock.new
mocked_sentry.expect :call, :return_value, [StandardError, Hash]

data = nil
empty_doc = Nokogiri::HTML('')
PenderSentry.stub(:notify, mocked_sentry) do
data = Parser::KwaiItem.new('https://s.kw.ai/p/example').parse_data(empty_doc)
end
mocked_sentry.verify
assert_equal 5, data[:error][:code]
assert_match /NoMethodError/, data[:error][:message]
end
end

0 comments on commit 3bef6c0

Please sign in to comment.