Skip to content

Commit

Permalink
Additional unit tests added and passing. Decamelcased the startcallre…
Browse files Browse the repository at this point in the history
…cording method since we downcase all of the commands coming in.
  • Loading branch information
jsgoecke committed Oct 2, 2010
1 parent 655f82b commit 0486cb5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 33 deletions.
6 changes: 3 additions & 3 deletions lib/tropo-agitate.rb
Expand Up @@ -242,17 +242,17 @@ def method_missing(method, *args)
# - http://www.voip-info.org/wiki/view/Asterisk+cmd+MixMonitor
# Tropo: https://www.tropo.com/docs/scripting/startcallrecording.htm
#
# @param [Hash] options used to build the say
# @param [Hash] options used to build the startCallRecording
#
# @return [String] the response in AGI raw form
def monitor(options)
def monitor(options={})
@current_call.startCallRecording options[:args]['uri'], options[:args]
@agi_response + "0\n"
rescue => e
log_error(this_method, e)
end
alias :mixmonitor :monitor
alias :startCallRecording :monitor
alias :startcallrecording :monitor

##
# Initiates a playback to the Tropo call object for Speech Synthesis/TTS
Expand Down
4 changes: 3 additions & 1 deletion lib/tropo.rb
Expand Up @@ -54,9 +54,11 @@ def meetme(text, *rest); "meetme: #{text.inspect}, #{rest.inspect}"; end
def say(text, options); 'say response: text'; options; end
def setHeader(header, value); @headers[header] = value; end
def sipgetheader(calleridname); calleridname; end
def startCallRecording(uri, options); nil; end
def startCallRecording(uri, options); nil ; end
def stopCallRecording; nil; end
def state; 'RINGING'; end
def transfer(foo, bar); true; end
def record(uri, options); true; end
end

# Here for testing outside of Tropo, so we mock the $currentApp object
Expand Down
57 changes: 30 additions & 27 deletions spec/tropo-agitate_spec.rb
Expand Up @@ -16,16 +16,16 @@

@current_call = CurrentCall.new
$incomingCall = IncomingCall.new
@tropo_agi = TropoAGItate.new(@current_call, CurrentApp.new)
@tropo_agitate = TropoAGItate.new(@current_call, CurrentApp.new)
end

it "should create a TropoAGItate object" do
@tropo_agi.instance_of?(TropoAGItate).should == true
@tropo_agitate.instance_of?(TropoAGItate).should == true
end

it "should create a properly formatted initial message" do
agi_uri = URI.parse @tropo_agi.tropo_agi_config['agi']['uri_for_local_tests']
message = @tropo_agi.initial_message(agi_uri.host, agi_uri.port, agi_uri.path[1..-1])
agi_uri = URI.parse @tropo_agitate.tropo_agi_config['agi']['uri_for_local_tests']
message = @tropo_agitate.initial_message(agi_uri.host, agi_uri.port, agi_uri.path[1..-1])
@initial_message = <<-MSG
agi_network: yes
agi_network_script: #{agi_uri.path[1..-1]}
Expand Down Expand Up @@ -56,84 +56,87 @@
end

it "should parse arguments stripping quotes" do
result = @tropo_agi.parse_args('"Hello LSRC!"')
result = @tropo_agitate.parse_args('"Hello LSRC!"')
result[0].should == "Hello LSRC!"

result = @tropo_agi.parse_args('"{"prompt":"hi!","timeout":3}"')
result = @tropo_agitate.parse_args('"{"prompt":"hi!","timeout":3}"')
result.should == { "timeout" => 3, "prompt" => "hi!"}

result = @tropo_agi.parse_args('"1234","d",""')
result = @tropo_agitate.parse_args('"1234","d",""')

result[0].should == '1234'
result[1].should == 'd'
result[3].should == nil
end

it "should strip quotes from a string" do
@tropo_agi.strip_quotes('"foobar"').should == 'foobar'
@tropo_agitate.strip_quotes('"foobar"').should == 'foobar'
end

it "should handle commas in non JSON args" do
command = @tropo_agi.parse_command('EXEC playback "Hello, LRSC!"')
command = @tropo_agitate.parse_command('EXEC playback "Hello, LRSC!"')
command.should == { :action => "exec", :command => "playback", :args => ["Hello, LRSC!"] }
end

it "should extract the appropriate commands from AGI" do
command = @tropo_agi.parse_command('ANSWER')
command = @tropo_agitate.parse_command('ANSWER')
command.should == { :action => "answer" }

command = @tropo_agi.parse_command('HANGUP')
command = @tropo_agitate.parse_command('HANGUP')
command.should == { :action => "hangup" }

command = @tropo_agi.parse_command('EXEC playback "Hello LRSC!"')
command = @tropo_agitate.parse_command('EXEC playback "Hello LRSC!"')
command.should == { :action => "exec", :command => "playback", :args => ["Hello LRSC!"] }

command = @tropo_agi.parse_command('EXEC ask "{"prompt":"hi!","timeout":3}"')
command = @tropo_agitate.parse_command('EXEC ask "{"prompt":"hi!","timeout":3}"')
command.should == { :command => "ask", :action => "exec", :args => { "timeout" => 3, "prompt" => "hi!"} }

command = @tropo_agi.parse_command('EXEC Dial "sip:jsgoecke@yahoo.com","",""')
command = @tropo_agitate.parse_command('EXEC Dial "sip:jsgoecke@yahoo.com","",""')
command.should == { :command => "dial", :action => "exec", :args => ["sip:jsgoecke@yahoo.com", "", ""] }

command = @tropo_agi.parse_command('EXEC MeetMe "1234","d",""')
command = @tropo_agitate.parse_command('EXEC MeetMe "1234","d",""')
command.should == { :command => "meetme", :action => "exec", :args => ["1234", "d", ""] }

command = @tropo_agi.parse_command('SET CALLERID "9095551234"')
command = @tropo_agitate.parse_command('SET CALLERID "9095551234"')
command.should == { :command => "callerid", :action => "set", :args => ["9095551234"] }

command = @tropo_agi.parse_command('SET MYVAR "foobar"')
command = @tropo_agitate.parse_command('SET MYVAR "foobar"')
command.should == { :command => "myvar", :action => "set", :args => ["foobar"] }

command = @tropo_agi.parse_command('GET VARIABLE "myvar"')
command = @tropo_agitate.parse_command('GET VARIABLE "myvar"')
command.should == { :command => "variable", :action => "get", :args => ["myvar"] }

command = @tropo_agi.parse_command('EXEC monitor "{"method":"POST","uri":"http://localhost"}"')
command = @tropo_agitate.parse_command('EXEC monitor "{"method":"POST","uri":"http://localhost"}"')
command.should == { :command => "monitor", :action => "exec", :args => { 'method' => 'POST', 'uri' => 'http://localhost' } }

command = @tropo_agitate.parse_command('EXEC mixmonitor "{"method":"POST","uri":"http://localhost"}"')
command.should == { :command => "mixmonitor", :action => "exec", :args => { 'method' => 'POST', 'uri' => 'http://localhost' } }
end

it "should execute the command" do
command = @tropo_agi.execute_command('EXEC MeetMe "1234","d",""')
command = @tropo_agitate.execute_command('EXEC MeetMe "1234","d",""')
command.should == "200 result=0\n"

command = @tropo_agi.execute_command('SET CALLERID "9095551234"')
command = @tropo_agitate.execute_command('SET CALLERID "9095551234"')
command.should == "200 result=0\n"

command = @tropo_agi.execute_command('SET CALLERIDNAME "John Denver"')
command = @tropo_agitate.execute_command('SET CALLERIDNAME "John Denver"')
command.should == "200 result=0\n"

command = @tropo_agi.execute_command('GET VARIABLE "CALLERIDNAME"')
command = @tropo_agitate.execute_command('GET VARIABLE "CALLERIDNAME"')
command.should == "200 result=1 (John Denver)\n"

command = @tropo_agi.execute_command('SET VARIABLE FOOBAR "green"')
command = @tropo_agitate.execute_command('SET VARIABLE FOOBAR "green"')
command.should == "200 result=0\n"

command = @tropo_agi.execute_command('GET VARIABLE "FOOBAR"')
command = @tropo_agitate.execute_command('GET VARIABLE "FOOBAR"')
command.should == "200 result=1 (green)\n"


command = @tropo_agi.execute_command("EXEC monitor #{{ 'method' => 'POST', 'uri' => 'http://localhost' }.to_json}")
command = @tropo_agitate.execute_command("EXEC monitor #{{ 'method' => 'POST', 'uri' => 'http://localhost' }.to_json}")
command.should == "200 result=0\n"

command = @tropo_agi.execute_command("EXEC mixmonitor #{{ 'method' => 'POST', 'uri' => 'http://localhost' }.to_json}")
command = @tropo_agitate.execute_command("EXEC mixmonitor #{{ 'method' => 'POST', 'uri' => 'http://localhost' }.to_json}")
command.should == "200 result=0\n"
end
end
25 changes: 23 additions & 2 deletions spec/tropo-commands_spec.rb
Expand Up @@ -13,8 +13,8 @@
# Register the hosted JSON file
FakeWeb.register_uri(:get, "http://hosting.tropo.com/49767/www/audio/asterisk_sounds/asterisk_sounds.json",
:body => '{"tt-monkeys":"tt-monkeys.gsm"}')
@tropo_agi = TropoAGItate.new(@current_call, CurrentApp.new)
@tropo_commands = TropoAGItate::Commands.new(CurrentCall.new, @tropo_agi.tropo_agi_config)
@tropo_agitate = TropoAGItate.new(@current_call, CurrentApp.new)
@tropo_commands = TropoAGItate::Commands.new(CurrentCall.new, @tropo_agitate.tropo_agi_config)
end

it "should return the asterisk sound files" do
Expand Down Expand Up @@ -76,4 +76,25 @@
options = { :args => ["\"1234\"|\"d\"|\"\""] }
@tropo_commands.meetme(options).should == "200 result=0\n"
end

it "should return a valid string when we request a record" do
options ={ :args => ['"http://tropo-audiofiles-to-s3.heroku.com/post_audio_to_s3?filename=voicemail" "mp3" "#" "120000" "0" "BEEP" "s=5"'] }
@tropo_commands.record(options).should == "200 result=0\n"
end

it "should return a valid string when we reqeust a monitor/mixmonitor/startcallrecording" do
options = { :args => { "uri" => "http://localhost/post_audio_to_s3?filename=voicemail.mp3",
"method" => "POST",
"format" => "mp3",
"transcriptionOutURI" => "mailto:jsgoecke@voxeo.com"} }
@tropo_commands.monitor(options).should == "200 result=0\n"
@tropo_commands.mixmonitor(options).should == "200 result=0\n"
@tropo_commands.startcallrecording(options).should == "200 result=0\n"
end

it "should return a valid string when we request a stopcallrecording" do
@tropo_commands.stopcallrecording.should == "200 result=0\n"
@tropo_commands.monitor_stop.should == "200 result=0\n"
@tropo_commands.mixmonitor_stop.should == "200 result=0\n"
end
end

0 comments on commit 0486cb5

Please sign in to comment.