|
|
|
|
@ -105,47 +105,77 @@ RSpec.describe AttemptsController, type: :controller do
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with stop params' do
|
|
|
|
|
let(:twilio_attributes) {
|
|
|
|
|
{'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+0000000000','To' => '2223334444','Body' => 'sToP','NumMedia' => '0'}
|
|
|
|
|
}
|
|
|
|
|
['stOp', 'cANcel', 'QuIt', 'no'].each do |command|
|
|
|
|
|
context "with #{command} command" do
|
|
|
|
|
let(:twilio_attributes) {
|
|
|
|
|
{'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+0000000000','To' => '2223334444','Body' => command,'NumMedia' => '0'}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it "updates the last attempt by recipient phone number" do
|
|
|
|
|
post :twilio, params: twilio_attributes
|
|
|
|
|
attempt.reload
|
|
|
|
|
expect(attempt.answer_index).to be_nil
|
|
|
|
|
expect(attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml)
|
|
|
|
|
expect(attempt.recipient).to be_opted_out
|
|
|
|
|
end
|
|
|
|
|
it "updates the last attempt by recipient phone number" do
|
|
|
|
|
post :twilio, params: twilio_attributes
|
|
|
|
|
attempt.reload
|
|
|
|
|
expect(attempt.answer_index).to be_nil
|
|
|
|
|
expect(attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml)
|
|
|
|
|
expect(attempt.recipient).to be_opted_out
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends back a message" do
|
|
|
|
|
post :twilio, params: twilio_attributes
|
|
|
|
|
expect(response.body).to eq('Thank you, you have been opted out of these messages and will no longer receive them.')
|
|
|
|
|
it "sends back a message" do
|
|
|
|
|
post :twilio, params: twilio_attributes
|
|
|
|
|
expect(response.body).to eq('Thank you, you have been opted out of these messages and will no longer receive them.')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with skip params' do
|
|
|
|
|
let(:twilio_skip_attributes) {
|
|
|
|
|
{'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+0000000000','To' => '2223334444','Body' => 'SkIP','NumMedia' => '0'}
|
|
|
|
|
}
|
|
|
|
|
['staRt', 'reSUme', 'rEstaRt', 'Yes', 'go'].each do |command|
|
|
|
|
|
context "with #{command} command" do
|
|
|
|
|
before :each do
|
|
|
|
|
attempt.recipient.update(opted_out: true)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "updates the last attempt by recipient phone number" do
|
|
|
|
|
post :twilio, params: twilio_skip_attributes
|
|
|
|
|
attempt.reload
|
|
|
|
|
expect(attempt.answer_index).to be_nil
|
|
|
|
|
expect(attempt.responded_at).to be_present
|
|
|
|
|
expect(attempt.twilio_details).to eq(twilio_skip_attributes.with_indifferent_access.to_yaml)
|
|
|
|
|
expect(attempt.recipient).to_not be_opted_out
|
|
|
|
|
let(:twilio_attributes) {
|
|
|
|
|
{'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+0000000000','To' => '2223334444','Body' => command,'NumMedia' => '0'}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
school_attempts = attempt.question.attempts.for_school(school)
|
|
|
|
|
expect(school_attempts.with_answer.count).to eq(0)
|
|
|
|
|
expect(school_attempts.with_no_answer.count).to eq(3)
|
|
|
|
|
expect(school_attempts.not_yet_responded.count).to eq(2)
|
|
|
|
|
it "updates the last attempt by recipient phone number" do
|
|
|
|
|
expect(attempt.recipient).to be_opted_out
|
|
|
|
|
post :twilio, params: twilio_attributes
|
|
|
|
|
attempt.reload
|
|
|
|
|
expect(attempt.answer_index).to be_nil
|
|
|
|
|
expect(attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml)
|
|
|
|
|
expect(attempt.recipient).to_not be_opted_out
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends back a message" do
|
|
|
|
|
post :twilio, params: twilio_attributes
|
|
|
|
|
expect(response.body).to eq('Thank you, you will now begin receiving messages again.')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends back a message" do
|
|
|
|
|
post :twilio, params: twilio_skip_attributes
|
|
|
|
|
expect(response.body).to eq('Thank you, this question has been skipped.')
|
|
|
|
|
['skip', 'i dont know', "i don't know", 'next'].each do |command|
|
|
|
|
|
context "with #{command} command" do
|
|
|
|
|
let(:twilio_skip_attributes) {
|
|
|
|
|
{'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+0000000000','To' => '2223334444','Body' => command,'NumMedia' => '0'}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it "updates the last attempt by recipient phone number" do
|
|
|
|
|
post :twilio, params: twilio_skip_attributes
|
|
|
|
|
attempt.reload
|
|
|
|
|
expect(attempt.answer_index).to be_nil
|
|
|
|
|
expect(attempt.responded_at).to be_present
|
|
|
|
|
expect(attempt.twilio_details).to eq(twilio_skip_attributes.with_indifferent_access.to_yaml)
|
|
|
|
|
expect(attempt.recipient).to_not be_opted_out
|
|
|
|
|
|
|
|
|
|
school_attempts = attempt.question.attempts.for_school(school)
|
|
|
|
|
expect(school_attempts.with_answer.count).to eq(0)
|
|
|
|
|
expect(school_attempts.with_no_answer.count).to eq(3)
|
|
|
|
|
expect(school_attempts.not_yet_responded.count).to eq(2)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends back a message" do
|
|
|
|
|
post :twilio, params: twilio_skip_attributes
|
|
|
|
|
expect(response.body).to eq('Thank you, this question has been skipped.')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|