forked from peacecorps/medlink
/
twilio_controller_spec.rb
30 lines (23 loc) · 1.11 KB
/
twilio_controller_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require "rails_helper"
describe TwilioController do
Given(:twilio) { TwilioAccount.first }
Given(:phone) { FactoryGirl.create :phone }
context "with a valid sid", :vcr do
When(:result) { post :receive, AccountSid: twilio.sid, From: phone.number, To: twilio.number, Body: "help" }
Then { result.status == 200 }
And { SMS.outgoing.count == 1 }
And { SMS.outgoing.last.number == Phone.condense(phone.number) }
end
context "with a new phone number", :vcr do
Given(:number) { "+1 (555) 555-0123" }
When(:result) { post :receive, AccountSid: twilio.sid, From: number, To: twilio.number, Body: "help" }
Then { result.status == 200 }
And { SMS.outgoing.count == 1 }
And { SMS.outgoing.last.number == Phone.condense(number) }
end
context "with an invalid sid" do
When(:result) { post :receive, AccountSid: "1234", From: phone.number, To: twilio.number, Body: "help" }
Then { result.status == 400 }
And { SMS.outgoing.count == 0 }
end
end