spec/smsified_spec.rb in smsified-0.1.4 vs spec/smsified_spec.rb in smsified-0.1.5
- old
+ new
@@ -9,10 +9,34 @@
@password = 'pass'
@address = '14155551212'
@sender_address = '13035551212'
end
+ describe "Helpers" do
+ it 'Should camelcase the appropriate keys' do
+ class Foo
+ include Smsified::Helpers
+
+ attr_reader :keys
+
+ def initialize(hash)
+ @keys = camelcase_keys(hash)
+ end
+ end
+
+ camelcased_keys = Foo.new({ :destination_address => 'foo',
+ :notify_url => 'bar',
+ :client_correlator => 'baz',
+ :callback_data => 'donkey' }).keys
+
+ camelcased_keys[:destinationAddress].should eql 'foo'
+ camelcased_keys[:notifyURL].should eql 'bar'
+ camelcased_keys[:clientCorrelator].should eql 'baz'
+ camelcased_keys[:callbackData].should eql 'donkey'
+ end
+ end
+
describe "OneAPI" do
before(:all) do
@one_api = Smsified::OneAPI.new :username => @username, :password => @password, :debug => true
@message_sent = { "resourceReference" => { "resourceURL" => "https://api.smsified.com/v1/smsmessaging/outbound/tel%3A%2B#{@sender_address}/requests/795bd02c8e343b2dfd673b67dd0ee55a" } }
@@ -252,24 +276,24 @@
end
end
describe 'Updated subscriptions' do
before(:all) do
+ @inbound_subscription = { "resourceReference" => { "resourceURL" => "https://api.smsified.com/v1/smsmessaging/inbound/subscriptions/e636368b7fddac0e93e34ae03bad33dd" } }
@outbound_subscription = { "resourceReference" => { "resourceURL" => "https://api.smsified.com/v1/smsmessaging/outbound/subscriptions/4bc465cd394c9f5e78802af5ad6bb442" } }
FakeWeb.register_uri(:post,
"https://#{@username}:#{@password}@api.smsified.com/v1/smsmessaging/outbound/#{@sender_address}/subscriptions",
:status => ["200", "OK"],
:body => @outbound_subscription.to_json)
end
it 'Should update an inbound subscription' do
- pending('udpate resources being deployed')
result = @subscriptions.update_inbound_subscription('c880c96f161f6220d4977b29b4bfc111', :notify_url => 'http://foobar1.com')
result.http.code.should eql '200'
- result.data.should eql nil
+ result.data.should eql @inbound_subscription
end
it 'Should update an outbound subscription' do
result = @subscriptions.update_outbound_subscription(@sender_address, :notify_url => 'http://foobar.com')
result.http.code.should eql '200'
@@ -439,8 +463,39 @@
delivery_response = one_api.delivery_status :request_id => '795bd02c8e343b2dfd673b67dd0ee55a', :sender_address => @sender_address
delivery_response.data.should eql @delivery_status
sms_message = one_api.retrieve_sms '74ae6147f915eabf87b35b9ea30c5916'
sms_message.data.should eql @message
+ end
+ end
+
+ describe 'IncomingMessage' do
+ it 'Should parse an incoming message from SMSified' do
+ json = '{
+ "inboundSMSMessageNotification": {
+ "inboundSMSMessage": {
+ "dateTime": "2011-05-11T18:05:54.546Z",
+ "destinationAddress": "16575550100",
+ "message": "Inbound test",
+ "messageId": "ef795d3dac56a62fef3ff1852b0c123a",
+ "senderAddress": "14075550100"
+ }
+ }
+ }'
+
+ incoming_message = Smsified::IncomingMessage.new json
+ incoming_message.date_time.should eql Time.parse '2011-05-11T18:05:54.546Z'
+ incoming_message.destination_address.should eql '16575550100'
+ incoming_message.message.should eql 'Inbound test'
+ incoming_message.message_id.should eql 'ef795d3dac56a62fef3ff1852b0c123a'
+ incoming_message.sender_address.should eql '14075550100'
+ end
+
+ it "Should raise an error if JSON not passed" do
+ lambda { Smsified::IncomingMessage.new 'foobar' }.should raise_error(Smsified::IncomingMessage::MessageError)
+ end
+
+ it "Should raise an error if a different type than an IncomingMessage is passed" do
+ lambda { Smsified::IncomingMessage.new "{ 'foo': 'bar'}" }.should raise_error(Smsified::IncomingMessage::MessageError)
end
end
end