google4r 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -0
- data/LICENSE +22 -0
- data/README +75 -0
- data/lib/google4r/checkout.rb +36 -0
- data/lib/google4r/checkout/commands.rb +267 -0
- data/lib/google4r/checkout/frontend.rb +100 -0
- data/lib/google4r/checkout/notifications.rb +533 -0
- data/lib/google4r/checkout/shared.rb +501 -0
- data/lib/google4r/checkout/xml_generation.rb +271 -0
- data/lib/google4r/maps.rb +174 -0
- data/test/checkout/integration/checkout_command_test.rb +103 -0
- data/test/checkout/unit/address_test.rb +131 -0
- data/test/checkout/unit/area_test.rb +41 -0
- data/test/checkout/unit/checkout_command_test.rb +112 -0
- data/test/checkout/unit/checkout_command_xml_generator_test.rb +187 -0
- data/test/checkout/unit/command_test.rb +126 -0
- data/test/checkout/unit/flat_rate_shipping_test.rb +114 -0
- data/test/checkout/unit/frontend_test.rb +63 -0
- data/test/checkout/unit/item_test.rb +159 -0
- data/test/checkout/unit/marketing_preferences_test.rb +65 -0
- data/test/checkout/unit/merchant_code_test.rb +122 -0
- data/test/checkout/unit/new_order_notification_test.rb +115 -0
- data/test/checkout/unit/notification_acknowledgement_test.rb +43 -0
- data/test/checkout/unit/notification_handler_test.rb +93 -0
- data/test/checkout/unit/order_adjustment_test.rb +95 -0
- data/test/checkout/unit/order_state_change_notification_test.rb +159 -0
- data/test/checkout/unit/pickup_shipping_test.rb +70 -0
- data/test/checkout/unit/private_data_parser_test.rb +68 -0
- data/test/checkout/unit/shipping_adjustment_test.rb +100 -0
- data/test/checkout/unit/shipping_method_test.rb +41 -0
- data/test/checkout/unit/shopping_cart_test.rb +146 -0
- data/test/checkout/unit/tax_rule_test.rb +65 -0
- data/test/checkout/unit/tax_table_test.rb +82 -0
- data/test/checkout/unit/us_country_area_test.rb +76 -0
- data/test/checkout/unit/us_state_area_test.rb +70 -0
- data/test/checkout/unit/us_zip_area_test.rb +66 -0
- data/test/maps/geocoder_test.rb +143 -0
- data/var/cacert.pem +7815 -0
- metadata +100 -0
@@ -0,0 +1,126 @@
|
|
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 'test/checkout/frontend_configuration'
|
31
|
+
|
32
|
+
require 'google4r/checkout'
|
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_sign_and_encode_works_properly
|
57
|
+
hash = @command.sign_and_encode
|
58
|
+
|
59
|
+
assert_equal 2, hash.length
|
60
|
+
assert_equal TestCommand::XML_REPRESENTATION, Base64.decode64(hash[:cart])
|
61
|
+
assert_equal OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'),
|
62
|
+
FRONTEND_CONFIGURATION[:merchant_key], TestCommand::XML_REPRESENTATION),
|
63
|
+
Base64.decode64(hash[:signature])
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_sending_fails_if_certificate_validation_fails
|
67
|
+
OpenSSL::SSL::SSLSocket.any_instance.stubs(:connect).raises(OpenSSL::SSL::SSLError, 'certificate verify failed')
|
68
|
+
|
69
|
+
assert_raises(OpenSSL::SSL::SSLError) { @command.send_to_google_checkout }
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_to_xml_raises_runtime_error
|
73
|
+
assert_raises(RuntimeError) { Command.new(Frontend.new(FRONTEND_CONFIGURATION)).to_xml }
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_unknown_xml_response_in_body_raises_runtime_error
|
77
|
+
mock_body = '<?xml version="1.0" ?><unexpected-tag />'
|
78
|
+
|
79
|
+
success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
|
80
|
+
success_response.expects(:body).returns(mock_body)
|
81
|
+
|
82
|
+
Net::HTTP.any_instance.stubs(:request).returns(success_response)
|
83
|
+
|
84
|
+
assert_raises(RuntimeError) { @command.send_to_google_checkout }
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_invalid_response_code_raises_runtime_error
|
88
|
+
unknown_response = mock()
|
89
|
+
unknown_response.expects(:code)
|
90
|
+
unknown_response.expects(:message)
|
91
|
+
|
92
|
+
Net::HTTP.any_instance.stubs(:request).returns(unknown_response)
|
93
|
+
|
94
|
+
assert_raises(RuntimeError) { @command.send_to_google_checkout }
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_error_tag_in_response_code_raises_google_checkout_error
|
98
|
+
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>'
|
99
|
+
|
100
|
+
error_response = Net::HTTPClientError.new(Net::HTTP.version_1_2, 400, "Bad Request")
|
101
|
+
error_response.expects(:body).returns(mock_body)
|
102
|
+
|
103
|
+
Net::HTTP.any_instance.stubs(:request).returns(error_response)
|
104
|
+
|
105
|
+
assert_raises(GoogleCheckoutError) { @command.send_to_google_checkout }
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_send_to_google_checkout_works_correctly_if_200_is_returned
|
109
|
+
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&shoppingcart=foo-bar</redirect-url></checkout-redirect>'
|
110
|
+
|
111
|
+
success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
|
112
|
+
success_response.expects(:body).returns(mock_body)
|
113
|
+
|
114
|
+
Net::HTTP.any_instance.stubs(:request).returns(success_response)
|
115
|
+
Net::HTTP.any_instance.stubs(:set_form_data).with(@command.sign_and_encode).returns(success_response)
|
116
|
+
|
117
|
+
Net::HTTP::Post.any_instance.expects(:basic_auth).with(FRONTEND_CONFIGURATION[:merchant_id],
|
118
|
+
FRONTEND_CONFIGURATION[:merchant_key])
|
119
|
+
|
120
|
+
result = @command.send_to_google_checkout
|
121
|
+
|
122
|
+
assert_kind_of CheckoutRedirectResponse, result
|
123
|
+
assert_equal 'foo-bar', result.serial_number
|
124
|
+
assert_equal 'https://sandbox.google.com/checkout/view/buy?o=shoppingcart&shoppingcart=foo-bar', result.redirect_url
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,114 @@
|
|
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 'test/checkout/frontend_configuration'
|
31
|
+
|
32
|
+
require 'google4r/checkout'
|
33
|
+
|
34
|
+
# Test for the FlatRateShipping class.
|
35
|
+
class Google4R::Checkout::FlatRateShippingMethodTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@shipping = FlatRateShipping.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_flat_rate_shipping_method_behaves_correctly
|
43
|
+
[ :name, :name=, :price, :price=,
|
44
|
+
:allowed_areas, :create_allowed_area, :excluded_areas, :create_excluded_area
|
45
|
+
].each do |symbol|
|
46
|
+
assert_respond_to @shipping, symbol
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_initialization
|
51
|
+
assert_nil @shipping.name
|
52
|
+
assert_nil @shipping.price
|
53
|
+
assert_equal [], @shipping.allowed_areas
|
54
|
+
assert_equal [], @shipping.excluded_areas
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_flat_rate_shipping_method_setting_attributes_works_correctly
|
58
|
+
@shipping.name = "Shipping Method Name"
|
59
|
+
assert_equal "Shipping Method Name", @shipping.name
|
60
|
+
|
61
|
+
@shipping.price = Money.new(100, "EUR")
|
62
|
+
assert_kind_of Money, @shipping.price
|
63
|
+
assert_equal 100, @shipping.price.cents
|
64
|
+
assert_equal "EUR", @shipping.price.currency
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_flat_rate_shipping_method_price_is_validated
|
68
|
+
# Test that FlatRateShippingMethod checks for its price attribute responding
|
69
|
+
# to cents and currency.
|
70
|
+
assert_raises(RuntimeError) { @shipping.price = nil }
|
71
|
+
assert_raises(RuntimeError) { @shipping.price = 10 }
|
72
|
+
assert_raises(RuntimeError) { @shipping.price = "str" }
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_create_create_allowed_excluded_areas_works_with_block
|
76
|
+
[ [ :allowed_areas, :create_allowed_area], [ :excluded_areas, :create_excluded_area ] ].each do |pair|
|
77
|
+
read_sym, create_sym = pair
|
78
|
+
|
79
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
80
|
+
|
81
|
+
the_area = nil
|
82
|
+
|
83
|
+
res =
|
84
|
+
@shipping.send(create_sym, clazz) do |area|
|
85
|
+
the_area = area
|
86
|
+
assert_kind_of clazz, area
|
87
|
+
end
|
88
|
+
|
89
|
+
assert_equal res, the_area
|
90
|
+
assert @shipping.send(read_sym).include?(the_area)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_create_create_allowed_excluded_areas_works_without_block
|
96
|
+
[ [ :allowed_areas, :create_allowed_area], [ :excluded_areas, :create_excluded_area ] ].each do |pair|
|
97
|
+
read_sym, create_sym = pair
|
98
|
+
|
99
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
100
|
+
area = @shipping.send(create_sym, clazz)
|
101
|
+
|
102
|
+
assert_kind_of clazz, area
|
103
|
+
|
104
|
+
assert @shipping.send(read_sym).include?(area)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_create_create_allowed_excluded_areas_validates_parameter
|
110
|
+
[ :create_allowed_area, :create_excluded_area ].each do |sym|
|
111
|
+
assert_raises(RuntimeError) { @shipping.send(sym, String) }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,63 @@
|
|
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 'test/checkout/frontend_configuration'
|
31
|
+
|
32
|
+
require 'google4r/checkout'
|
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
|
+
[ :create_checkout_command, :configuration, :tax_table_factory,
|
50
|
+
:tax_table_factory=
|
51
|
+
].each do |symbol|
|
52
|
+
assert_respond_to @frontend, symbol
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_create_checkout_command_works_correctly
|
57
|
+
assert_kind_of CheckoutCommand, @frontend.create_checkout_command
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_create_notification_handler_works_correctly
|
61
|
+
assert_kind_of NotificationHandler, @frontend.create_notification_handler
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,159 @@
|
|
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 'test/checkout/frontend_configuration'
|
31
|
+
|
32
|
+
require 'google4r/checkout'
|
33
|
+
|
34
|
+
# Test for the Item class.
|
35
|
+
class Google4R::Checkout::ItemTest < 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
|
+
@xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
43
|
+
<item>
|
44
|
+
<item-name>MegaSound 2GB MP3 Player</item-name>
|
45
|
+
<item-description>Portable MP3 player - stores 500 songs</item-description>
|
46
|
+
<unit-price currency="USD">178.00</unit-price>
|
47
|
+
<quantity>1</quantity>
|
48
|
+
<merchant-item-id>MGS2GBMP3</merchant-item-id>
|
49
|
+
<merchant-private-item-data>
|
50
|
+
<item-note>Text 1</item-note>
|
51
|
+
<item-note>Text 2</item-note>
|
52
|
+
<nested>
|
53
|
+
<tags>value</tags>
|
54
|
+
</nested>
|
55
|
+
</merchant-private-item-data>
|
56
|
+
<tax-table-selector>Some Table</tax-table-selector>
|
57
|
+
</item>}
|
58
|
+
|
59
|
+
@optional_tags = [ 'merchant-item-id', 'merchant-private-item-data', 'tax-table-selector' ]
|
60
|
+
|
61
|
+
@command = @frontend.create_checkout_command
|
62
|
+
@cart = @command.cart
|
63
|
+
@item = @cart.create_item
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_item_behaves_correctly
|
67
|
+
[ :cart, :name, :name=, :description, :description=, :unit_price, :unit_price=,
|
68
|
+
:quantity, :quantity=, :id, :id=, :private_data, :private_data=,
|
69
|
+
:tax_table, :tax_table=
|
70
|
+
].each do |symbol|
|
71
|
+
assert_respond_to @item, symbol
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_item_gets_initialized_correctly
|
76
|
+
assert_equal @cart, @item.cart
|
77
|
+
assert_nil @item.name
|
78
|
+
assert_nil @item.description
|
79
|
+
assert_nil @item.unit_price
|
80
|
+
assert_nil @item.quantity
|
81
|
+
assert_nil @item.private_data
|
82
|
+
assert_nil @item.id
|
83
|
+
assert_nil @item.tax_table
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_item_setters_work
|
87
|
+
@item.name = "name"
|
88
|
+
assert_equal "name", @item.name
|
89
|
+
|
90
|
+
@item.description = "description"
|
91
|
+
assert_equal "description", @item.description
|
92
|
+
|
93
|
+
@item.unit_price = Money.new(100, "EUR")
|
94
|
+
assert_equal Money.new(100, "EUR"), @item.unit_price
|
95
|
+
|
96
|
+
@item.quantity = 10
|
97
|
+
assert_equal 10, @item.quantity
|
98
|
+
|
99
|
+
@item.id = "id"
|
100
|
+
assert_equal "id", @item.id
|
101
|
+
|
102
|
+
@item.private_data = Hash.new
|
103
|
+
assert_equal Hash.new, @item.private_data
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_set_tax_table_works
|
107
|
+
table = @command.tax_tables.first
|
108
|
+
@item.tax_table = table
|
109
|
+
assert_equal table, @item.tax_table
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_set_tax_table_raises_if_table_is_unknown_in_command
|
113
|
+
assert_raises(RuntimeError) { @item.tax_table = TaxTable.new(false) }
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_set_private_data_only_works_with_hashes
|
117
|
+
assert_raises(RuntimeError) { @cart.private_data = 1 }
|
118
|
+
assert_raises(RuntimeError) { @cart.private_data = nil }
|
119
|
+
assert_raises(RuntimeError) { @cart.private_data = 'Foobar' }
|
120
|
+
assert_raises(RuntimeError) { @cart.private_data = [] }
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_item_price_must_be_money_instance
|
124
|
+
assert_raises(RuntimeError) { @item.unit_price = nil }
|
125
|
+
assert_raises(RuntimeError) { @item.unit_price = "String" }
|
126
|
+
assert_raises(RuntimeError) { @item.unit_price = 10 }
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_create_from_element_works
|
130
|
+
@optional_tags.power.each do |optional_tag_names|
|
131
|
+
xml_str = @xml_str
|
132
|
+
|
133
|
+
optional_tag_names.each { |name| xml_str = xml_str.gsub(%r{<#{name}.*?</#{name}>}, '') }
|
134
|
+
|
135
|
+
command = @frontend.create_checkout_command
|
136
|
+
tax_table = TaxTable.new(false)
|
137
|
+
tax_table.name = 'Some Table'
|
138
|
+
command.tax_tables << tax_table
|
139
|
+
item = Item.create_from_element(REXML::Document.new(xml_str).root, command.cart)
|
140
|
+
|
141
|
+
assert_equal command.cart, item.cart
|
142
|
+
|
143
|
+
assert_equal 'MegaSound 2GB MP3 Player', item.name
|
144
|
+
assert_equal 'Portable MP3 player - stores 500 songs', item.description
|
145
|
+
assert_equal Money.new(17800, 'USD'), item.unit_price
|
146
|
+
assert_equal 1, item.quantity
|
147
|
+
assert_equal 'MGS2GBMP3', item.id unless item.id.nil?
|
148
|
+
|
149
|
+
hash =
|
150
|
+
{
|
151
|
+
'item-note' => [ 'Text 1', 'Text 2' ],
|
152
|
+
'nested' => { 'tags' => 'value' }
|
153
|
+
}
|
154
|
+
assert_equal hash, item.private_data unless optional_tag_names.include?('merchant-private-item-data')
|
155
|
+
|
156
|
+
assert_equal 'Some Table', item.tax_table.name unless optional_tag_names.include?('tax-table-selector')
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|