Fixes #2366 - "Warten auf Erinnerung" - Inconsistent timestamps

This commit is contained in:
Mantas 2021-08-27 00:55:38 +03:00 committed by Thorsten Eckel
parent c305ff89be
commit 6be39c9625
2 changed files with 48 additions and 1 deletions

View file

@ -125,11 +125,13 @@ class Transaction::Notification
identifier = user.login
end
already_notified_cutoff = Time.use_zone(Setting.get('timezone_default').presence || 'UTC') { Time.current.beginning_of_day }
already_notified = History.where(
history_type_id: History.type_lookup('notification').id,
history_object_id: History.object_lookup('Ticket').id,
o_id: ticket.id
).where('created_at > ?', Time.zone.now.beginning_of_day).exists?(['value_to LIKE ?', "%#{identifier}(#{@item[:type]}:%"])
).where('created_at > ?', already_notified_cutoff).exists?(['value_to LIKE ?', "%#{identifier}(#{@item[:type]}:%"])
next if already_notified
end

View file

@ -0,0 +1,45 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'rails_helper'
RSpec.describe Transaction::Notification, type: :model do
describe 'pending ticket reminder repeats after midnight at selected time zone' do
let(:group) { create(:group) }
let(:user) { create(:agent) }
let(:ticket) { create(:ticket, owner: user, state_name: 'open', pending_time: Time.current) }
before do
user.groups << group
ticket
Setting.set('timezone_default', 'America/Santiago')
freeze_time
run(ticket, user, 'reminder_reached')
OnlineNotification.destroy_all
end
it 'notification not sent at UTC midnight' do
travel_to Time.current.end_of_day + 1.minute
expect { run(ticket, user, 'reminder_reached') }.not_to change(OnlineNotification, :count)
end
it 'notification sent at selected time zone midnight' do
travel_to Time.use_zone('America/Santiago') { Time.current.end_of_day + 1.minute }
expect { run(ticket, user, 'reminder_reached') }.to change(OnlineNotification, :count).by(1)
end
end
def run(ticket, user, type)
described_class.new(
object: ticket.class.name,
type: type,
object_id: ticket.id,
interface_handle: 'scheduler',
changes: nil,
created_at: Time.current,
user_id: user.id
).perform
end
end