Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/recurring_job/usps_upload_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class HolidayService
class CalendarService
# https://www.opm.gov/policy-data-oversight/snow-dismissal-procedures/federal-holidays

class << self
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/services/usps_confirmation_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/job_configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
)

Expand Down
2 changes: 1 addition & 1 deletion spec/config/initializers/job_configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe HolidayService do
RSpec.describe CalendarService do
let(:year) { 2018 }

let(:instance) { described_class.new(year) }
Expand Down Expand Up @@ -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) }

Expand All @@ -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) }

Expand Down
3 changes: 2 additions & 1 deletion spec/services/undeliverable_address_notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spec/services/usps_confirmation_uploader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down