Skip to content

Commit

Permalink
Added some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamjwc authored and Cody Fauser committed Oct 2, 2009
1 parent 343048a commit 0761e6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
9 changes: 4 additions & 5 deletions lib/active_merchant/billing/gateways/sallie_mae.rb
Expand Up @@ -78,7 +78,8 @@ def add_address(post, creditcard, options)
end

def add_invoice(post, options)
post[:ci_memo] = options[:description].to_s unless options[:description].blank?
memo = "OrderID: #{options[:order_id]}\nDescription: #{options[:description]}"
post[:ci_memo] = memo
end

def add_creditcard(post, creditcard)
Expand All @@ -104,21 +105,19 @@ def parse(body)
def commit(action, money, parameters)
parameters[:acctid] = @options[:account_id].to_s
parameters[:subid] = @options[:sub_id].to_s if @options[:sub_id].blank?
parameters[:amount] = "%.2f" % (money / 100.0)

case action
when :sale
parameters[:action] = "ns_quicksale_cc"
parameters[:amount] = "%.2f" % (money / 100.0)
when :authonly
parameters[:action] = "ns_quicksale_cc"
parameters[:authonly] = 1
parameters[:amount] = "%.2f" % (money / 100.0)
when :capture
parameters[:action] = "ns_quicksale_cc"
parameters[:amount] = "%.2f" % (money / 100.0)
end

response = parse(ssl_post(URL, parameters.to_post_data))
response = parse(ssl_post(URL, parameters.to_post_data) || "")
Response.new(successful?(response), message_from(response), {}, :authorization => response["refcode"])
end

Expand Down
13 changes: 4 additions & 9 deletions test/unit/gateways/sallie_mae_test.rb
Expand Up @@ -3,8 +3,7 @@
class SallieMaeTest < Test::Unit::TestCase
def setup
@gateway = SallieMaeGateway.new(
:login => 'login',
:password => 'password'
:account_id => 'FAKEACCOUNT'
)

@credit_card = credit_card
Expand All @@ -21,29 +20,25 @@ def test_successful_purchase
@gateway.expects(:ssl_post).returns(successful_purchase_response)

assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_instance_of
assert_success response

# Replace with authorization number from the successful response
assert_equal '', response.authorization
assert response.test?
end

def test_unsuccessful_request
@gateway.expects(:ssl_post).returns(failed_purchase_response)
@gateway.expects(:ssl_post).returns(failed_purcahse_response)

assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_failure response
assert response.test?
end

private

# Place raw successful response from gateway here
def successful_purchase_response
"Status=Accepted"
end

# Place raw failed response from gateway here
def failed_purcahse_response
"Status=Declined"
end
end

0 comments on commit 0761e6c

Please sign in to comment.