Skip to content

Commit

Permalink
Working tests and return false not nil for no urls
Browse files Browse the repository at this point in the history
Actual ran tests locally :-)
  • Loading branch information
computermacgyver committed Aug 28, 2024
1 parent 087c006 commit e7822e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/bot/smooch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def self.is_a_shortcut_for_submission?(state, message)
self.is_v2? && (state == 'main' || state == 'waiting_for_message') && (
!message['mediaUrl'].blank? ||
::Bot::Alegre.get_number_of_words(message['text'].to_s) > CheckConfig.get('min_number_of_words_for_tipline_submit_shortcut', 10, :integer) ||
URI.regexp =~ message['text'].to_s # URL in message?
URI.regexp.match(message['text'].to_s)!=nil # URL in message?
)
end

Expand Down
16 changes: 8 additions & 8 deletions test/models/bot/smooch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -791,21 +791,21 @@ def teardown
end

test "should submit message for factchecking" do
Bot::Smooch.stubs(:is_v2?).returns{true}
Bot::Smooch.stubs(:is_v2?).returns(true)
state='main'

# Should not be a submission shortcut
message = {"text": "abc"}
assert_equal(false, Bot::Smooch::is_a_shortcut_for_submission(state,message), "Unexpected shortcut")
message = {"text"=>"abc"}
assert_equal(false, Bot::Smooch.is_a_shortcut_for_submission?(state,message), "Unexpected shortcut")

# Should be a submission shortcut
message = {"text": "abc http://example.com"}
assert_equal(true, Bot::Smooch::is_a_shortcut_for_submission(state,message), "Missed URL shortcut")
message = {"text"=>"abc http://example.com"}
assert_equal(true, Bot::Smooch.is_a_shortcut_for_submission?(state,message), "Missed URL shortcut")

# Should be a submission shortcut
message = {"text": "abc", "mediaUrl": "not blank"}
assert_equal(true, Bot::Smooch::is_a_shortcut_for_submission(state,message), "Missed media shortcut")
message = {"text"=>"abc", "mediaUrl"=>"not blank"}
assert_equal(true, Bot::Smooch.is_a_shortcut_for_submission?(state,message), "Missed media shortcut")

Bot::Smooch.unstubs(:is_v2?)
Bot::Smooch.unstub(:is_v2?)
end
end

0 comments on commit e7822e0

Please sign in to comment.