Skip to content

Commit

Permalink
tests now use real callback and redirect data
Browse files Browse the repository at this point in the history
also renamed test objects for clarity
  • Loading branch information
capablemonkey committed Jun 8, 2013
1 parent 032065c commit f5e24ae
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 35 deletions.
4 changes: 2 additions & 2 deletions test/unit/integrations/dwolla_module_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ class DwollaModuleTest < Test::Unit::TestCase
include ActiveMerchant::Billing::Integrations

def test_notification_method
assert_instance_of Dwolla::Notification, Dwolla.notification('{"Amount": 0.01, "CheckoutId": "f32b1e55-9612-4b6d-90f9-1c1519e588da", "ClearingDate": "8/28/2012 3:17:18 PM", "Error": null, "OrderId": null, "Signature": "098d3f32654bd8eebc9db323228879fa2ea12459", "Status": "Completed", "TestMode": "false", "TransactionId": 1312616}', {:credential3 => 'mysecret'})
assert_instance_of Dwolla::Notification, Dwolla.notification('{"Amount":0.01,"OrderId":"abc123","Status":"Completed","Error":null,"TransactionId":3165397,"CheckoutId":"ac5b910a-7ec1-4b65-9f68-90449ed030f6","Signature":"7d4c5deaf9178faae7c437fd8693fc0b97b1b22b","TestMode":"false","ClearingDate":"6/8/2013 8:07:41 PM"}', {:credential3 => '62hdv0jBjsBlD+0AmhVn9pQuULSC661AGo2SsksQTpqNUrff7Z'})
end

def test_return
assert_instance_of Dwolla::Return, Dwolla.return("signature=098d3f32654bd8eebc9db323228879fa2ea12459&test=true&orderId=&amount=0.01&checkoutId=f32b1e55-9612-4b6d-90f9-1c1519e588da&status=Completed&clearingDate=8/28/2012%203:17:18%20PM&transaction=1312616&postback=success", {:credential3 => 'mysecret'})
assert_instance_of Dwolla::Return, Dwolla.return("signature=7d4c5deaf9178faae7c437fd8693fc0b97b1b22b&orderId=abc123&amount=0.01&checkoutId=ac5b910a-7ec1-4b65-9f68-90449ed030f6&status=Completed&clearingDate=6/8/2013%208:07:41%20PM&transaction=3165397&postback=success", {:credential3 => '62hdv0jBjsBlD+0AmhVn9pQuULSC661AGo2SsksQTpqNUrff7Z'})
end
end
36 changes: 18 additions & 18 deletions test/unit/integrations/notifications/dwolla_notification_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,52 @@ class DwollaNotificationTest < Test::Unit::TestCase
include ActiveMerchant::Billing::Integrations

def setup
@error_dwolla = Dwolla::Notification.new(http_raw_error_data, {:credential3 => 'mysecret'})
@dwolla = Dwolla::Notification.new(http_raw_success_data, {:credential3 => 'mysecret'})
@error_dwolla = Dwolla::Notification.new(http_raw_error_data, {:credential3 => '62hdv0jBjsBlD+0AmhVn9pQuULSC661AGo2SsksQTpqNUrff7Z'})
@success = Dwolla::Notification.new(http_raw_success_data, {:credential3 => '62hdv0jBjsBlD+0AmhVn9pQuULSC661AGo2SsksQTpqNUrff7Z'})
end

def test_success_accessors
assert @dwolla.complete?
assert_equal "1234asdfasd567", @dwolla.item_id
assert_equal "Completed", @dwolla.status
assert_equal 0.01, @dwolla.gross
assert_equal "USD", @dwolla.currency
assert @dwolla.test?
assert @success.complete?
assert_equal "abc123", @success.item_id
assert_equal "Completed", @success.status
assert_equal 0.01, @success.gross
assert_equal "USD", @success.currency
assert_false @success.test?
end

def test_error_accessors
assert_false @error_dwolla.complete?
assert_equal "order-1", @error_dwolla.item_id
assert_equal "abc123", @error_dwolla.item_id
assert_equal "Failed", @error_dwolla.status
assert_equal 0.01, @error_dwolla.gross
assert_equal 300.00, @error_dwolla.gross
assert_equal "USD", @error_dwolla.currency
assert_equal "Invalid Credentials", @error_dwolla.error
assert @error_dwolla.test?
assert_equal "Insufficient funds exist to complete the transaction.", @error_dwolla.error
assert_false @error_dwolla.test?
end

def test_compositions
assert_equal Money.new(1, 'USD'), @dwolla.amount
assert_equal Money.new(1, 'USD'), @success.amount
end

# Replace with real successful acknowledgement code
def test_acknowledgement
assert_equal true, @dwolla.acknowledge
assert_equal true, @success.acknowledge
end

def test_respond_to_acknowledge
assert @dwolla.respond_to?(:acknowledge)
assert @success.respond_to?(:acknowledge)
end

def test_raw_should_be_set
assert @dwolla.raw.present?
assert @success.raw.present?
end

private
def http_raw_error_data
%*{"Amount": 0.01, "CheckoutId": "f32b1e55-9612-4b6d-90f9-1c1519e588da", "ClearingDate": "8/28/2012 3:17:18 PM", "Error": "Invalid Credentials", "OrderId": "order-1", "Signature": "098d3f32654bd8eebc9db323228879fa2ea12459", "Status": "Failed", "TestMode": "false", "TransactionId": 1312616}*
%*{"Amount":300.00,"OrderId":"abc123","Status":"Failed","Error":"Insufficient funds exist to complete the transaction.","TransactionId":null,"CheckoutId":"a6129f18-2932-4c4f-ac36-4363aa2bd19b","Signature":"641ac3fb80566eb33c5f6bf3db282a8c9f912a71","TestMode":"false","ClearingDate":""}*
end

def http_raw_success_data
%*{"Amount": 0.01, "CheckoutId": "f32b1e55-9612-4b6d-90f9-1c1519e588da", "ClearingDate": "8/28/2012 3:17:18 PM", "Error": null, "OrderId": "1234asdfasd567", "Signature": "098d3f32654bd8eebc9db323228879fa2ea12459", "Status": "Completed", "TestMode": "false", "TransactionId": 1312616}*
%*{"Amount":0.01,"OrderId":"abc123","Status":"Completed","Error":null,"TransactionId":3165397,"CheckoutId":"ac5b910a-7ec1-4b65-9f68-90449ed030f6","Signature":"7d4c5deaf9178faae7c437fd8693fc0b97b1b22b","TestMode":"false","ClearingDate":"6/8/2013 8:07:41 PM"}*
end
end
44 changes: 29 additions & 15 deletions test/unit/integrations/returns/dwolla_return_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,50 @@ class DwollaReturnTest < Test::Unit::TestCase
include ActiveMerchant::Billing::Integrations

def setup
@failed_callback_dwolla = Dwolla::Return.new(http_raw_data_failed_callback, {:credential3 => 'mysecret'})
@dwolla = Dwolla::Return.new(http_raw_data_success, {:credential3 => 'mysecret'})
@checkout_failed = Dwolla::Return.new(http_raw_data_failed_checkout, {:credential3 => '62hdv0jBjsBlD+0AmhVn9pQuULSC661AGo2SsksQTpqNUrff7Z'})
@callback_failed = Dwolla::Return.new(http_raw_data_failed_callback, {:credential3 => '62hdv0jBjsBlD+0AmhVn9pQuULSC661AGo2SsksQTpqNUrff7Z'})
@success = Dwolla::Return.new(http_raw_data_success, {:credential3 => '62hdv0jBjsBlD+0AmhVn9pQuULSC661AGo2SsksQTpqNUrff7Z'})
end

def test_success_return
assert @success.success?
end

def test_success_accessors
assert_equal "ac5b910a-7ec1-4b65-9f68-90449ed030f6", @success.checkout_id
assert_equal "3165397", @success.transaction
assert_false @success.test?
end

def test_failed_callback_return
assert_false @failed_callback_dwolla.success?
assert_false @callback_failed.success?
end

def test_failed_callback_accessors
assert_equal "f32b1e55-9612-4b6d-90f9-1c1519e588da", @failed_callback_dwolla.checkout_id
assert_equal "1312616", @failed_callback_dwolla.transaction
assert @failed_callback_dwolla.test?
assert_equal "ac5b910a-7ec1-4b65-9f68-90449ed030f6", @callback_failed.checkout_id
assert_equal "3165397", @callback_failed.transaction
assert @callback_failed.test?
end

def test_success_return
assert @dwolla.success?
def test_checkout_failed_return
assert_false @callback_failed.success?
end

def test_success_accessors
assert_equal "f32b1e55-9612-4b6d-90f9-1c1519e588da", @dwolla.checkout_id
assert_equal "1312616", @dwolla.transaction
assert @dwolla.test?
def test_checkout_failed_accessors
assert_equal "failure", @checkout_failed.error
assert_equal "User Cancelled", @checkout_failed.error_description
end

private
def http_raw_data_success
"signature=098d3f32654bd8eebc9db323228879fa2ea12459&test=true&orderId=&amount=0.01&checkoutId=f32b1e55-9612-4b6d-90f9-1c1519e588da&status=Completed&clearingDate=8/28/2012%203:17:18%20PM&transaction=1312616&postback=success"
"signature=7d4c5deaf9178faae7c437fd8693fc0b97b1b22b&orderId=abc123&amount=0.01&checkoutId=ac5b910a-7ec1-4b65-9f68-90449ed030f6&status=Completed&clearingDate=6/8/2013%208:07:41%20PM&transaction=3165397&postback=success"
end

def http_raw_data_failed_callback
"signature=098d3f32654bd8eebc9db323228879fa2ea12459&test=true&orderId=&amount=0.01&checkoutId=f32b1e55-9612-4b6d-90f9-1c1519e588da&status=Completed&clearingDate=8/28/2012%203:17:18%20PM&transaction=1312616&postback=failure"
"signature=7d4c5deaf9178faae7c437fd8693fc0b97b1b22b&orderId=abc123&amount=0.01&checkoutId=ac5b910a-7ec1-4b65-9f68-90449ed030f6&status=Completed&clearingDate=6/8/2013%208:07:41%20PM&transaction=3165397&postback=failure&test=true"
end

def http_raw_data_failed_checkout
"error=failure&error_description=User+Cancelled"
end
end

0 comments on commit f5e24ae

Please sign in to comment.