test/unit/gateway_test.rb in xero_gateway-float-2.0.18 vs test/unit/gateway_test.rb in xero_gateway-float-2.1.1
- old
+ new
@@ -4,32 +4,32 @@
include TestHelper
def setup
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
end
-
+
context "with error handling" do
-
+
should "handle token expired" do
XeroGateway::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("token_expired"), :code => "401"))
-
+
assert_raises XeroGateway::OAuth::TokenExpired do
@gateway.get_accounts
end
end
-
+
should "handle invalid request tokens" do
XeroGateway::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("invalid_request_token"), :code => "401"))
-
+
assert_raises XeroGateway::OAuth::TokenInvalid do
@gateway.get_accounts
end
end
-
+
should "handle invalid consumer key" do
XeroGateway::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("invalid_consumer_key"), :code => "401"))
-
+
assert_raises XeroGateway::OAuth::TokenInvalid do
@gateway.get_accounts
end
end
@@ -46,14 +46,14 @@
assert_raises XeroGateway::OAuth::UnknownError do
@gateway.get_accounts
end
end
-
+
should "handle ApiExceptions" do
XeroGateway::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => get_file_as_string("api_exception.xml"), :code => "400"))
-
+
assert_raises XeroGateway::ApiException do
@gateway.create_invoice(XeroGateway::Invoice.new)
end
end
@@ -84,21 +84,21 @@
should "handle random root elements" do
XeroGateway::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => "<RandomRootElement></RandomRootElement>", :code => "200"))
assert_raises XeroGateway::UnparseableResponse do
@gateway.create_invoice(XeroGateway::Invoice.new)
- end
+ end
end
-
+
end
-
+
def test_unknown_error_handling
if STUB_XERO_CALLS
@gateway.xero_url = "DUMMY_URL"
- @gateway.stubs(:http_get).with {|client, url, params| url =~ /Invoices\/AN_INVALID_ID$/ }.returns(get_file_as_string("unknown_error.xml"))
+ @gateway.stubs(:http_get).with {|client, url, params| url =~ /Invoices\/AN_INVALID_ID$/ }.returns(get_file_as_string("unknown_error.xml"))
end
-
+
result = @gateway.get_invoice("AN_INVALID_ID")
assert !result.success?
assert_equal 1, result.errors.size
assert !result.errors.first.type.nil?
assert !result.errors.first.description.nil?
@@ -107,10 +107,10 @@
def test_object_not_found_error_handling
if STUB_XERO_CALLS
@gateway.xero_url = "DUMMY_URL"
@gateway.stubs(:http_get).with {|client, url, params| url =~ /Invoices\/UNKNOWN_INVOICE_NO$/ }.returns(get_file_as_string("invoice_not_found_error.xml"))
end
-
+
result = @gateway.get_invoice("UNKNOWN_INVOICE_NO")
assert !result.success?
assert_equal 1, result.errors.size
assert_equal "Xero.API.Library.Exceptions.ObjectDoesNotExistException", result.errors.first.type
assert !result.errors.first.description.nil?