fix: Conversation filter on dates (#5024)
This commit is contained in:
@@ -65,7 +65,8 @@ class FilterService
|
|||||||
|
|
||||||
def lt_gt_filter_values(query_hash)
|
def lt_gt_filter_values(query_hash)
|
||||||
attribute_key = query_hash[:attribute_key]
|
attribute_key = query_hash[:attribute_key]
|
||||||
attribute_type = custom_attribute(attribute_key, @account, query_hash['custom_attribute_type']).try(:attribute_display_type)
|
attribute_model = query_hash['custom_attribute_type'].presence || self.class::ATTRIBUTE_MODEL
|
||||||
|
attribute_type = custom_attribute(attribute_key, @account, attribute_model).try(:attribute_display_type)
|
||||||
attribute_data_type = self.class::ATTRIBUTE_TYPES[attribute_type]
|
attribute_data_type = self.class::ATTRIBUTE_TYPES[attribute_type]
|
||||||
value = query_hash['values'][0]
|
value = query_hash['values'][0]
|
||||||
operator = query_hash['filter_operator'] == 'is_less_than' ? '<' : '>'
|
operator = query_hash['filter_operator'] == 'is_less_than' ? '<' : '>'
|
||||||
@@ -90,7 +91,7 @@ class FilterService
|
|||||||
def custom_attribute_query(query_hash, custom_attribute_type, current_index)
|
def custom_attribute_query(query_hash, custom_attribute_type, current_index)
|
||||||
attribute_key = query_hash[:attribute_key]
|
attribute_key = query_hash[:attribute_key]
|
||||||
query_operator = query_hash[:query_operator]
|
query_operator = query_hash[:query_operator]
|
||||||
attribute_model = custom_attribute_type || self.class::ATTRIBUTE_MODEL
|
attribute_model = custom_attribute_type.presence || self.class::ATTRIBUTE_MODEL
|
||||||
|
|
||||||
attribute_type = custom_attribute(attribute_key, @account, attribute_model).try(:attribute_display_type)
|
attribute_type = custom_attribute(attribute_key, @account, attribute_model).try(:attribute_display_type)
|
||||||
filter_operator_value = filter_operation(query_hash, current_index)
|
filter_operator_value = filter_operation(query_hash, current_index)
|
||||||
@@ -107,7 +108,7 @@ class FilterService
|
|||||||
|
|
||||||
def custom_attribute(attribute_key, account, custom_attribute_type)
|
def custom_attribute(attribute_key, account, custom_attribute_type)
|
||||||
current_account = account || Current.account
|
current_account = account || Current.account
|
||||||
attribute_model = custom_attribute_type || self.class::ATTRIBUTE_MODEL
|
attribute_model = custom_attribute_type.presence || self.class::ATTRIBUTE_MODEL
|
||||||
@custom_attribute = current_account.custom_attribute_definitions.where(
|
@custom_attribute = current_account.custom_attribute_definitions.where(
|
||||||
attribute_model: attribute_model
|
attribute_model: attribute_model
|
||||||
).find_by(attribute_key: attribute_key)
|
).find_by(attribute_key: attribute_key)
|
||||||
|
|||||||
@@ -58,13 +58,15 @@ describe ::Conversations::FilterService do
|
|||||||
attribute_key: 'browser_language',
|
attribute_key: 'browser_language',
|
||||||
filter_operator: 'contains',
|
filter_operator: 'contains',
|
||||||
values: 'en',
|
values: 'en',
|
||||||
query_operator: 'AND'
|
query_operator: 'AND',
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access,
|
}.with_indifferent_access,
|
||||||
{
|
{
|
||||||
attribute_key: 'status',
|
attribute_key: 'status',
|
||||||
filter_operator: 'not_equal_to',
|
filter_operator: 'not_equal_to',
|
||||||
values: %w[resolved],
|
values: %w[resolved],
|
||||||
query_operator: nil
|
query_operator: nil,
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
@@ -94,13 +96,15 @@ describe ::Conversations::FilterService do
|
|||||||
user_1.id,
|
user_1.id,
|
||||||
user_2.id
|
user_2.id
|
||||||
],
|
],
|
||||||
query_operator: 'AND'
|
query_operator: 'AND',
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access,
|
}.with_indifferent_access,
|
||||||
{
|
{
|
||||||
attribute_key: 'labels',
|
attribute_key: 'labels',
|
||||||
filter_operator: 'equal_to',
|
filter_operator: 'equal_to',
|
||||||
values: ['support'],
|
values: ['support'],
|
||||||
query_operator: nil
|
query_operator: nil,
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
]
|
]
|
||||||
result = filter_service.new(params, user_1).perform
|
result = filter_service.new(params, user_1).perform
|
||||||
@@ -116,13 +120,15 @@ describe ::Conversations::FilterService do
|
|||||||
user_1.id,
|
user_1.id,
|
||||||
user_2.id
|
user_2.id
|
||||||
],
|
],
|
||||||
query_operator: 'AND'
|
query_operator: 'AND',
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access,
|
}.with_indifferent_access,
|
||||||
{
|
{
|
||||||
attribute_key: 'campaign_id',
|
attribute_key: 'campaign_id',
|
||||||
filter_operator: 'is_present',
|
filter_operator: 'is_present',
|
||||||
values: [],
|
values: [],
|
||||||
query_operator: nil
|
query_operator: nil,
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
]
|
]
|
||||||
result = filter_service.new(params, user_1).perform
|
result = filter_service.new(params, user_1).perform
|
||||||
@@ -150,7 +156,36 @@ describe ::Conversations::FilterService do
|
|||||||
attribute_key: 'conversation_created',
|
attribute_key: 'conversation_created',
|
||||||
filter_operator: 'is_less_than',
|
filter_operator: 'is_less_than',
|
||||||
values: ['2022-01-20'],
|
values: ['2022-01-20'],
|
||||||
query_operator: 'OR'
|
query_operator: 'OR',
|
||||||
|
custom_attribute_type: ''
|
||||||
|
}.with_indifferent_access,
|
||||||
|
{
|
||||||
|
attribute_key: 'labels',
|
||||||
|
filter_operator: 'equal_to',
|
||||||
|
values: ['support'],
|
||||||
|
query_operator: nil
|
||||||
|
}.with_indifferent_access
|
||||||
|
]
|
||||||
|
result = filter_service.new(params, user_1).perform
|
||||||
|
expect(result[:conversations].length).to be 1
|
||||||
|
expect(result[:conversations][0][:id]).to be user_2_assigned_conversation.id
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'filter by custom_attributes and labels with custom_attribute_type nil' do
|
||||||
|
user_2_assigned_conversation.update_labels('support')
|
||||||
|
params[:payload] = [
|
||||||
|
{
|
||||||
|
attribute_key: 'conversation_type',
|
||||||
|
filter_operator: 'equal_to',
|
||||||
|
values: ['platinum'],
|
||||||
|
query_operator: 'AND'
|
||||||
|
}.with_indifferent_access,
|
||||||
|
{
|
||||||
|
attribute_key: 'conversation_created',
|
||||||
|
filter_operator: 'is_less_than',
|
||||||
|
values: ['2022-01-20'],
|
||||||
|
query_operator: 'OR',
|
||||||
|
custom_attribute_type: nil
|
||||||
}.with_indifferent_access,
|
}.with_indifferent_access,
|
||||||
{
|
{
|
||||||
attribute_key: 'labels',
|
attribute_key: 'labels',
|
||||||
@@ -170,13 +205,36 @@ describe ::Conversations::FilterService do
|
|||||||
attribute_key: 'conversation_type',
|
attribute_key: 'conversation_type',
|
||||||
filter_operator: 'equal_to',
|
filter_operator: 'equal_to',
|
||||||
values: ['platinum'],
|
values: ['platinum'],
|
||||||
query_operator: 'AND'
|
query_operator: 'AND',
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access,
|
}.with_indifferent_access,
|
||||||
{
|
{
|
||||||
attribute_key: 'conversation_created',
|
attribute_key: 'conversation_created',
|
||||||
filter_operator: 'is_less_than',
|
filter_operator: 'is_less_than',
|
||||||
values: ['2022-01-20'],
|
values: ['2022-01-20'],
|
||||||
query_operator: nil
|
query_operator: nil,
|
||||||
|
custom_attribute_type: ''
|
||||||
|
}.with_indifferent_access
|
||||||
|
]
|
||||||
|
result = filter_service.new(params, user_1).perform
|
||||||
|
expect(result[:conversations].length).to be 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'filter by custom_attributes with custom_attribute_type nil' do
|
||||||
|
params[:payload] = [
|
||||||
|
{
|
||||||
|
attribute_key: 'conversation_type',
|
||||||
|
filter_operator: 'equal_to',
|
||||||
|
values: ['platinum'],
|
||||||
|
query_operator: 'AND',
|
||||||
|
custom_attribute_type: nil
|
||||||
|
}.with_indifferent_access,
|
||||||
|
{
|
||||||
|
attribute_key: 'conversation_created',
|
||||||
|
filter_operator: 'is_less_than',
|
||||||
|
values: ['2022-01-20'],
|
||||||
|
query_operator: nil,
|
||||||
|
custom_attribute_type: nil
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
]
|
]
|
||||||
result = filter_service.new(params, user_1).perform
|
result = filter_service.new(params, user_1).perform
|
||||||
@@ -189,13 +247,15 @@ describe ::Conversations::FilterService do
|
|||||||
attribute_key: 'conversation_type',
|
attribute_key: 'conversation_type',
|
||||||
filter_operator: 'equal_to',
|
filter_operator: 'equal_to',
|
||||||
values: ['platinum'],
|
values: ['platinum'],
|
||||||
query_operator: 'AND'
|
query_operator: 'AND',
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access,
|
}.with_indifferent_access,
|
||||||
{
|
{
|
||||||
attribute_key: 'browser_language',
|
attribute_key: 'browser_language',
|
||||||
filter_operator: 'is_equal_to',
|
filter_operator: 'is_equal_to',
|
||||||
values: 'en',
|
values: 'en',
|
||||||
query_operator: nil
|
query_operator: nil,
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
]
|
]
|
||||||
result = filter_service.new(params, user_1).perform
|
result = filter_service.new(params, user_1).perform
|
||||||
@@ -214,7 +274,8 @@ describe ::Conversations::FilterService do
|
|||||||
attribute_key: 'created_at',
|
attribute_key: 'created_at',
|
||||||
filter_operator: 'is_greater_than',
|
filter_operator: 'is_greater_than',
|
||||||
values: ['2022-01-20'],
|
values: ['2022-01-20'],
|
||||||
query_operator: nil
|
query_operator: nil,
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
]
|
]
|
||||||
result = filter_service.new(params, user_1).perform
|
result = filter_service.new(params, user_1).perform
|
||||||
@@ -228,13 +289,15 @@ describe ::Conversations::FilterService do
|
|||||||
attribute_key: 'conversation_type',
|
attribute_key: 'conversation_type',
|
||||||
filter_operator: 'equal_to',
|
filter_operator: 'equal_to',
|
||||||
values: ['platinum'],
|
values: ['platinum'],
|
||||||
query_operator: 'AND'
|
query_operator: 'AND',
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access,
|
}.with_indifferent_access,
|
||||||
{
|
{
|
||||||
attribute_key: 'created_at',
|
attribute_key: 'created_at',
|
||||||
filter_operator: 'is_greater_than',
|
filter_operator: 'is_greater_than',
|
||||||
values: ['2022-01-20'],
|
values: ['2022-01-20'],
|
||||||
query_operator: nil
|
query_operator: nil,
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
]
|
]
|
||||||
result = filter_service.new(params, user_1).perform
|
result = filter_service.new(params, user_1).perform
|
||||||
@@ -257,13 +320,15 @@ describe ::Conversations::FilterService do
|
|||||||
attribute_key: 'last_activity_at',
|
attribute_key: 'last_activity_at',
|
||||||
filter_operator: 'days_before',
|
filter_operator: 'days_before',
|
||||||
values: [3],
|
values: [3],
|
||||||
query_operator: 'AND'
|
query_operator: 'AND',
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access,
|
}.with_indifferent_access,
|
||||||
{
|
{
|
||||||
attribute_key: 'conversation_type',
|
attribute_key: 'conversation_type',
|
||||||
filter_operator: 'equal_to',
|
filter_operator: 'equal_to',
|
||||||
values: ['platinum'],
|
values: ['platinum'],
|
||||||
query_operator: nil
|
query_operator: nil,
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -280,7 +345,8 @@ describe ::Conversations::FilterService do
|
|||||||
attribute_key: 'last_activity_at',
|
attribute_key: 'last_activity_at',
|
||||||
filter_operator: 'days_before',
|
filter_operator: 'days_before',
|
||||||
values: [3],
|
values: [3],
|
||||||
query_operator: nil
|
query_operator: nil,
|
||||||
|
custom_attribute_type: ''
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user