Update the Settings::WorkingDaysUpdateService to schedule the WorkPackages::ApplyWorkingDaysChangeJob on a successful settings change

pull/11854/head
Dombi Attila 2 years ago
parent 15ad45b17a
commit b0c02dced7
  1. 14
      app/services/settings/working_days_update_service.rb
  2. 30
      spec/services/settings/working_days_update_service_spec.rb

@ -30,6 +30,8 @@ class Settings::WorkingDaysUpdateService < Settings::UpdateService
def call(params)
params = params.to_h.deep_symbolize_keys
self.non_working_days_params = params.delete(:non_working_days) || []
self.previous_working_days = Setting[:working_days]
self.previous_non_working_days = NonWorkingDay.pluck(:date)
super
end
@ -54,9 +56,19 @@ class Settings::WorkingDaysUpdateService < Settings::UpdateService
results
end
def after_perform(call)
super.tap do
WorkPackages::ApplyWorkingDaysChangeJob.perform_later(
user_id: User.current.id,
previous_working_days:,
previous_non_working_days:
)
end
end
private
attr_accessor :non_working_days_params
attr_accessor :non_working_days_params, :previous_working_days, :previous_non_working_days
def persist_non_working_days
# We don't support update for now

@ -74,15 +74,39 @@ describe Settings::WorkingDaysUpdateService do
describe '#call' do
subject { instance.call(params) }
shared_examples 'successful working days settings call' do
include_examples 'successful call'
it 'calls the WorkPackages::ApplyWorkingDaysChangeJob' do
previous_working_days = Setting[:working_days]
previous_non_working_days = NonWorkingDay.pluck(:date)
allow(WorkPackages::ApplyWorkingDaysChangeJob).to receive(:perform_later)
subject
expect(WorkPackages::ApplyWorkingDaysChangeJob)
.to have_received(:perform_later)
.with(user_id: user.id, previous_working_days:, previous_non_working_days:)
end
end
shared_examples 'unsuccessful working days settings call' do
include_examples 'unsuccessful call'
it 'does not persists the non working days' do
expect { subject }.not_to change(NonWorkingDay, :count)
end
it 'does not calls the WorkPackages::ApplyWorkingDaysChangeJob' do
allow(WorkPackages::ApplyWorkingDaysChangeJob).to receive(:perform_later)
subject
expect(WorkPackages::ApplyWorkingDaysChangeJob).not_to have_received(:perform_later)
end
end
include_examples 'successful call'
include_examples 'successful working days settings call'
context 'when non working days are present' do
let!(:existing_nwd) { create(:non_working_day, name: 'Existing NWD') }
@ -96,7 +120,7 @@ describe Settings::WorkingDaysUpdateService do
]
end
include_examples 'successful call'
include_examples 'successful working days settings call'
it 'persists (create/delete) the non working days' do
expect { subject }.to change(NonWorkingDay, :count).by(1)
@ -137,7 +161,7 @@ describe Settings::WorkingDaysUpdateService do
]
end
include_examples 'successful call'
include_examples 'successful working days settings call'
it 'persists (create/delete) the non working days' do
expect { subject }.not_to change(NonWorkingDay, :count)

Loading…
Cancel
Save