require 'test_helper' class ShipwireTest < Test::Unit::TestCase def setup Base.mode = :test @shipwire = ShipwireService.new( :login => 'cody@example.com', :password => 'test' ) @options = { :warehouse => '01', :shipping_method => 'UPS Ground' } @address = { :name => 'Fred Brooks', :address1 => '1234 Penny Lane', :city => 'Jonsetown', :state => 'NC', :country => 'US', :zip => '23456', :email => 'buyer@jadedpallet.com' } @line_items = [ { :sku => '9999', :quantity => 25 } ] end def test_missing_login assert_raise(ArgumentError) do ShipwireService.new(:password => 'test') end end def test_missing_password assert_raise(ArgumentError) do ShipwireService.new(:login => 'cody') end end def test_missing_credentials assert_raise(ArgumentError) do ShipwireService.new(:password => 'test') end end def test_credentials_present assert_nothing_raised do ShipwireService.new( :login => 'cody', :password => 'test' ) end end def test_country_format xml = REXML::Document.new(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options)) country_node = REXML::XPath.first(xml, "//Country") assert_equal 'US', country_node.text end def test_no_tracking_numbers_available @shipwire.expects(:ssl_post).returns(successful_empty_tracking_response) response = @shipwire.fetch_tracking_numbers assert response.success? assert_equal Hash.new, response.tracking_numbers end def test_successful_tracking expected = { "2986" => "1ZW682E90326614239", "2987" => "1ZW682E90326795080" } @shipwire.expects(:ssl_post).returns(successful_tracking_response) response = @shipwire.fetch_tracking_numbers assert response.success? assert_equal "3", response.params["total_orders"] assert_equal "Test", response.params["status"] assert_equal "2", response.params["total_shipped_orders"] assert_equal expected, response.tracking_numbers end def test_successful_tracking_with_live_data @shipwire.expects(:ssl_post).returns(successful_live_tracking_response) response = @shipwire.fetch_tracking_numbers assert response.success? assert_equal "15", response.params["total_orders"] assert_equal "0", response.params["status"] assert_equal "13", response.params["total_shipped_orders"] assert_equal 13, response.tracking_numbers.size end def test_valid_credentials @shipwire.expects(:ssl_post).returns(successful_empty_tracking_response) assert @shipwire.valid_credentials? end def test_invalid_credentials @shipwire.expects(:ssl_post).returns(invalid_login_response) assert !@shipwire.valid_credentials? end private def successful_empty_tracking_response "\r\nTest" end def successful_tracking_response <<-XML Test 3 2 2006-04-28 20:35:45 XML end def successful_live_tracking_response <<-XML 0 15 13 XML end def invalid_login_response <<-XML Error Error with EmailAddress, valid email is required. There is an error in XML document. XML end end