From d3f6910dd7e6c3a71b25a79482cdf1e259933261 Mon Sep 17 00:00:00 2001 From: chris-teague Date: Fri, 23 Nov 2012 15:33:35 +1030 Subject: [PATCH] Added test coverage to chat command --- lib/fsr/cmd/chat.rb | 16 ++++++++++++---- spec/fsr/cmd/chat.rb | 6 +++--- spec/fsr/loading.rb | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/fsr/cmd/chat.rb b/lib/fsr/cmd/chat.rb index 66d16f6..f54187d 100644 --- a/lib/fsr/cmd/chat.rb +++ b/lib/fsr/cmd/chat.rb @@ -6,11 +6,19 @@ class Chat < Command attr_reader :fs_socket def initialize(fs_socket = nil, args = {}) + + raise(ArgumentError, "args (Passed: <<<#{args}>>>) must be a hash") unless args.kind_of?(Hash) + @fs_socket = fs_socket # FSR::CommandSocket obj @protocol = args[:protocol] ? args[:protocol] : 'sip' - @from = '1001' - @to = '1003@192.168.0.6' - @message = 'Oh, hello!' + raise(ArgumentError, "Cannot send chat with invalid protocol") unless @protocol.to_s.size > 0 + @from = args[:from] # i.e. 1000@192.168.1.1 + raise(ArgumentError, "Cannot send chat without :from set") unless @from.to_s.size > 0 + @to = args[:to] # i.e. 1001@192.168.1.1 + raise(ArgumentError, "Cannot send chat without :to set") unless @to.to_s.size > 0 + @message = args[:message] + raise(ArgumentError, "Cannot send chat without :message set") unless @message.to_s.size > 0 + @message.gsub!('|', '\|') end # Send the command to the event socket, using api by default. @@ -26,6 +34,6 @@ def raw end end - register(:chat, Chat) + register(:chat, Chat) end end \ No newline at end of file diff --git a/spec/fsr/cmd/chat.rb b/spec/fsr/cmd/chat.rb index 1f9144a..dbef89f 100644 --- a/spec/fsr/cmd/chat.rb +++ b/spec/fsr/cmd/chat.rb @@ -46,13 +46,13 @@ end it "Honours a more complex message" do - chat = FSR::Cmd::Chat.new(nil, :message => 'Hello, friendly sir. fƒø£0"f', :to => '1000@192.168.1.1', :from => '1001') - chat.raw.should == %Q(chat sip|1001|1000@192.168.1.1|Hello, friendly sir. fƒø£0"f) + chat = FSR::Cmd::Chat.new(nil, :message => 'Hello, friendly sir. "*/;{(\|/;,@#,/', :to => '1000@192.168.1.1', :from => '1001') + chat.raw.should == 'chat sip|1001|1000@192.168.1.1|Hello, friendly sir. "*/;{(\\\|/;,@#,/' end it "Escapes pipes from messages" do chat = FSR::Cmd::Chat.new(nil, :message => 'He||o there |ove|y', :to => '1000@192.168.1.1', :from => '1001') - chat.raw.should == "chat sip|1001|1000@192.168.1.1|He\|\|o there \|ove\|y" + chat.raw.should == %Q(chat sip|1001|1000@192.168.1.1|He\\|\\|o there \\|ove\\|y) end end \ No newline at end of file diff --git a/spec/fsr/loading.rb b/spec/fsr/loading.rb index b63f9c1..941ebad 100644 --- a/spec/fsr/loading.rb +++ b/spec/fsr/loading.rb @@ -16,7 +16,7 @@ # When you add commands you must modify the expected cmds_loaded behavior it "Loads all commands" do - all_commands = [:kill, :uuid_dump, :originate, :sofia, :fsctl, :sofia_contact, :status, :calls, :call_center, :channels, :enum, :sched_hangup, :sched_transfer, :uuid_transfer, :uuid_send_dtmf, :conference, :valet_info] # If you add a command add it to this set + all_commands = [:kill, :uuid_dump, :originate, :chat, :sofia, :fsctl, :sofia_contact, :status, :calls, :call_center, :channels, :enum, :sched_hangup, :sched_transfer, :uuid_transfer, :uuid_send_dtmf, :conference, :valet_info] # If you add a command add it to this set cmds_loaded = FSR.load_all_commands cmds_loaded.kind_of?(Array).should == true all_commands.each do |cmd|