nbudin-google4r-checkout 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGES +83 -0
  3. data/LICENSE +22 -0
  4. data/README +58 -0
  5. data/Rakefile +80 -0
  6. data/VERSION +1 -0
  7. data/lib/google4r/checkout/commands.rb +515 -0
  8. data/lib/google4r/checkout/frontend.rb +204 -0
  9. data/lib/google4r/checkout/merchant_calculation.rb +321 -0
  10. data/lib/google4r/checkout/notifications.rb +708 -0
  11. data/lib/google4r/checkout/shared.rb +1249 -0
  12. data/lib/google4r/checkout/utils.rb +94 -0
  13. data/lib/google4r/checkout/xml_generation.rb +920 -0
  14. data/lib/google4r/checkout.rb +34 -0
  15. data/test/frontend_configuration.rb +13 -0
  16. data/test/integration/checkout_command_test.rb +246 -0
  17. data/test/test_helper.rb +115 -0
  18. data/test/unit/add_merchant_order_number_command_test.rb +70 -0
  19. data/test/unit/add_tracking_data_command_test.rb +75 -0
  20. data/test/unit/address_test.rb +131 -0
  21. data/test/unit/anonymous_address_test.rb +75 -0
  22. data/test/unit/archive_order_command_test.rb +66 -0
  23. data/test/unit/area_test.rb +44 -0
  24. data/test/unit/authorization_amount_notification_test.rb +69 -0
  25. data/test/unit/authorize_order_command_test.rb +66 -0
  26. data/test/unit/backorder_items_command_test.rb +83 -0
  27. data/test/unit/callback_handler_test.rb +83 -0
  28. data/test/unit/cancel_items_command_test.rb +89 -0
  29. data/test/unit/cancel_order_command_test.rb +83 -0
  30. data/test/unit/carrier_calculated_shipping_test.rb +57 -0
  31. data/test/unit/charge_amount_notification_test.rb +64 -0
  32. data/test/unit/charge_order_command_test.rb +77 -0
  33. data/test/unit/chargeback_amount_notification_test.rb +65 -0
  34. data/test/unit/checkout_command_test.rb +125 -0
  35. data/test/unit/checkout_command_xml_generator_test.rb +218 -0
  36. data/test/unit/command_test.rb +116 -0
  37. data/test/unit/deliver_order_command_test.rb +70 -0
  38. data/test/unit/delivery_method_test.rb +42 -0
  39. data/test/unit/digital_content_test.rb +105 -0
  40. data/test/unit/flat_rate_shipping_test.rb +132 -0
  41. data/test/unit/frontend_test.rb +136 -0
  42. data/test/unit/item_info_test.rb +69 -0
  43. data/test/unit/item_test.rb +171 -0
  44. data/test/unit/marketing_preferences_test.rb +65 -0
  45. data/test/unit/merchant_calculated_shipping_test.rb +172 -0
  46. data/test/unit/merchant_calculation_callback_test.rb +137 -0
  47. data/test/unit/merchant_calculation_result_test.rb +78 -0
  48. data/test/unit/merchant_calculation_results_test.rb +178 -0
  49. data/test/unit/merchant_code_result_test.rb +51 -0
  50. data/test/unit/merchant_code_test.rb +122 -0
  51. data/test/unit/new_order_notification_test.rb +115 -0
  52. data/test/unit/notification_acknowledgement_test.rb +67 -0
  53. data/test/unit/notification_handler_test.rb +113 -0
  54. data/test/unit/order_adjustment_test.rb +119 -0
  55. data/test/unit/order_state_change_notification_test.rb +158 -0
  56. data/test/unit/pickup_shipping_test.rb +70 -0
  57. data/test/unit/postal_area_test.rb +71 -0
  58. data/test/unit/private_data_parser_test.rb +68 -0
  59. data/test/unit/refund_amount_notification_test.rb +65 -0
  60. data/test/unit/refund_order_command_test.rb +86 -0
  61. data/test/unit/reset_items_shipping_information_command_test.rb +83 -0
  62. data/test/unit/return_items_command_test.rb +83 -0
  63. data/test/unit/risk_information_notification_test.rb +98 -0
  64. data/test/unit/send_buyer_message_command_test.rb +73 -0
  65. data/test/unit/ship_items_command_test.rb +101 -0
  66. data/test/unit/shipping_adjustment_test.rb +100 -0
  67. data/test/unit/shopping_cart_test.rb +146 -0
  68. data/test/unit/tax_rule_test.rb +70 -0
  69. data/test/unit/tax_table_test.rb +82 -0
  70. data/test/unit/tracking_data_test.rb +54 -0
  71. data/test/unit/unarchive_order_command_test.rb +66 -0
  72. data/test/unit/us_country_area_test.rb +76 -0
  73. data/test/unit/us_state_area_test.rb +70 -0
  74. data/test/unit/us_zip_area_test.rb +66 -0
  75. data/test/unit/world_area_test.rb +48 -0
  76. data/test/xml/apiv2.xsd +997 -0
  77. data/test/xml/test_check_persisting_works_expected.xml +213 -0
  78. data/var/cacert.pem +7815 -0
  79. metadata +200 -0
@@ -0,0 +1,116 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/command_test.rb
4
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
5
+ # Copyright: (c) 2007 by Manuel Holtgrewe
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ require 'net/http'
35
+
36
+ require 'base64'
37
+
38
+ class TestCommand < Google4R::Checkout::Command
39
+ XML_REPRESENTATION = "<?xml version='1.0' ?><root />"
40
+
41
+ def to_xml
42
+ XML_REPRESENTATION
43
+ end
44
+ end
45
+
46
+ # Test for the class Command.
47
+ class Google4R::Checkout::CommandTest < Test::Unit::TestCase
48
+ include Google4R::Checkout
49
+
50
+ def setup
51
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
52
+ @frontend.tax_table_factory = TestTaxTableFactory.new
53
+ @command = TestCommand.new(@frontend)
54
+ end
55
+
56
+ def test_sending_fails_if_certificate_validation_fails
57
+ OpenSSL::SSL::SSLSocket.any_instance.stubs(:connect).raises(OpenSSL::SSL::SSLError, 'certificate verify failed')
58
+
59
+ assert_raises(OpenSSL::SSL::SSLError) { @command.send_to_google_checkout }
60
+ end
61
+
62
+ def test_instantiate_abstract_class
63
+ assert_raises(RuntimeError) { Command.new(Frontend.new(FRONTEND_CONFIGURATION)) }
64
+ assert_raises(RuntimeError) { ItemsCommand.new(Frontend.new(FRONTEND_CONFIGURATION)) }
65
+ end
66
+
67
+ def test_unknown_xml_response_in_body_raises_runtime_error
68
+ mock_body = '<?xml version="1.0" ?><unexpected-tag />'
69
+
70
+ success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
71
+ success_response.expects(:body).returns(mock_body)
72
+
73
+ Net::HTTP.any_instance.stubs(:request).returns(success_response)
74
+
75
+ assert_raises(RuntimeError) { @command.send_to_google_checkout }
76
+ end
77
+
78
+ def test_invalid_response_code_raises_runtime_error
79
+ unknown_response = mock()
80
+ unknown_response.expects(:code)
81
+ unknown_response.expects(:message)
82
+
83
+ Net::HTTP.any_instance.stubs(:request).returns(unknown_response)
84
+
85
+ assert_raises(RuntimeError) { @command.send_to_google_checkout }
86
+ end
87
+
88
+ def test_error_tag_in_response_code_raises_google_checkout_error
89
+ mock_body = '<?xml version="1.0" encoding="UTF-8"?><error xmlns="http://checkout.google.com/schema/2" serial-number="foo-bar"><error-message>Malformed URL component: expected id: (\d{10})|(\d{15}), but got something-different</error-message></error>'
90
+
91
+ error_response = Net::HTTPClientError.new(Net::HTTP.version_1_2, 400, "Bad Request")
92
+ error_response.expects(:body).returns(mock_body)
93
+
94
+ Net::HTTP.any_instance.stubs(:request).returns(error_response)
95
+
96
+ assert_raises(GoogleCheckoutError) { @command.send_to_google_checkout }
97
+ end
98
+
99
+ def test_send_to_google_checkout_works_correctly_if_200_is_returned
100
+ mock_body = '<?xml version="1.0" encoding="UTF-8"?><checkout-redirect xmlns="http://checkout.google.com/schema/2" serial-number="foo-bar"><redirect-url>https://sandbox.google.com/checkout/view/buy?o=shoppingcart&amp;shoppingcart=foo-bar</redirect-url></checkout-redirect>'
101
+
102
+ success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
103
+ success_response.expects(:body).returns(mock_body)
104
+
105
+ Net::HTTP.any_instance.stubs(:request).returns(success_response)
106
+
107
+ Net::HTTP::Post.any_instance.expects(:basic_auth).with(FRONTEND_CONFIGURATION[:merchant_id],
108
+ FRONTEND_CONFIGURATION[:merchant_key])
109
+
110
+ result = @command.send_to_google_checkout
111
+
112
+ assert_kind_of CheckoutRedirectResponse, result
113
+ assert_equal 'foo-bar', result.serial_number
114
+ assert_equal 'https://sandbox.google.com/checkout/view/buy?o=shoppingcart&shoppingcart=foo-bar', result.redirect_url
115
+ end
116
+ end
@@ -0,0 +1,70 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/deliver_order_command_test.rb
4
+ # Author: Dan Dukeson <dandukeson at gmail dot com>
5
+ # Copyright: (c) 2007 by Dan Dukeson
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Tests for the DeliverOrderCommand class.
35
+ class Google4R::Checkout::DeliverOrderCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_deliver_order_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.send_email = true
44
+
45
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
46
+ <deliver-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
47
+ <send-email>true</send-email>
48
+ </deliver-order>}
49
+ end
50
+
51
+ def test_behaves_correctly
52
+ [ :google_order_number, :send_email ].each do |symbol|
53
+ assert_respond_to @command, symbol
54
+ end
55
+ end
56
+
57
+ def test_xml_send_email
58
+ assert_strings_equal(@sample_xml, @command.to_xml)
59
+ end
60
+
61
+ def test_accessors
62
+ assert_equal('841171949013218', @command.google_order_number)
63
+ assert @command.send_email
64
+ end
65
+
66
+ def test_to_xml_does_not_raise_exception
67
+ assert_nothing_raised { @command.to_xml }
68
+ end
69
+
70
+ end
@@ -0,0 +1,42 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/shipping_method_test.rb
4
+ # Authors: Manuel Holtgrewe <purestorm at ggnore dot net>
5
+ # Tony Chan <api.htchan at gmail dot com>
6
+ # Copyright: (c) 2007 by Manuel Holtgrewe
7
+ # License: MIT License as follows:
8
+ #
9
+ # Permission is hereby granted, free of charge, to any person obtaining
10
+ # a copy of this software and associated documentation files (the
11
+ # "Software"), to deal in the Software without restriction, including
12
+ # without limitation the rights to use, copy, modify, merge, publish,
13
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
14
+ # persons to whom the Software is furnished to do so, subject to the
15
+ # following conditions:
16
+ #
17
+ # The above copyright notice and this permission notice shall be included
18
+ # in all copies or substantial portions of the Software.
19
+ #
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ #++
28
+
29
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
30
+
31
+ require 'google4r/checkout'
32
+
33
+ require 'test/frontend_configuration'
34
+
35
+ # Test for the ShippingMethod class.
36
+ class Google4R::Checkout::DeliveryMethodTest < Test::Unit::TestCase
37
+ include Google4R::Checkout
38
+
39
+ def test_shipping_method_raises_runtime_error_on_initialisation
40
+ assert_raises(RuntimeError) { DeliveryMethod.new }
41
+ end
42
+ end
@@ -0,0 +1,105 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/digital_content_test.rb
4
+ # Author: Tony Chan <api.htchan at gmail dot com>
5
+ # Copyright: (c) 2007 by Dan Dukeson
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Tests for the ShipItemsCommand class.
35
+ class Google4R::Checkout::DigitalContentTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @frontend.tax_table_factory = TestTaxTableFactory.new
41
+
42
+ @email_delivery_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
43
+ <digital-content>
44
+ <display-disposition>OPTIMISTIC</display-disposition>
45
+ <email-delivery>true</email-delivery>
46
+ </digital-content>}
47
+
48
+ @key_url_delivery_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
49
+ <digital-content>
50
+ <display-disposition>PESSIMISTIC</display-disposition>
51
+ <description>
52
+ Please go to &amp;lt;a href=&quot;http://supersoft.example.com&quot;&amp;gt;our website&amp;lt;/a&amp;gt;,
53
+ and enter your access key so that you can download our software.
54
+ </description>
55
+ <key>1456-1514-3657-2198</key>
56
+ <url>http://supersoft.example.com</url>
57
+ </digital-content>}
58
+
59
+ @description_delivery_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
60
+ <digital-content>
61
+ <display-disposition>OPTIMISTIC</display-disposition>
62
+ <description>
63
+ It may take up to 24 hours to process your new storage. You will
64
+ be able to see your increased storage on your
65
+ &amp;lt;a href=&quot;http://login.example.com&quot;&amp;gt;account page&amp;lt;/a&amp;gt;.
66
+ </description>
67
+ </digital-content>}
68
+
69
+
70
+ @optional_tags = [ 'merchant-item-id', 'merchant-private-item-data', 'tax-table-selector' ]
71
+
72
+ @command = @frontend.create_checkout_command
73
+ @shopping_cart = @command.shopping_cart
74
+ @item = @shopping_cart.create_item
75
+ @item.create_digital_content
76
+ end
77
+
78
+ def test_behaves_correctly
79
+ [ :description, :description=, :display_disposition,
80
+ :display_disposition=, :email_delivery,
81
+ :email_delivery=, :key, :key=, :url, :url= ].each do |symbol|
82
+ assert_respond_to @item.digital_content, symbol
83
+ end
84
+ end
85
+
86
+ def test_create_from_element_works
87
+ digital_content = Item::DigitalContent.create_from_element(REXML::Document.new(@email_delivery_str).root)
88
+ assert_equal 'OPTIMISTIC', digital_content.display_disposition
89
+ assert_equal "true", digital_content.email_delivery
90
+
91
+ digital_content = Item::DigitalContent.create_from_element(REXML::Document.new(@key_url_delivery_str).root)
92
+ assert_equal 'PESSIMISTIC', digital_content.display_disposition
93
+ assert_nil digital_content.email_delivery
94
+ assert_equal '1456-1514-3657-2198', digital_content.key
95
+ assert_equal 'http://supersoft.example.com', digital_content.url
96
+
97
+ digital_content = Item::DigitalContent.create_from_element(REXML::Document.new(@description_delivery_str).root)
98
+ assert_equal 'OPTIMISTIC', digital_content.display_disposition
99
+ assert_nospace_equal %q{It may take up to 24 hours to process your new
100
+ storage. You will be able to see your increased storage on your &amp;lt;a
101
+ href=&quot;http://login.example.com&quot;&amp;gt;account page&amp;lt;/a&amp;gt;.},
102
+ REXML::Text.new(digital_content.description).to_s
103
+ end
104
+
105
+ end
@@ -0,0 +1,132 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/flat_rate_shipping_test.rb
4
+ # Authors: Manuel Holtgrewe <purestorm at ggnore dot net>
5
+ # Tony Chan <api.htchan at gmail dot com>
6
+ # Copyright: (c) 2007 by Manuel Holtgrewe
7
+ # License: MIT License as follows:
8
+ #
9
+ # Permission is hereby granted, free of charge, to any person obtaining
10
+ # a copy of this software and associated documentation files (the
11
+ # "Software"), to deal in the Software without restriction, including
12
+ # without limitation the rights to use, copy, modify, merge, publish,
13
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
14
+ # persons to whom the Software is furnished to do so, subject to the
15
+ # following conditions:
16
+ #
17
+ # The above copyright notice and this permission notice shall be included
18
+ # in all copies or substantial portions of the Software.
19
+ #
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ #++
28
+
29
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
30
+
31
+ require 'google4r/checkout'
32
+
33
+ require 'test/frontend_configuration'
34
+
35
+ # Test for the FlatRateShipping class.
36
+ class Google4R::Checkout::FlatRateShippingMethodTest < Test::Unit::TestCase
37
+ include Google4R::Checkout
38
+
39
+ def setup
40
+ @shipping = FlatRateShipping.new
41
+ end
42
+
43
+ def test_flat_rate_shipping_method_behaves_correctly
44
+ [ :name, :name=, :price, :price=,
45
+ :shipping_restrictions_allowed_areas, :shipping_restrictions_excluded_areas,
46
+ :create_allowed_area, :create_excluded_area, :create_area
47
+ ].each do |symbol|
48
+ assert_respond_to @shipping, symbol
49
+ end
50
+ end
51
+
52
+ def test_initialization
53
+ assert_nil @shipping.name
54
+ assert_nil @shipping.price
55
+ assert_equal [], @shipping.shipping_restrictions_allowed_areas
56
+ assert_equal [], @shipping.shipping_restrictions_excluded_areas
57
+ end
58
+
59
+ def test_flat_rate_shipping_method_setting_attributes_works_correctly
60
+ @shipping.name = "Shipping Method Name"
61
+ assert_equal "Shipping Method Name", @shipping.name
62
+
63
+ @shipping.price = Money.new(100, "EUR")
64
+ assert_kind_of Money, @shipping.price
65
+ assert_equal 100, @shipping.price.cents
66
+ assert_equal "EUR", @shipping.price.currency
67
+ end
68
+
69
+ def test_flat_rate_shipping_method_price_is_validated
70
+ # Test that FlatRateShippingMethod checks for its price attribute responding
71
+ # to cents and currency.
72
+ assert_raises(RuntimeError) { @shipping.price = nil }
73
+ assert_raises(RuntimeError) { @shipping.price = 10 }
74
+ assert_raises(RuntimeError) { @shipping.price = "str" }
75
+ end
76
+
77
+ def test_create_allowed_excluded_areas_works_with_block
78
+ [ [ :shipping_restrictions_allowed_areas, :create_allowed_area],
79
+ [ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
80
+ read_sym, create_sym = pair
81
+
82
+ [ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
83
+
84
+ the_area = nil
85
+
86
+ res =
87
+ @shipping.send(create_sym, clazz) do |area|
88
+ the_area = area
89
+ assert_kind_of clazz, area
90
+ end
91
+
92
+ assert_equal res, the_area
93
+ assert @shipping.send(read_sym).include?(the_area)
94
+ end
95
+ end
96
+ end
97
+
98
+ def test_create_allowed_excluded_areas_works_without_block
99
+ [ [ :shipping_restrictions_allowed_areas, :create_allowed_area],
100
+ [ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
101
+ read_sym, create_sym = pair
102
+
103
+ [ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
104
+ area = @shipping.send(create_sym, clazz)
105
+
106
+ assert_kind_of clazz, area
107
+
108
+ assert @shipping.send(read_sym).include?(area)
109
+ end
110
+ end
111
+ end
112
+
113
+ def test_create_allowed_excluded_areas_validates_parameter
114
+ [ :create_allowed_area, :create_excluded_area ].each do |sym|
115
+ assert_raises(RuntimeError) { @shipping.send(sym, String) }
116
+ end
117
+ end
118
+
119
+ def test_new_create_area_with_flat_rate_shipping
120
+ [ [ :shipping_restrictions, :allowed_areas ],
121
+ [ :shipping_restrictions, :excluded_areas ] ].each do |pair|
122
+ type_sym, area_sym = pair
123
+ [ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
124
+ area = @shipping.send(:create_area, type_sym, area_sym, clazz)
125
+
126
+ assert_kind_of clazz, area
127
+
128
+ assert @shipping.send((type_sym.to_s + '_' + area_sym.to_s).to_sym).include?(area)
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,136 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/frontend_test.rb
4
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
5
+ # Copyright: (c) 2007 by Manuel Holtgrewe
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Test for the class Area and all of its subclasses.
35
+ class Google4R::Checkout::FrontendTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @frontend.tax_table_factory = TestTaxTableFactory.new
41
+ end
42
+
43
+ def test_initialized_correctly
44
+ assert_equal FRONTEND_CONFIGURATION.dup, @frontend.configuration
45
+ assert @frontend.configuration.frozen?
46
+ end
47
+
48
+ def test_frontend_behaves_correctly
49
+ [ :configuration, :tax_table_factory, :tax_table_factory=,
50
+ :create_notification_handler, :create_callback_handler,
51
+ :create_deliver_order_command, :create_charge_order_command,
52
+ :create_checkout_command, :create_cancel_order_command,
53
+ :create_refund_order_command, :create_send_buyer_message_command,
54
+ :create_authorize_order_command, :create_add_merchant_order_number_command,
55
+ :create_add_tracking_data_command, :create_archive_order_command,
56
+ :create_unarchive_order_command, :create_ship_items_command,
57
+ :create_backorder_items_command, :create_return_items_command,
58
+ :create_cancel_items_command, :create_reset_items_shipping_information_command
59
+ ].each do |symbol|
60
+ assert_respond_to @frontend, symbol
61
+ end
62
+ end
63
+
64
+ def test_create_notification_handler_works_correctly
65
+ assert_kind_of NotificationHandler, @frontend.create_notification_handler
66
+ end
67
+
68
+ def test_create_callback_handler_works_correctly
69
+ assert_kind_of CallbackHandler, @frontend.create_callback_handler
70
+ end
71
+
72
+ def test_create_deliver_order_command_works_correctly
73
+ assert_kind_of DeliverOrderCommand, @frontend.create_deliver_order_command
74
+ end
75
+
76
+ def test_create_charge_order_command_works_correctly
77
+ assert_kind_of ChargeOrderCommand, @frontend.create_charge_order_command
78
+ end
79
+
80
+ def test_create_checkout_command_works_correctly
81
+ assert_kind_of CheckoutCommand, @frontend.create_checkout_command
82
+ end
83
+
84
+ def test_create_cancel_order_command_works_correctly
85
+ assert_kind_of CancelOrderCommand, @frontend.create_cancel_order_command
86
+ end
87
+
88
+ def test_create_refund_order_command_works_correctly
89
+ assert_kind_of RefundOrderCommand, @frontend.create_refund_order_command
90
+ end
91
+
92
+ def test_create_send_buyer_message_command_works_correctly
93
+ assert_kind_of SendBuyerMessageCommand, @frontend.create_send_buyer_message_command
94
+ end
95
+
96
+ def test_create_authorize_order_command_works_correctly
97
+ assert_kind_of AuthorizeOrderCommand, @frontend.create_authorize_order_command
98
+ end
99
+
100
+ def test_create_add_merchant_order_number_command_works_correctly
101
+ assert_kind_of AddMerchantOrderNumberCommand, @frontend.create_add_merchant_order_number_command
102
+ end
103
+
104
+ def test_create_add_tracking_data_command_works_correctly
105
+ assert_kind_of AddTrackingDataCommand, @frontend.create_add_tracking_data_command
106
+ end
107
+
108
+ def test_create_archive_order_command_works_correctly
109
+ assert_kind_of ArchiveOrderCommand, @frontend.create_archive_order_command
110
+ end
111
+
112
+ def test_create_unarchive_order_command_works_correctly
113
+ assert_kind_of UnarchiveOrderCommand, @frontend.create_unarchive_order_command
114
+ end
115
+
116
+ def test_create_ship_items_command_works_correctly
117
+ assert_kind_of ShipItemsCommand, @frontend.create_ship_items_command
118
+ end
119
+
120
+ def test_create_backorder_items_command_works_correctly
121
+ assert_kind_of BackorderItemsCommand, @frontend.create_backorder_items_command
122
+ end
123
+
124
+ def test_create_return_items_command_works_correctly
125
+ assert_kind_of ReturnItemsCommand, @frontend.create_return_items_command
126
+ end
127
+
128
+ def test_create_cancel_items_command_works_correctly
129
+ assert_kind_of CancelItemsCommand, @frontend.create_cancel_items_command
130
+ end
131
+
132
+ def test_create_reset_items_shipping_information_command_works_correctly
133
+ assert_kind_of ResetItemsShippingInformationCommand, @frontend.create_reset_items_shipping_information_command
134
+ end
135
+
136
+ end
@@ -0,0 +1,69 @@
1
+ require 'google4r/checkout'
2
+
3
+ require 'test/frontend_configuration'
4
+ #--
5
+ # Project: google_checkout4r
6
+ # File: test/unit/item_info_test.rb
7
+ # Author: Tony Chan <api.htchan at gmail dot com>
8
+ # Copyright: (c) 2007 by Manuel Holtgrewe
9
+ # License: MIT License as follows:
10
+ #
11
+ # Permission is hereby granted, free of charge, to any person obtaining
12
+ # a copy of this software and associated documentation files (the
13
+ # "Software"), to deal in the Software without restriction, including
14
+ # without limitation the rights to use, copy, modify, merge, publish,
15
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
16
+ # persons to whom the Software is furnished to do so, subject to the
17
+ # following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be included
20
+ # in all copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
28
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ #++
30
+
31
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
32
+
33
+ require 'google4r/checkout'
34
+
35
+ require 'test/frontend_configuration'
36
+
37
+ # Test for the class ItemInfo.
38
+ class Google4R::Checkout::ItemInfoTest < Test::Unit::TestCase
39
+ include Google4R::Checkout
40
+
41
+ def setup
42
+ @item_info = ItemInfo.new('A1')
43
+ @item_info.create_tracking_data('UPS', '55555555')
44
+ @item_info.create_tracking_data('FedEx', '12345678')
45
+ end
46
+
47
+ def test_initialization_works
48
+ assert_kind_of ItemInfo, @item_info
49
+ end
50
+
51
+ def test_responds_correctly
52
+ [ :merchant_item_id, :tracking_data_arr].each do |sym|
53
+ assert_respond_to @item_info, sym
54
+ end
55
+ end
56
+
57
+ def test_merchant_item_id
58
+ assert_equal('A1', @item_info.merchant_item_id)
59
+ end
60
+
61
+ def test_tracking_data_arr
62
+ tracking_data = @item_info.tracking_data_arr[0]
63
+ assert_equal('UPS', tracking_data.carrier)
64
+ assert_equal('55555555', tracking_data.tracking_number)
65
+ tracking_data = @item_info.tracking_data_arr[1]
66
+ assert_equal('FedEx', tracking_data.carrier)
67
+ assert_equal('12345678', tracking_data.tracking_number)
68
+ end
69
+ end