Fixes #3270 - Ticket selector "within last (relative)" and "within next (relative)" not working correctly.

This commit is contained in:
Rolf Schmidt 2020-11-09 09:36:07 +01:00 committed by Thorsten Eckel
parent 053429bb79
commit 6810bc5548
3 changed files with 74 additions and 48 deletions

View file

@ -813,7 +813,7 @@ condition example
query += "#{attribute} >= ?"
bind_params.push selector['value']
elsif selector['operator'] == 'within last (relative)'
query += "#{attribute} >= ?"
query += "#{attribute} BETWEEN ? AND ?"
time = nil
case selector['range']
when 'minute'
@ -830,8 +830,9 @@ condition example
raise "Unknown selector attributes '#{selector.inspect}'"
end
bind_params.push time
bind_params.push Time.zone.now
elsif selector['operator'] == 'within next (relative)'
query += "#{attribute} <= ?"
query += "#{attribute} BETWEEN ? AND ?"
time = nil
case selector['range']
when 'minute'
@ -847,6 +848,7 @@ condition example
else
raise "Unknown selector attributes '#{selector.inspect}'"
end
bind_params.push Time.zone.now
bind_params.push time
elsif selector['operator'] == 'before (relative)'
query += "#{attribute} <= ?"

View file

@ -828,6 +828,76 @@ RSpec.describe Ticket, type: :model do
.to change { ticket.reload.escalation_at }.to(nil)
end
end
context 'when within last (relative)' do
let(:first_response_time) { 5 }
let(:sla) { create(:sla, calendar: calendar, first_response_time: first_response_time) }
let(:within_condition) do
{ 'ticket.escalation_at'=>{ 'operator' => 'within last (relative)', 'value' => '30', 'range' => 'minute' } }
end
before do
sla
travel_to '2020-11-05 11:37:00'
ticket = create(:ticket)
create(:ticket_article, :inbound_email, ticket: ticket)
travel_to '2020-11-05 11:50:00'
end
context 'when in range' do
it 'does find the ticket' do
count, _tickets = described_class.selectors(within_condition, limit: 2_000, execution_time: true)
expect(count).to eq(1)
end
end
context 'when out of range' do
let(:first_response_time) { 500 }
it 'does not find the ticket' do
count, _tickets = described_class.selectors(within_condition, limit: 2_000, execution_time: true)
expect(count).to eq(0)
end
end
end
context 'when within next (relative)' do
let(:first_response_time) { 5 }
let(:sla) { create(:sla, calendar: calendar, first_response_time: first_response_time) }
let(:within_condition) do
{ 'ticket.escalation_at'=>{ 'operator' => 'within next (relative)', 'value' => '30', 'range' => 'minute' } }
end
before do
sla
travel_to '2020-11-05 11:50:00'
ticket = create(:ticket)
create(:ticket_article, :inbound_email, ticket: ticket)
travel_to '2020-11-05 11:37:00'
end
context 'when in range' do
it 'does find the ticket' do
count, _tickets = described_class.selectors(within_condition, limit: 2_000, execution_time: true)
expect(count).to eq(1)
end
end
context 'when out of range' do
let(:first_response_time) { 500 }
it 'does not find the ticket' do
count, _tickets = described_class.selectors(within_condition, limit: 2_000, execution_time: true)
expect(count).to eq(0)
end
end
end
end
describe '#first_response_escalation_at' do

View file

@ -409,29 +409,6 @@ class TicketSelectorTest < ActiveSupport::TestCase
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
condition = {
'ticket.group_id' => {
operator: 'is',
value: @group.id,
},
'ticket.created_at' => {
operator: 'within next (relative)',
range: 'year', # minute|hour|day|month|
value: '10',
},
}
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
condition = {
'ticket.group_id' => {
operator: 'is',
@ -567,29 +544,6 @@ class TicketSelectorTest < ActiveSupport::TestCase
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
condition = {
'ticket.group_id' => {
operator: 'is',
value: @group.id,
},
'ticket.updated_at' => {
operator: 'within next (relative)',
range: 'year', # minute|hour|day|month|
value: '10',
},
}
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
condition = {
'ticket.group_id' => {
operator: 'is',