Skip to content

Commit

Permalink
CV2-3623: normalize tipline text before saving (#1650)
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy authored Sep 12, 2023
1 parent 0f14239 commit 0231b3d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/bot/smooch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions test/models/bot/smooch_4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit 0231b3d

Please sign in to comment.