diff --git a/app/controllers/recurring_job/usps_upload_controller.rb b/app/controllers/recurring_job/usps_upload_controller.rb index 95c3c8c037a..5e4cb169046 100644 --- a/app/controllers/recurring_job/usps_upload_controller.rb +++ b/app/controllers/recurring_job/usps_upload_controller.rb @@ -2,7 +2,7 @@ module RecurringJob class UspsUploadController < AuthTokenController def create today = Time.zone.today - UspsConfirmationUploader.new.run unless HolidayService.observed_holiday?(today) + UspsConfirmationUploader.new.run unless CalendarService.weekend_or_holiday?(today) render plain: 'ok' end diff --git a/app/services/holiday_service.rb b/app/services/calendar_service.rb similarity index 92% rename from app/services/holiday_service.rb rename to app/services/calendar_service.rb index c4391f7e7d8..95c7014ce5c 100644 --- a/app/services/holiday_service.rb +++ b/app/services/calendar_service.rb @@ -1,4 +1,4 @@ -class HolidayService +class CalendarService # https://www.opm.gov/policy-data-oversight/snow-dismissal-procedures/federal-holidays class << self @@ -9,6 +9,14 @@ def holiday?(date) def observed_holiday?(date) new(date.year).observed_holiday?(date) end + + def weekend?(date) + date.saturday? || date.sunday? + end + + def weekend_or_holiday?(date) + weekend?(date) || holiday?(date) + end end attr_reader :year diff --git a/app/services/usps_confirmation_uploader.rb b/app/services/usps_confirmation_uploader.rb index 6160dbf111b..2878bccce9f 100644 --- a/app/services/usps_confirmation_uploader.rb +++ b/app/services/usps_confirmation_uploader.rb @@ -27,7 +27,8 @@ def clear_confirmations(confirmations) end def remote_path - File.join(env.usps_upload_sftp_directory, 'batch.psv') + timestamp = Time.zone.now.strftime('%Y%m%d') + File.join(env.usps_upload_sftp_directory, "batch#{timestamp}.psv") end def sftp_config diff --git a/config/initializers/job_configurations.rb b/config/initializers/job_configurations.rb index 5fef01dc78b..7457e41b723 100644 --- a/config/initializers/job_configurations.rb +++ b/config/initializers/job_configurations.rb @@ -7,7 +7,7 @@ interval: 24 * 60 * 60, timeout: 300, callback: lambda { - UspsConfirmationUploader.new.run unless HolidayService.observed_holiday?(Time.zone.today) + UspsConfirmationUploader.new.run unless CalendarService.weekend_or_holiday?(Time.zone.today) }, ) diff --git a/spec/config/initializers/job_configurations.rb b/spec/config/initializers/job_configurations.rb index 0f2942433e3..86c98b907d5 100644 --- a/spec/config/initializers/job_configurations.rb +++ b/spec/config/initializers/job_configurations.rb @@ -11,7 +11,7 @@ expect(UspsConfirmationUploader).to receive(:new).and_return(stub) expect(stub).to receive(:run).and_return('the GPO test worked') - result = HolidayService.observed_holiday?(Time.zone.today) ? nil : 'the GPO test worked' + result = CalendarService.weekend_or_holiday?(Time.zone.today) ? nil : 'the GPO test worked' expect(job.callback.call).to eq result end diff --git a/spec/services/holiday_service_spec.rb b/spec/services/calendar_service_spec.rb similarity index 70% rename from spec/services/holiday_service_spec.rb rename to spec/services/calendar_service_spec.rb index 4bd7b6e21c1..9235b98938f 100644 --- a/spec/services/holiday_service_spec.rb +++ b/spec/services/calendar_service_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe HolidayService do +RSpec.describe CalendarService do let(:year) { 2018 } let(:instance) { described_class.new(year) } @@ -90,6 +90,25 @@ end context 'class methods' do + describe '.weekend?' do + let(:a_monday) { Date.new(2020, 11, 23) } + let(:a_friday) { Date.new(2020, 11, 27) } + let(:a_saturday) { Date.new(2020, 11, 28) } + let(:a_sunday) { Date.new(2020, 11, 29) } + + subject { described_class } + + it 'returns true for weekends' do + expect(subject.weekend?(a_saturday)).to eq(true) + expect(subject.weekend?(a_sunday)).to eq(true) + end + + it 'returns false for weekdays' do + expect(subject.weekend?(a_friday)).to eq(false) + expect(subject.weekend?(a_monday)).to eq(false) + end + end + describe '.holiday?' do subject { described_class.holiday?(date) } @@ -106,6 +125,30 @@ end end + describe '.weekend_or_holiday?' do + let(:a_monday) { Date.new(2020, 11, 23) } + let(:a_friday) { Date.new(2020, 11, 27) } + let(:a_saturday) { Date.new(2020, 11, 28) } + let(:a_sunday) { Date.new(2020, 11, 29) } + let(:a_thanksgiving) { Date.new(2020, 11, 26) } + + subject { described_class } + + it 'returns true for weekends' do + expect(subject.weekend_or_holiday?(a_saturday)).to eq(true) + expect(subject.weekend_or_holiday?(a_sunday)).to eq(true) + end + + it 'returns false for weekdays' do + expect(subject.weekend_or_holiday?(a_monday)).to eq(false) + expect(subject.weekend_or_holiday?(a_friday)).to eq(false) + end + + it 'returns true for holidays on a weekday' do + expect(subject.weekend_or_holiday?(a_thanksgiving)).to eq(true) + end + end + describe '.observed_holiday?' do subject { described_class.observed_holiday?(date) } diff --git a/spec/services/undeliverable_address_notifier_spec.rb b/spec/services/undeliverable_address_notifier_spec.rb index 089fdb951d4..dd7717e65dd 100644 --- a/spec/services/undeliverable_address_notifier_spec.rb +++ b/spec/services/undeliverable_address_notifier_spec.rb @@ -70,7 +70,8 @@ def mock_data end def download_folder - File.join(AppConfig.env.usps_download_sftp_directory, 'batch.psv') + timestamp = Time.zone.now.strftime('%Y%m%d') + File.join(AppConfig.env.usps_download_sftp_directory, "batch#{timestamp}.psv") end def sftp_options diff --git a/spec/services/usps_confirmation_uploader_spec.rb b/spec/services/usps_confirmation_uploader_spec.rb index 7e421926381..b1317c14bd0 100644 --- a/spec/services/usps_confirmation_uploader_spec.rb +++ b/spec/services/usps_confirmation_uploader_spec.rb @@ -109,7 +109,8 @@ def sftp_options end def upload_folder - File.join(AppConfig.env.usps_upload_sftp_directory, 'batch.psv') + timestamp = Time.zone.now.strftime('%Y%m%d') + File.join(AppConfig.env.usps_upload_sftp_directory, "batch#{timestamp}.psv") end def write_permission