fix: Update automation to use case-insensitive filter (#5302)
This commit is contained in:
parent
bef3f66501
commit
747ce9c80f
4 changed files with 32 additions and 5 deletions
|
@ -88,7 +88,11 @@ class AutomationRules::ConditionsFilterService < FilterService
|
|||
|
||||
case current_filter['attribute_type']
|
||||
when 'standard'
|
||||
" messages.#{attribute_key} #{filter_operator_value} #{query_operator} "
|
||||
if current_filter['data_type'] == 'text'
|
||||
" LOWER(messages.#{attribute_key}) #{filter_operator_value} #{query_operator} "
|
||||
else
|
||||
" messages.#{attribute_key} #{filter_operator_value} #{query_operator} "
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ class FilterService
|
|||
query_hash['values'].map { |x| Conversation.statuses[x.to_sym] }
|
||||
when 'message_type'
|
||||
query_hash['values'].map { |x| Message.message_types[x.to_sym] }
|
||||
when 'content'
|
||||
string_filter_values(query_hash)
|
||||
else
|
||||
query_hash['values']
|
||||
end
|
||||
|
|
|
@ -175,7 +175,7 @@
|
|||
"message_type": {
|
||||
"attribute_name": "Message Type",
|
||||
"input_type": "search_box with name tags/plain text",
|
||||
"data_type": "text",
|
||||
"data_type": "numeric",
|
||||
"filter_operators": [ "equal_to", "not_equal_to" ],
|
||||
"attribute_type": "standard"
|
||||
},
|
||||
|
|
|
@ -362,16 +362,20 @@ describe AutomationRuleListener do
|
|||
event_name: 'message_created',
|
||||
name: 'Call actions message created based on case in-sensitive filter',
|
||||
description: 'Add labels, assign team after message created',
|
||||
conditions: [{ 'values': ['KYC'], 'attribute_key': 'content', 'query_operator': nil, 'filter_operator': 'contains' }]
|
||||
conditions: [
|
||||
{ 'values': ['KYC'], 'attribute_key': 'content', 'query_operator': nil, 'filter_operator': 'contains' }
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
let!(:message) { create(:message, account: account, conversation: conversation, message_type: 'incoming', content: 'kyc message') }
|
||||
let!(:message) { create(:message, account: account, conversation: conversation, message_type: 'incoming', content: 'KyC message') }
|
||||
let!(:message_2) { create(:message, account: account, conversation: conversation, message_type: 'incoming', content: 'SALE') }
|
||||
|
||||
let!(:event) do
|
||||
Events::Base.new('message_created', Time.zone.now, { conversation: conversation, message: message })
|
||||
end
|
||||
|
||||
it 'triggers automation rule based on case in-sensitive filter' do
|
||||
it 'triggers automation rule on contains filter' do
|
||||
expect(conversation.labels).to eq([])
|
||||
expect(TeamNotifications::AutomationNotificationMailer).to receive(:conversation_creation)
|
||||
listener.message_created(event)
|
||||
|
@ -379,6 +383,23 @@ describe AutomationRuleListener do
|
|||
|
||||
expect(conversation.labels.pluck(:name)).to contain_exactly('support', 'priority_customer')
|
||||
end
|
||||
|
||||
it 'triggers automation on equal_to filter' do
|
||||
automation_rule.update!(
|
||||
conditions: [
|
||||
{ 'values': ['sale'], 'attribute_key': 'content', 'query_operator': nil, 'filter_operator': 'equal_to' }
|
||||
],
|
||||
actions: [
|
||||
{ 'action_name' => 'add_label', 'action_params' => %w[sale_enquiry] }
|
||||
]
|
||||
)
|
||||
|
||||
event = Events::Base.new('message_created', Time.zone.now, { conversation: conversation, message: message_2 })
|
||||
listener.message_created(event)
|
||||
|
||||
conversation.reload
|
||||
expect(conversation.labels.pluck(:name)).to contain_exactly('sale_enquiry')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#message_created' do
|
||||
|
|
Loading…
Reference in a new issue