diff --git a/app/models/bot/smooch.rb b/app/models/bot/smooch.rb index 6f808d28b6..c6036891ce 100644 --- a/app/models/bot/smooch.rb +++ b/app/models/bot/smooch.rb @@ -779,9 +779,9 @@ def self.save_text_message(message) pm = nil extra = {} if link.nil? - claim = self.extract_claim(text) + claim = self.extract_claim(text).gsub(/\s+/, ' ').strip extra = { quote: claim } - pm = ProjectMedia.joins(:media).where('lower(quote) = ?', claim.downcase).where('project_medias.team_id' => team.id).last + pm = ProjectMedia.joins(:media).where('trim(lower(quote)) = ?', claim.downcase).where('project_medias.team_id' => team.id).last else extra = { url: link.url } pm = ProjectMedia.joins(:media).where('medias.url' => link.url, 'project_medias.team_id' => team.id).last diff --git a/test/models/bot/smooch_4_test.rb b/test/models/bot/smooch_4_test.rb index 31f2db57f1..80db102e3a 100644 --- a/test/models/bot/smooch_4_test.rb +++ b/test/models/bot/smooch_4_test.rb @@ -566,6 +566,45 @@ def teardown end end + test "should normalize text for tipline queries" do + Sidekiq::Testing.inline! do + text = "\vstring for testing\t\n " + message = { + type: 'text', + text: text, + authorId: random_string, + '_id': random_string + } + assert_difference 'ProjectMedia.count', 1 do + Bot::Smooch.save_message(message.to_json, @app_id) + end + pm = ProjectMedia.last + assert_equal 'string for testing', pm.media.quote + text = "\vstring FOR teSTIng\t\n " + message = { + type: 'text', + text: text, + authorId: random_string, + '_id': random_string + } + assert_no_difference 'ProjectMedia.count' do + Bot::Smooch.save_message(message.to_json, @app_id) + end + # test with existing items + pm = create_project_media team: @team, quote: ' test with Existing ITEM' + text = "\vTEST with existing item \t\n " + message = { + type: 'text', + text: text, + authorId: random_string, + '_id': random_string + } + assert_no_difference 'ProjectMedia.count' do + Bot::Smooch.save_message(message.to_json, @app_id) + end + end + end + test "should send only visual card to user" do pm = create_project_media publish_report(pm, {}, nil, { use_text_message: false })