mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
moving weekend logic into the next_attempt_at logic in recipient_schedule
This commit is contained in:
parent
ac7858c5f6
commit
a2300a58b9
4 changed files with 32 additions and 12 deletions
|
|
@ -13,6 +13,7 @@ describe "survey:attempt_questions" do
|
|||
n += 1.day until n.on_weekday?
|
||||
return n
|
||||
}
|
||||
|
||||
let(:ready_recipient_schedule) { double('ready recipient schedule', attempt_question: nil) }
|
||||
let(:recipient_schedules) { double("recipient schedules", ready: [ready_recipient_schedule]) }
|
||||
let(:active_schedule) { double("active schedule", recipient_schedules: recipient_schedules) }
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ RSpec.describe RecipientSchedule, type: :model do
|
|||
recipient_list_id: recipient_list.id,
|
||||
question_list: question_list,
|
||||
random: false,
|
||||
frequency_hours: 24 * 7
|
||||
frequency_hours: 24
|
||||
)
|
||||
end
|
||||
let!(:recipient_schedule) { schedule.recipient_schedules.for(recipient).first }
|
||||
|
|
@ -32,8 +32,8 @@ RSpec.describe RecipientSchedule, type: :model do
|
|||
schedule: schedule,
|
||||
upcoming_question_ids: '1,3',
|
||||
attempted_question_ids: '2',
|
||||
last_attempt_at: 1.day.ago,
|
||||
next_attempt_at: 1.day.ago + (60 * 60 * schedule.frequency_hours)
|
||||
last_attempt_at: Date.today + (60 * 60 * schedule.frequency_hours),
|
||||
next_attempt_at: 1.day.from_now + (60 * 60 * schedule.frequency_hours)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
@ -73,7 +73,21 @@ RSpec.describe RecipientSchedule, type: :model do
|
|||
it 'should not do anything' do
|
||||
expect(attempt).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'right before a weekend' do
|
||||
before :each do
|
||||
friday_time = ActiveSupport::TimeZone["UTC"].parse('2017-04-21T20:00:00')
|
||||
Timecop.freeze()
|
||||
recipient_schedule.update_attributes(next_attempt_at: friday_time)
|
||||
end
|
||||
|
||||
let!(:attempt) { recipient_schedule.attempt_question }
|
||||
|
||||
it 'should schedule the next attempt for after the weekend' do
|
||||
next_weekday_time = ActiveSupport::TimeZone["UTC"].parse('2017-04-24T20:00:00')
|
||||
expect(recipient_schedule.reload.next_attempt_at).to eq(next_weekday_time)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an opted in recipient' do
|
||||
|
|
@ -103,10 +117,11 @@ RSpec.describe RecipientSchedule, type: :model do
|
|||
|
||||
it 'should update next_attempt_at' do
|
||||
now = DateTime.now
|
||||
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT16:00:00%z"))
|
||||
time = date.to_time.to_i + (60 * 60 * 24 * 7)
|
||||
date = ActiveSupport::TimeZone["Eastern Time (US & Canada)"].parse(now.strftime("%Y-%m-%dT16:00:00%z"))
|
||||
date += 1.day
|
||||
date += 1.day if date.on_weekend?
|
||||
|
||||
expect(recipient_schedule.next_attempt_at.to_i).to eq(time)
|
||||
expect(recipient_schedule.next_attempt_at).to eq(date.to_time)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue