Permalink
Browse files

adding tests

  • Loading branch information...
1 parent 49212be commit 54759cfc0965fae212eecf94c1d8df510dd62a5a David Malin committed Aug 25, 2011
Showing with 105 additions and 5 deletions.
  1. +1 −1 lib/eztexting_rest/base.rb
  2. +5 −4 lib/eztexting_rest/voice.rb
  3. +99 −0 test/eztexting_rest_test.rb
@@ -21,7 +21,7 @@ def get(uri,parameters)
def delete(uri,options)
options = options.merge!('_method' => 'DELETE')
parameters = post_request_options(options)
- url = EztextingRest.base_uri + uri + "?" + parameters
+ url = EztextingRest.base_uri + uri
response = Curl::Easy.http_post(url)
return process(response.body_str)
@@ -6,11 +6,12 @@ def self.broadcast(opts={})
location = "/voicemessages/"
options = {
- 'phonenumbers' => phone_numbers,
- 'soundsource' => opts[:recording],
- 'callerid' => opts[:called_id]
+ 'phonenumbers' => opts[:numbers],
+ 'soundsource' => opts[:recording],
+ 'callerid' => opts[:caller_id],
+ 'soundfile' => opts[:soundfile]
}
-
+ puts options.inspect
processed_response = post(location,options)
end
@@ -0,0 +1,99 @@
+$:.unshift(File.dirname(__FILE__) + "../lib")
+
+require 'test/unit'
+require 'rubygems'
+require 'webmock/test_unit'
+require 'eztexting_rest'
+
+class EztextingRestTest < ActiveSupport::TestCase
+
+ def setup
+ # Stub All outbound requests to make sure tests do not hit api
+ stub_request(:any, /.*app.eztexting.com.*/)
+
+ @username = "Customer"
+ @password = "Secret"
+ EztextingRest.connect!(@username,@password)
+ end
+
+ test 'EztextingRest#credentials should store when connect! is run' do
+ assert_equal EztextingRest.credentials, {'User' => @username, 'Password' => @password}
+ end
+
+ test 'EztextingRest#base_uri should return as app.eztexting.com' do
+ assert_equal EztextingRest.base_uri, "https://app.eztexting.com"
+ end
+
+ test 'EztextingRest::Lookup# should call sending/phone-number/ with the phone number as part of the uri ' do
+ EztextingRest::Lookup.carrier("5551230987")
+ assert_requested :get, "https://app.eztexting.com/sending/phone-numbers/5551230987?Password=Secret&User=Customer&format=xml"
+ end
+
+ test 'EztextingRest::Credits#balance should make get request to billing/credits/get' do
+ EztextingRest::Credits.balance
+ assert_requested :get, "https://app.eztexting.com/billing/credits/get?Password=Secret&User=Customer&format=xml"
+ end
+
+ test 'EztextingRest::Credits#purchase should post to billing/credits' do
+ opts = {
+ :credits => 1, :coupon_code => "code", :first_name => "david", :last_name => "marks",
+ :address => "101 East 1st Ave", :city => "NY", :state => "NY",
+ :zip => '10015', :country => "USA", :card_type => "VISA", :number => '41473123123312',
+ :security_code => "121", :expiration_month => "11", :expiration_year => "2011"
+ }
+ EztextingRest::Credits.purchase(opts)
+ assert_requested :post, "https://app.eztexting.com/billing/credits"
+ end
+
+ test 'EztextingRest::Keyword#check should post to keywords/new' do
+ EztextingRest::Keywords.check("candy")
+ assert_requested :get, "https://app.eztexting.com/keywords/new?Keyword=candy&Password=Secret&User=Customer&format=xml"
+ end
+
+ test 'EztextingRest::Keyword#rent should post to /keywords' do
+ opts = {
+ :keyword => "Testing Coverage", :first_name => "david", :last_name => "marks",
+ :address => "101 East 1st Ave", :city => "NY", :state => "NY",
+ :zip => '10015', :country => "USA", :card_type => "VISA", :number => '41473123123312',
+ :security_code => "121", :expiration_month => "11", :expiration_year => "2011"
+ }
+ EztextingRest::Keywords.rent(opts)
+ assert_requested :post, "https://app.eztexting.com/keywords"
+ end
+
+ test 'EztextingRest::Keyword#configure should post to /keywords/<keyword>' do
+ options = {
+ :keyword => "foobar" , :enable_double_optin => "Y", :confirm_message => "configured", :join_message => "msg",
+ :forward_email => "none@none.com", :foward_url => "http://www.google.com", :contact_group_ids => "3"
+ }
+
+ EztextingRest::Keywords.configure(options)
+ assert_requested :post, "https://app.eztexting.com/keywords/foobar"
+ end
+
+ test 'EztextingRest::Keyword#cancel should post to /keywords/<keyword>' do
+ EztextingRest::Keywords.cancel("unused")
+ assert_requested :post, "https://app.eztexting.com/keywords/unused"
+ end
+
+ test 'EztextingRest::Sms#single should post to /sending/messages' do
+ opts = { 'PhoneNumbers[]'=>'5551239988', 'Subject'=>'Check it out', 'Message'=>'I am making an awesome application with this api!'}
+ EztextingRest::Sms.single(opts)
+ assert_requested :post, "https://app.eztexting.com/sending/messages"
+ end
+
+ test 'EztextingRest::Sms#multi should post to /sending/messages TWICE' do
+ opts = [
+ { 'PhoneNumbers[]'=>'5551239988', 'Subject'=>'Check it out', 'Message'=>'I am making an awesome application with this api!'},
+ { 'PhoneNumbers[]'=>'5551239988', 'Subject'=>'Check it out, AGAIN', 'Message'=>'I am making an awesome application with this api!'}
+ ]
+ EztextingRest::Sms.multi(opts)
+ assert_requested :post, "https://app.eztexting.com/sending/messages", :times => 2
+ end
+
+ test 'EztextingRest::Voice#broadcaset should post to /voicemessages' do
+ opts = {:numbers => "3213213124", :soundfile => "location_of_file", :srecording => "src", :caller_id => '21232121212'}
+ EztextingRest::Voice.broadcast(opts)
+ assert_requested :post, "https://app.eztexting.com/voicemessages/"
+ end
+end

0 comments on commit 54759cf

Please sign in to comment.