spec/api_spec.rb in clickatell-0.2.0 vs spec/api_spec.rb in clickatell-0.3.0

- old
+ new

@@ -2,25 +2,32 @@ require File.dirname(__FILE__) + '/../lib/clickatell' module Clickatell describe "API Command" do + before do + @command = API::Command.new('cmdname') + end + it "should return encoded URL for the specified command and parameters" do - command = API::Command.new('cmdname') - url = command.with_params(:param_one => 'abc', :param_two => '123') + url = @command.with_params(:param_one => 'abc', :param_two => '123') url.should == URI.parse("http://api.clickatell.com/http/cmdname?param_one=abc&param_two=123") end it "should URL encode any special characters in parameters" do - command = API::Command.new('cmdname') - url = command.with_params(:param_one => 'abc', :param_two => 'hello world') + url = @command.with_params(:param_one => 'abc', :param_two => 'hello world') url.should == URI.parse("http://api.clickatell.com/http/cmdname?param_one=abc&param_two=hello%20world") end + end + + describe "Secure API Command" do + before do + @command = API::Command.new('cmdname', :secure => true) + end - it "should support non-secure api commands" do - command = API::Command.new('cmdname', :secure => true) - url = command.with_params(:param_one => 'abc', :param_two => '123') + it "should use HTTPS" do + url = @command.with_params(:param_one => 'abc', :param_two => '123') url.should == URI.parse("https://api.clickatell.com/http/cmdname?param_one=abc&param_two=123") end end describe "Command executor" do @@ -70,10 +77,32 @@ ).and_return(response=mock('response')) Response.should_receive(:parse).with(response).and_return('ID' => 'message_id') API.send_message('4477791234567', 'hello world', :session_id => 'abcde').should == 'message_id' end + it "should support sending messages with custom from number, returning the message id" do + API.should_receive(:execute_command).with('sendmsg', + :session_id => 'abcde', + :to => '4477791234567', + :text => 'hello world', + :from => 'LUKE' + ).and_return(response=mock('response')) + Response.should_receive(:parse).with(response).and_return('ID' => 'message_id') + API.send_message('4477791234567', 'hello world', {:session_id => 'abcde'}, :from => 'LUKE') + end + + it "should ignore any invalid parameters when sending message" do + API.should_receive(:execute_command).with('sendmsg', + :session_id => 'abcde', + :to => '4477791234567', + :text => 'hello world', + :from => 'LUKE' + ).and_return(response=mock('response')) + Response.stub!(:parse).and_return('ID' => 'foo') + API.send_message('4477791234567', 'hello world', {:session_id => 'abcde'}, :from => 'LUKE', :any_old_param => 'test') + end + it "should support message status query with authentication, returning message status" do API.should_receive(:execute_command).with('querymsg', :api_id => '1234', :user => 'joebloggs', :password => 'superpass', @@ -82,10 +111,10 @@ Response.should_receive(:parse).with(response).and_return('ID' => 'message_id', 'Status' => 'message_status') API.message_status('messageid', :username => 'joebloggs', :password => 'superpass', :api_key => '1234' ).should == 'message_status' end - + it "should support message status query with pre-auth" do API.should_receive(:execute_command).with('querymsg', :session_id => 'abcde', :apimsgid => 'messageid' ).and_return(response=mock('response')) \ No newline at end of file