|
|
|
@ -2,37 +2,34 @@ require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
|
|
RSpec.describe RecipientSchedule, type: :model do
|
|
|
|
RSpec.describe RecipientSchedule, type: :model do
|
|
|
|
|
|
|
|
|
|
|
|
let(:question) { Question.create!(text: 'What is the question?', option1: 'A', option2: 'B', option3: 'C', option4: 'D', option5: 'E')}
|
|
|
|
let!(:school) { School.create!(name: 'School') }
|
|
|
|
let(:question_list) { QuestionList.create(name: 'Parent Questions', question_ids: "#{question.id},2,3")}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let(:recipient) { Recipient.create!(name: 'Parent', phone: '1112223333') }
|
|
|
|
let!(:recipient) { create_recipients(school, 1).first }
|
|
|
|
let(:recipient_list) { RecipientList.create(name: 'Parent List', recipient_ids: recipient.id.to_s)}
|
|
|
|
let!(:recipient_list) do
|
|
|
|
|
|
|
|
school.recipient_lists.create!(name: 'Parents', recipient_ids: "#{recipient.id}")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let!(:questions) { create_questions(3) }
|
|
|
|
|
|
|
|
let!(:question_list) do
|
|
|
|
|
|
|
|
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
let(:schedule) do
|
|
|
|
let!(:schedule) do
|
|
|
|
Schedule.create!(
|
|
|
|
Schedule.create!(
|
|
|
|
name: 'Parent Schedule',
|
|
|
|
name: 'Parent Schedule',
|
|
|
|
recipient_list_id: recipient_list.id,
|
|
|
|
recipient_list_id: recipient_list.id,
|
|
|
|
question_list: question_list,
|
|
|
|
question_list: question_list,
|
|
|
|
|
|
|
|
random: false,
|
|
|
|
frequency_hours: 24 * 7
|
|
|
|
frequency_hours: 24 * 7
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:recipient_schedule) { schedule.recipient_schedules.for(recipient).first }
|
|
|
|
let!(:recipient_schedule) do
|
|
|
|
|
|
|
|
RecipientSchedule.create!(
|
|
|
|
|
|
|
|
recipient: recipient,
|
|
|
|
|
|
|
|
schedule: schedule,
|
|
|
|
|
|
|
|
upcoming_question_ids: "#{question.id},3",
|
|
|
|
|
|
|
|
attempted_question_ids: '2',
|
|
|
|
|
|
|
|
last_attempt_at: 2.weeks.ago,
|
|
|
|
|
|
|
|
next_attempt_at: 2.weeks.ago + (60 * 60 * schedule.frequency_hours)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let!(:not_ready_recipient_schedule) do
|
|
|
|
let!(:not_ready_recipient_schedule) do
|
|
|
|
RecipientSchedule.create!(
|
|
|
|
RecipientSchedule.create!(
|
|
|
|
recipient: recipient,
|
|
|
|
recipient: recipient,
|
|
|
|
schedule: schedule,
|
|
|
|
schedule: schedule,
|
|
|
|
upcoming_question_ids: "#{question.id},3",
|
|
|
|
upcoming_question_ids: '1,3',
|
|
|
|
attempted_question_ids: '2',
|
|
|
|
attempted_question_ids: '2',
|
|
|
|
last_attempt_at: 1.day.ago,
|
|
|
|
last_attempt_at: 1.day.ago,
|
|
|
|
next_attempt_at: 1.day.ago + (60 * 60 * schedule.frequency_hours)
|
|
|
|
next_attempt_at: 1.day.ago + (60 * 60 * schedule.frequency_hours)
|
|
|
|
@ -50,7 +47,7 @@ RSpec.describe RecipientSchedule, type: :model do
|
|
|
|
|
|
|
|
|
|
|
|
describe 'next_question' do
|
|
|
|
describe 'next_question' do
|
|
|
|
it 'should provide the next question from the upcoming_question_ids list' do
|
|
|
|
it 'should provide the next question from the upcoming_question_ids list' do
|
|
|
|
expect(recipient_schedule.next_question).to eq(question)
|
|
|
|
expect(recipient_schedule.next_question).to eq(questions.first)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@ -66,17 +63,17 @@ RSpec.describe RecipientSchedule, type: :model do
|
|
|
|
expect(attempt.recipient).to eq(recipient)
|
|
|
|
expect(attempt.recipient).to eq(recipient)
|
|
|
|
expect(attempt.schedule).to eq(schedule)
|
|
|
|
expect(attempt.schedule).to eq(schedule)
|
|
|
|
expect(attempt.recipient_schedule).to eq(recipient_schedule)
|
|
|
|
expect(attempt.recipient_schedule).to eq(recipient_schedule)
|
|
|
|
expect(attempt.question).to eq(question)
|
|
|
|
expect(attempt.question).to eq(questions.first)
|
|
|
|
expect(attempt.sent_at.to_i).to eq(Time.new.to_i)
|
|
|
|
expect(attempt.sent_at.to_i).to eq(Time.new.to_i)
|
|
|
|
expect(attempt.answer_index).to be_nil
|
|
|
|
expect(attempt.answer_index).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it 'should update the upcoming_questions_ids' do
|
|
|
|
it 'should update the upcoming_questions_ids' do
|
|
|
|
expect(recipient_schedule.upcoming_question_ids).to eq('3')
|
|
|
|
expect(recipient_schedule.upcoming_question_ids).to eq(questions[1..2].map(&:id).join(','))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it 'should update the attempted_question_ids' do
|
|
|
|
it 'should update the attempted_question_ids' do
|
|
|
|
expect(recipient_schedule.attempted_question_ids).to eq("2,#{question.id}")
|
|
|
|
expect(recipient_schedule.attempted_question_ids).to eq(questions.first.id.to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it 'should update last_attempt_at' do
|
|
|
|
it 'should update last_attempt_at' do
|
|
|
|
|