Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-3623: normalize tipline text before saving #1650

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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