Skip to content

Commit

Permalink
CV2-4998: extract link as tipline message (#1975)
Browse files Browse the repository at this point in the history
* CV2-4998: extract link as tipline message

* CV2-4998: apply PR comment

* CV2-4998: replace extract url method with Twitter one
  • Loading branch information
melsawy authored Aug 1, 2024
1 parent 010cfe5 commit 0e6a3d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/models/concerns/smooch_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ def bundle_list_of_messages_to_items(list, last)
if message['type'] == 'text'
# Get an item for long text (message that match number of words condition)
if message['payload'].nil?
messages << message if ::Bot::Alegre.get_number_of_words(message['text'].to_s) > CheckConfig.get('min_number_of_words_for_tipline_submit_shortcut', 10, :integer)
contains_link = Twitter::TwitterText::Extractor.extract_urls(message['text'])
messages << message if !contains_link.blank? || ::Bot::Alegre.get_number_of_words(message['text'].to_s) > CheckConfig.get('min_number_of_words_for_tipline_submit_shortcut', 10, :integer)
text << message['text']
end
elsif !message['mediaUrl'].blank?
Expand Down
20 changes: 15 additions & 5 deletions test/models/bot/smooch_3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def teardown
# messages contain the following:
# 1). long text( > min_number_of_words_for_tipline_submit_shortcut)
# 2). short text (< min_number_of_words_for_tipline_submit_shortcut)
# 3). 2 medias
# Result: created three items (one claim and two items of type image)
# 3). link
# 4). 2 medias
# Result: created four items (one claim, one link and two items of type image)
Sidekiq::Testing.fake! do
uid = random_string
messages = [
Expand All @@ -88,6 +89,13 @@ def teardown
source: { type: "whatsapp" },
text: long_text.join(' '),
},
{
'_id': random_string,
authorId: uid,
type: 'text',
source: { type: "whatsapp" },
text: @link_url,
},
{
'_id': random_string,
authorId: uid,
Expand Down Expand Up @@ -127,17 +135,19 @@ def teardown
Bot::Smooch.run(payload)
sleep 1
end
assert_difference 'ProjectMedia.count', 3 do
assert_difference 'ProjectMedia.count', 4 do
assert_difference 'UploadedImage.count', 2 do
assert_difference 'Claim.count' do
Sidekiq::Worker.drain_all
assert_difference 'Link.count' do
Sidekiq::Worker.drain_all
end
end
end
end
pm = ProjectMedia.last
request = pm.tipline_requests.last
text = request.smooch_data['text'].split("\n#{Bot::Smooch::MESSAGE_BOUNDARY}")
target_text = [long_text.join(' '), 'first image', @media_url, @media_url_2, 'bar']
target_text = [long_text.join(' '), @link_url, 'first image', @media_url, @media_url_2, 'bar']
assert_equal target_text, text
# Messages with short text only
messages = [
Expand Down

0 comments on commit 0e6a3d7

Please sign in to comment.