Skip to content

Commit

Permalink
Do not submit as unconfirmed media a text with just a few words.
Browse files Browse the repository at this point in the history
In that case, the request should still be saved, but associated with the workspace, not with a text media.

Fixes CV2-3784.
  • Loading branch information
caiosba committed Oct 5, 2023
1 parent 5da8afa commit c2e1818
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/models/bot/smooch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,9 @@ def self.save_text_message(message)
extra = {}
if link.nil?
claim = self.extract_claim(text).gsub(/\s+/, ' ').strip
if message['archived'] == CheckArchivedFlags::FlagCodes::UNCONFIRMED && ::Bot::Alegre.get_number_of_words(claim) < CheckConfig.get('min_number_of_words_for_tipline_submit_shortcut', 10, :integer)
return team
end
extra = { quote: claim }
pm = ProjectMedia.joins(:media).where('trim(lower(quote)) = ?', claim.downcase).where('project_medias.team_id' => team.id).last
else
Expand Down
26 changes: 26 additions & 0 deletions test/models/bot/smooch_6_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -854,4 +854,30 @@ def send_message_outside_24_hours_window(template, pm = nil)
send_message 'Hello'
assert_state 'main'
end

test 'should save unconfirmed media with enough words' do
@installation.set_smooch_disable_timeout = false
@installation.save!
reload_tipline_settings
send_message 'hello', '1' # Sends a first message and confirms language as English
send_message 'This is message is so long that it is considered a media'
assert_difference 'ProjectMedia.count' do
assert_difference "Dynamic.where(annotation_type: 'smooch').count" do
Sidekiq::Worker.drain_all
end
end
end

test 'should not save unconfirmed media with just a few words' do
@installation.set_smooch_disable_timeout = false
@installation.save!
reload_tipline_settings
send_message 'hello', '1' # Sends a first message and confirms language as English
send_message 'Hi, there!'
assert_no_difference 'ProjectMedia.count' do
assert_difference "Dynamic.where(annotation_type: 'smooch').count" do
Sidekiq::Worker.drain_all
end
end
end
end

0 comments on commit c2e1818

Please sign in to comment.