google4r-checkout-jn 1.1.jniziol
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.
- data/CHANGES +136 -0
- data/LICENSE +22 -0
- data/README.md +72 -0
- data/lib/google4r/checkout.rb +34 -0
- data/lib/google4r/checkout/commands.rb +665 -0
- data/lib/google4r/checkout/frontend.rb +222 -0
- data/lib/google4r/checkout/merchant_calculation.rb +323 -0
- data/lib/google4r/checkout/notifications.rb +774 -0
- data/lib/google4r/checkout/shared.rb +1386 -0
- data/lib/google4r/checkout/utils.rb +94 -0
- data/lib/google4r/checkout/xml_generation.rb +1023 -0
- data/test/frontend_configuration_example.rb +13 -0
- data/test/integration/checkout_command_test.rb +261 -0
- data/test/test_helper.rb +105 -0
- data/test/unit/add_merchant_order_number_command_test.rb +65 -0
- data/test/unit/add_tracking_data_command_test.rb +68 -0
- data/test/unit/address_test.rb +131 -0
- data/test/unit/anonymous_address_test.rb +75 -0
- data/test/unit/archive_order_command_test.rb +63 -0
- data/test/unit/area_test.rb +44 -0
- data/test/unit/authorization_amount_notification_test.rb +69 -0
- data/test/unit/authorize_order_command_test.rb +63 -0
- data/test/unit/backorder_items_command_test.rb +69 -0
- data/test/unit/callback_handler_test.rb +83 -0
- data/test/unit/cancel_items_command_test.rb +76 -0
- data/test/unit/cancel_order_command_test.rb +74 -0
- data/test/unit/carrier_calculated_shipping_test.rb +57 -0
- data/test/unit/charge_amount_notification_test.rb +72 -0
- data/test/unit/charge_and_ship_order_command_test.rb +69 -0
- data/test/unit/charge_fee_test.rb +53 -0
- data/test/unit/charge_order_command_test.rb +69 -0
- data/test/unit/chargeback_amount_notification_test.rb +69 -0
- data/test/unit/checkout_command_test.rb +149 -0
- data/test/unit/checkout_command_xml_generator_test.rb +216 -0
- data/test/unit/command_test.rb +116 -0
- data/test/unit/deliver_order_command_test.rb +65 -0
- data/test/unit/delivery_method_test.rb +42 -0
- data/test/unit/digital_content_test.rb +105 -0
- data/test/unit/flat_rate_shipping_test.rb +133 -0
- data/test/unit/frontend_test.rb +144 -0
- data/test/unit/item_info_test.rb +69 -0
- data/test/unit/item_test.rb +171 -0
- data/test/unit/marketing_preferences_test.rb +65 -0
- data/test/unit/merchant_calculated_shipping_test.rb +173 -0
- data/test/unit/merchant_calculation_callback_test.rb +137 -0
- data/test/unit/merchant_calculation_result_test.rb +78 -0
- data/test/unit/merchant_calculation_results_test.rb +203 -0
- data/test/unit/merchant_code_result_test.rb +51 -0
- data/test/unit/merchant_code_test.rb +122 -0
- data/test/unit/new_order_notification_test.rb +115 -0
- data/test/unit/notification_acknowledgement_test.rb +67 -0
- data/test/unit/notification_handler_test.rb +113 -0
- data/test/unit/order_adjustment_test.rb +119 -0
- data/test/unit/order_report_command_test.rb +109 -0
- data/test/unit/order_state_change_notification_test.rb +158 -0
- data/test/unit/parameterized_url_test.rb +57 -0
- data/test/unit/pickup_shipping_test.rb +70 -0
- data/test/unit/postal_area_test.rb +71 -0
- data/test/unit/private_data_parser_test.rb +68 -0
- data/test/unit/refund_amount_notification_test.rb +67 -0
- data/test/unit/refund_order_command_test.rb +79 -0
- data/test/unit/reset_items_shipping_information_command_test.rb +69 -0
- data/test/unit/return_items_command_test.rb +69 -0
- data/test/unit/risk_information_notification_test.rb +98 -0
- data/test/unit/send_buyer_message_command_test.rb +68 -0
- data/test/unit/ship_items_command_test.rb +81 -0
- data/test/unit/shipping_adjustment_test.rb +100 -0
- data/test/unit/shopping_cart_test.rb +146 -0
- data/test/unit/tax_rule_test.rb +70 -0
- data/test/unit/tax_table_test.rb +88 -0
- data/test/unit/tracking_data_test.rb +54 -0
- data/test/unit/unarchive_order_command_test.rb +63 -0
- data/test/unit/url_parameter_test.rb +55 -0
- data/test/unit/us_country_area_test.rb +76 -0
- data/test/unit/us_state_area_test.rb +70 -0
- data/test/unit/us_zip_area_test.rb +66 -0
- data/test/unit/world_area_test.rb +48 -0
- data/var/cacert.pem +7815 -0
- metadata +230 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/send_buyer_message_command_test.rb
|
4
|
+
# Author: Tony Chan <api.htchan at gmail dot com>
|
5
|
+
# Copyright: (c) 2007 by Tony Chan
|
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 SendBuyerMessageCommand class.
|
35
|
+
class Google4R::Checkout::SendBuyerMessageCommandTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
40
|
+
@command = @frontend.create_send_buyer_message_command
|
41
|
+
|
42
|
+
@command.google_order_number = '841171949013218'
|
43
|
+
@command.message = 'Due to high volume, your order will ship next week. Thank you for your patience.'
|
44
|
+
@command.send_email = true
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_behaves_correctly
|
48
|
+
[ :google_order_number, :message, :send_email ].each do |symbol|
|
49
|
+
assert_respond_to @command, symbol
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_xml_send_email
|
54
|
+
assert_command_element_text_equals("true", "> send-email", @command)
|
55
|
+
assert_command_element_text_equals(@command.message, "> message", @command)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_accessors
|
59
|
+
assert_equal('841171949013218', @command.google_order_number)
|
60
|
+
assert_equal('Due to high volume, your order will ship next week. Thank you for your patience.', @command.message)
|
61
|
+
assert @command.send_email
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_to_xml_does_not_raise_exception
|
65
|
+
assert_nothing_raised { @command.to_xml }
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/ship_items_command_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::ShipItemsCommandTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
40
|
+
@command = @frontend.create_ship_items_command
|
41
|
+
|
42
|
+
@command.google_order_number = '841171949013218'
|
43
|
+
@command.send_email = true
|
44
|
+
@item_info_1 = ItemInfo.new('A1')
|
45
|
+
@item_info_1.create_tracking_data('UPS', 55555555)
|
46
|
+
@item_info_2 = ItemInfo.new('A2')
|
47
|
+
@item_info_2.create_tracking_data('FedEx', 12345678)
|
48
|
+
@command.item_info_arr = [@item_info_1, @item_info_2]
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_behaves_correctly
|
52
|
+
[ :google_order_number, :item_info_arr, :send_email,
|
53
|
+
:google_order_number=, :item_info_arr=, :send_email= ].each do |symbol|
|
54
|
+
assert_respond_to @command, symbol
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_xml_generation
|
59
|
+
assert_command_element_text_equals("true", "> send-email", @command)
|
60
|
+
@command.item_info_arr.each do |item_info|
|
61
|
+
selector = "> item-shipping-information-list > item-shipping-information"
|
62
|
+
item_info_elt = find_command_elements(selector, @command).select do |element|
|
63
|
+
element.css("item-id > merchant-item-id").first.text == item_info.merchant_item_id
|
64
|
+
end.first
|
65
|
+
|
66
|
+
selector = "tracking-data-list > tracking-data"
|
67
|
+
assert_equal item_info.tracking_data_arr.first.carrier, item_info_elt.css("#{selector} > carrier").first.text
|
68
|
+
assert_equal item_info.tracking_data_arr.first.tracking_number, item_info_elt.css("#{selector} > tracking-number").first.text
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_accessors
|
73
|
+
assert_equal('841171949013218', @command.google_order_number)
|
74
|
+
assert @command.send_email
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_to_xml_does_not_raise_exception
|
78
|
+
assert_nothing_raised { @command.to_xml }
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/shipping_adjustment_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 ShippingAdjustmentTest.
|
35
|
+
class Google4R::Checkout::ShippingAdjustmentTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
40
|
+
<%s>
|
41
|
+
<shipping-name>%s</shipping-name>
|
42
|
+
<shipping-cost currency="%s">%s</shipping-cost>
|
43
|
+
</%s>}
|
44
|
+
|
45
|
+
@valid_adjustment_types =
|
46
|
+
[
|
47
|
+
[ "FLAT_RATE", 'flat-rate-shipping-adjustment' ],
|
48
|
+
[ "PICKUP", 'pickup-shipping-adjustment' ],
|
49
|
+
]
|
50
|
+
|
51
|
+
@invalid_adjustment_types = [ 'merchant-calculated-shipping', 'invalid-shipping' ]
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_responds_correctly
|
55
|
+
adjustment = ShippingAdjustment.new
|
56
|
+
|
57
|
+
[ :type, :type=, :name, :name=, :cost, :cost= ].each do |symbol|
|
58
|
+
assert_respond_to adjustment, symbol
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_constants_are_defined
|
63
|
+
assert defined?(ShippingAdjustment::FLAT_RATE)
|
64
|
+
assert defined?(ShippingAdjustment::PICKUP)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_create_from_element_works_with_valid_shipping_adjustment_types
|
68
|
+
@valid_adjustment_types.each do |pair|
|
69
|
+
type, tag_name = pair
|
70
|
+
|
71
|
+
xml_str = @xml_str %
|
72
|
+
[
|
73
|
+
tag_name, 'Some Name', 'USD', '10.00', tag_name
|
74
|
+
]
|
75
|
+
|
76
|
+
element = REXML::Document.new(xml_str).root
|
77
|
+
|
78
|
+
adjustment = ShippingAdjustment.create_from_element(element)
|
79
|
+
|
80
|
+
assert_equal Money.new(1000, 'USD'), adjustment.cost
|
81
|
+
assert_equal type, adjustment.type
|
82
|
+
assert_equal 'Some Name', adjustment.name
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_create_from_element_raises_exception_with_invalid_shipping_adjustment_types
|
87
|
+
@invalid_adjustment_types.each do |tag_name|
|
88
|
+
xml_str = @xml_str %
|
89
|
+
[
|
90
|
+
tag_name, 'Some Name', 'USD', '10.00', tag_name
|
91
|
+
]
|
92
|
+
|
93
|
+
element = REXML::Document.new(xml_str).root
|
94
|
+
|
95
|
+
assert_raises(RuntimeError) do
|
96
|
+
adjustment = ShippingAdjustment.create_from_element(element)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/area_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
|
+
# Tests for the ShoppingCart class and all subclasses.
|
35
|
+
class Google4R::Checkout::ShoppingCartTest < 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
|
+
@command = @frontend.create_checkout_command
|
42
|
+
@shopping_cart = @command.shopping_cart
|
43
|
+
|
44
|
+
@xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
45
|
+
<shopping-cart>
|
46
|
+
<merchant-private-data>
|
47
|
+
<affiliate-code>01234</affiliate-code>
|
48
|
+
</merchant-private-data>
|
49
|
+
<cart-expiration>
|
50
|
+
<good-until-date>2007-12-31T23:59:59-05:00</good-until-date>
|
51
|
+
</cart-expiration>
|
52
|
+
<items>
|
53
|
+
<item>
|
54
|
+
<item-name>AA Rechargeable Battery Pack</item-name>
|
55
|
+
<item-description>Battery pack containing four AA rechargeable batteries</item-description>
|
56
|
+
<unit-price currency="USD">12.00</unit-price>
|
57
|
+
<quantity>1</quantity>
|
58
|
+
</item>
|
59
|
+
<item>
|
60
|
+
<item-name>MegaSound 2GB MP3 Player</item-name>
|
61
|
+
<item-description>Portable MP3 player - stores 500 songs</item-description>
|
62
|
+
<quantity>1</quantity>
|
63
|
+
<unit-price currency="USD">178.00</unit-price>
|
64
|
+
</item>
|
65
|
+
</items>
|
66
|
+
</shopping-cart>}
|
67
|
+
|
68
|
+
@optional_tags = [ 'cart-expiration', 'merchant-private-data' ]
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_behaves_correctly
|
72
|
+
[ :owner, :expires_at, :items, :owner, :private_data, :private_data= ].each do |sym|
|
73
|
+
assert_respond_to @shopping_cart, sym
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_initialized_correctly
|
78
|
+
assert_equal @command, @shopping_cart.owner
|
79
|
+
assert_equal nil, @shopping_cart.expires_at
|
80
|
+
assert_equal [], @shopping_cart.items
|
81
|
+
assert_equal @command, @shopping_cart.owner
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_accessors_work_correctly
|
85
|
+
hash = { 'foo' => [ { 'bar' => 'baz' }, "d'oh", 2 ] }
|
86
|
+
@shopping_cart.private_data = hash.dup
|
87
|
+
assert_equal hash, @shopping_cart.private_data
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_setting_private_data_only_works_with_a_hash
|
91
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = 1 }
|
92
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = nil }
|
93
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = 'Foobar' }
|
94
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = [] }
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_create_item_works_correctly_with_block
|
98
|
+
the_item = nil
|
99
|
+
|
100
|
+
res =
|
101
|
+
@shopping_cart.create_item do |item|
|
102
|
+
the_item = item
|
103
|
+
|
104
|
+
assert_kind_of Item, item
|
105
|
+
end
|
106
|
+
|
107
|
+
assert_equal res, the_item
|
108
|
+
assert @shopping_cart.items.include?(the_item)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_create_item_works_correctly_without_block
|
112
|
+
item = @shopping_cart.create_item
|
113
|
+
|
114
|
+
assert @shopping_cart.items.include?(item)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_create_from_element_works
|
118
|
+
@optional_tags.power.each do |optional_tag_names|
|
119
|
+
xml_str = @xml_str
|
120
|
+
|
121
|
+
optional_tag_names.each { |name| xml_str = xml_str.gsub(%r{<#{name}.*?</#{name}>}, '') }
|
122
|
+
|
123
|
+
element = REXML::Document.new(xml_str).root
|
124
|
+
|
125
|
+
expect = Item.stubs(:create_from_element)
|
126
|
+
expect.with do |element, shopping_cart|
|
127
|
+
element.name == 'item' and
|
128
|
+
element.elements['item-name'].text == 'AA Rechargeable Battery Pack'
|
129
|
+
end
|
130
|
+
expect.times(1).returns(:item1)
|
131
|
+
|
132
|
+
expect = Item.stubs(:create_from_element)
|
133
|
+
expect.with do |element, shopping_cart|
|
134
|
+
element.name == 'item' and
|
135
|
+
element.elements['item-name'].text == 'MegaSound 2GB MP3 Player'
|
136
|
+
end
|
137
|
+
expect.times(1).returns(:item2)
|
138
|
+
|
139
|
+
shopping_cart = ShoppingCart.create_from_element(element, nil)
|
140
|
+
|
141
|
+
assert_equal Time.parse("2007-12-31T23:59:59-05:00"), shopping_cart.expires_at unless optional_tag_names.include?('cart-expiration')
|
142
|
+
assert_equal [ :item1, :item2 ], shopping_cart.items
|
143
|
+
assert_equal({ 'affiliate-code' => '01234' }, shopping_cart.private_data) unless optional_tag_names.include?('merchant-private-data')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/area_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
|
+
# Tests for the TaxRule class.
|
35
|
+
class Google4R::Checkout::TaxRuleTest < 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
|
+
@command = @frontend.create_checkout_command
|
42
|
+
@table = TaxTable.new(false)
|
43
|
+
@rule = @table.create_rule
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_tax_rule_gets_initialized_correctly
|
47
|
+
assert_equal @table, @rule.table
|
48
|
+
assert_nil @rule.area
|
49
|
+
assert_nil @rule.rate
|
50
|
+
assert !@rule.shipping_taxed
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_tax_rule_behaves_correctly
|
54
|
+
assert_respond_to @rule, :table
|
55
|
+
assert_respond_to @rule, :area
|
56
|
+
assert_respond_to @rule, :rate
|
57
|
+
assert_respond_to @rule, :shipping_taxed
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_tax_rule_accessors_work
|
61
|
+
@rule.area = :area
|
62
|
+
assert_equal :area, @rule.area
|
63
|
+
|
64
|
+
@rule.rate = 0.5
|
65
|
+
assert_equal 0.5, @rule.rate
|
66
|
+
|
67
|
+
@rule.shipping_taxed=true
|
68
|
+
assert @rule.shipping_taxed
|
69
|
+
end
|
70
|
+
end
|