Trigger date alerts when user is responsible of work package

pull/11482/head
Christophe Bliard 2 years ago
parent a3a5e58178
commit 1938902805
No known key found for this signature in database
GPG Key ID: 2BC07603210C3FA4
  1. 5
      app/workers/notifications/create_date_alerts_notifications_job.rb
  2. 38
      spec/workers/notifications/create_date_alerts_notifications_job_spec.rb

@ -59,10 +59,11 @@ module Notifications
end end
def work_package_with_involved(user) def work_package_with_involved(user)
WorkPackage work_packages = WorkPackage
.joins(:status) .joins(:status)
.where(statuses: { is_closed: false }) .where(statuses: { is_closed: false })
.where(assigned_to: user) work_packages.where(assigned_to: user)
.or(work_packages.where(responsible: user))
end end
def time_zones_covering_1am_local_time def time_zones_covering_1am_local_time

@ -62,8 +62,7 @@ describe Notifications::CreateDateAlertsNotificationsJob, type: :job do
) )
end end
shared_let(:alertable_work_packages) do shared_let(:alertable_work_packages) do
create_list(:work_package, 2, create_list(:work_package, 2)
assigned_to: user_paris)
end end
before do before do
@ -82,18 +81,23 @@ describe Notifications::CreateDateAlertsNotificationsJob, type: :job do
end end
failure_message do |user| failure_message do |user|
"expected user #{inspect_keys(user, :id, :firstname)} " \ "expected user #{inspect_keys(user)} " \
"to have a start date alert notification for work package " \ "to have a start date alert notification for work package " \
"#{inspect_keys(work_package, :id, :start_date, :due_date)}" "#{inspect_keys(work_package)}"
end end
failure_message_when_negated do |user| failure_message_when_negated do |user|
"expected user #{inspect_keys(user, :id, :firstname)} " \ "expected user #{inspect_keys(user)} " \
"to NOT have a start date alert notification for work package " \ "to NOT have a start date alert notification for work package " \
"#{inspect_keys(work_package, :id, :start_date, :due_date)}" "#{inspect_keys(work_package)}"
end end
def inspect_keys(object, *keys) def inspect_keys(object)
keys =
case object
when User then %i[id firstname]
when WorkPackage then %i[id start_date due_date assigned_to_id responsible_id]
end
formatted_pairs = object formatted_pairs = object
.slice(*keys) .slice(*keys)
.map { |k, v| "#{k}: #{v.is_a?(Date) ? v.to_s : v.inspect}" } .map { |k, v| "#{k}: #{v.is_a?(Date) ? v.to_s : v.inspect}" }
@ -107,8 +111,13 @@ describe Notifications::CreateDateAlertsNotificationsJob, type: :job do
end end
def alertable_work_package(attributes = {}) def alertable_work_package(attributes = {})
assignee = attributes.slice(:responsible, :responsible_id).any? ? nil : user_paris
attributes = attributes.reverse_merge(
start_date: in_1_day,
assigned_to: assignee
)
wp = alertable_work_packages.shift wp = alertable_work_packages.shift
wp.update!(attributes.reverse_merge(start_date: in_1_day)) wp.update!(attributes)
wp wp
end end
@ -150,6 +159,19 @@ describe Notifications::CreateDateAlertsNotificationsJob, type: :job do
end end
end end
it 'creates date alert notifications if user is assigned to or accountable of the work package' do
work_package_assigned = alertable_work_package(assigned_to: user_paris)
work_package_accountable = alertable_work_package(responsible: user_paris)
set_scheduled_time(timezone_paris.now.change(hour: 1, min: 0))
travel_to(timezone_paris.now.change(hour: 1, min: 4)) do
scheduled_job.invoke_job
expect(user_paris).to have_a_start_date_alert_notification_for(work_package_assigned)
expect(user_paris).to have_a_start_date_alert_notification_for(work_package_accountable)
end
end
context 'when scheduled and executed at 01:00 am Paris local time' do context 'when scheduled and executed at 01:00 am Paris local time' do
it 'creates a start date alert notification for a user in the same time zone' do it 'creates a start date alert notification for a user in the same time zone' do
work_package = alertable_work_package work_package = alertable_work_package

Loading…
Cancel
Save