google4r 0.0.1
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 +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,159 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/order_state_change_notification_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.
|
35
|
+
class Google4R::Checkout::OrderStateChangeNotificationTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@data = Hash.new
|
40
|
+
@data[:serial_number] = "c821426e-7caa-4d51-9b2e-48ef7ecd6423"
|
41
|
+
@data[:google_order_number] = "841171949013218"
|
42
|
+
@data[:new_financial_order_state] = "CHARGING"
|
43
|
+
@data[:previous_fulfillment_order_state] = "NEW"
|
44
|
+
@data[:new_financial_order_state] = "CHARGEABLE"
|
45
|
+
@data[:previous_fulfillment_order_state] = "NEW"
|
46
|
+
@data[:reason] = "charge_customer"
|
47
|
+
@data[:timestamp] = Time.new
|
48
|
+
|
49
|
+
@xml_template = %q{<?xml version="1.0" encoding="UTF-8"?>
|
50
|
+
<order-state-change-notification xmlns="http://checkout.google.com/schema/2"
|
51
|
+
serial-number="%s">
|
52
|
+
<google-order-number>%s</google-order-number>
|
53
|
+
<new-financial-order-state>%s</new-financial-order-state>
|
54
|
+
<new-fulfillment-order-state>%s</new-fulfillment-order-state>
|
55
|
+
<previous-financial-order-state>%s</previous-financial-order-state>
|
56
|
+
<previous-fulfillment-order-state>%s</previous-fulfillment-order-state>
|
57
|
+
<reason>%s</reason>
|
58
|
+
<timestamp>%s</timestamp>
|
59
|
+
</order-state-change-notification>
|
60
|
+
}
|
61
|
+
|
62
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
63
|
+
@frontend.tax_table_factory = TestTaxTableFactory.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_order_state_change_notification_responds_correctly
|
67
|
+
assert_respond_to OrderStateChangeNotification, :create_from_element
|
68
|
+
|
69
|
+
notification = OrderStateChangeNotification.new(@frontend)
|
70
|
+
|
71
|
+
[ :serial_number, :google_order_number, :new_financial_order_state, :previous_fulfillment_order_state,
|
72
|
+
:new_financial_order_state, :previous_fulfillment_order_state, :reason, :timestamp,
|
73
|
+
:serial_number=, :google_order_number=, :new_financial_order_state=, :previous_fulfillment_order_state=,
|
74
|
+
:new_financial_order_state=, :previous_fulfillment_order_state=, :reason=, :timestamp
|
75
|
+
].each do |sym|
|
76
|
+
assert_respond_to notification, sym
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_financial_order_state_defines_correct_constants
|
81
|
+
assert defined?(FinancialOrderState::REVIEWING)
|
82
|
+
assert defined?(FinancialOrderState::CHARGEABLE)
|
83
|
+
assert defined?(FinancialOrderState::CHARGING)
|
84
|
+
assert defined?(FinancialOrderState::CHARGED)
|
85
|
+
assert defined?(FinancialOrderState::PAYMENT_DECLINED)
|
86
|
+
assert defined?(FinancialOrderState::CANCELLED)
|
87
|
+
assert defined?(FinancialOrderState::CANCELLED_BY_GOOGLE)
|
88
|
+
|
89
|
+
assert_equal "REVIEWING", FinancialOrderState::REVIEWING
|
90
|
+
assert_equal "CHARGEABLE", FinancialOrderState::CHARGEABLE
|
91
|
+
assert_equal "CHARGING", FinancialOrderState::CHARGING
|
92
|
+
assert_equal "CHARGED", FinancialOrderState::CHARGED
|
93
|
+
assert_equal "PAYMENT_DECLINED", FinancialOrderState::PAYMENT_DECLINED
|
94
|
+
assert_equal "CANCELLED", FinancialOrderState::CANCELLED
|
95
|
+
assert_equal "CANCELLED_BY_GOOGLE", FinancialOrderState::CANCELLED_BY_GOOGLE
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_fulfillment_order_state_defines_correct_constants
|
99
|
+
assert defined?(FulfillmentOrderState::NEW)
|
100
|
+
assert defined?(FulfillmentOrderState::PROCESSING)
|
101
|
+
assert defined?(FulfillmentOrderState::DELIVERED)
|
102
|
+
assert defined?(FulfillmentOrderState::WILL_NOT_DELIVER)
|
103
|
+
|
104
|
+
assert_equal "NEW", FulfillmentOrderState::NEW
|
105
|
+
assert_equal "PROCESSING", FulfillmentOrderState::PROCESSING
|
106
|
+
assert_equal "DELIVERED", FulfillmentOrderState::DELIVERED
|
107
|
+
assert_equal "WILL_NOT_DELIVER", FulfillmentOrderState::WILL_NOT_DELIVER
|
108
|
+
end
|
109
|
+
|
110
|
+
# <reason> in notification
|
111
|
+
def test_create_from_xml_should_correctly_create_order_state_change_notification_with_reason
|
112
|
+
[ true, false ].each do |skip_reason|
|
113
|
+
xml_str = @xml_template %
|
114
|
+
[
|
115
|
+
@data[:serial_number], @data[:google_order_number], @data[:new_financial_order_state],
|
116
|
+
@data[:new_fulfillment_order_state], @data[:previous_financial_order_state],
|
117
|
+
@data[:previous_fulfillment_order_state], @data[:reason], @data[:timestamp].iso8601
|
118
|
+
]
|
119
|
+
|
120
|
+
xml_str = xml_str.gsub(/<reason>.*?<\/reason>/, '') if skip_reason
|
121
|
+
|
122
|
+
notification = OrderStateChangeNotification.create_from_element(REXML::Document.new(xml_str).root, @frontend)
|
123
|
+
|
124
|
+
@data.each do |key, value|
|
125
|
+
next if skip_reason and key == :reason
|
126
|
+
|
127
|
+
if key == :timestamp then
|
128
|
+
assert_in_delta @data[:timestamp].to_f, notification.timestamp.to_f, 1
|
129
|
+
else
|
130
|
+
assert_equal @data[key], notification.send(key), "#{key}"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
assert_nil notification.reason if skip_reason
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_create_from_xml_should_raise_exception_with_missing_tags
|
139
|
+
# Remove all required tags from the XML and expect the XPath query in
|
140
|
+
# OrderStateChangeNotification#create_from_xml to evaluate to nil and thus
|
141
|
+
# raise a NoMethodError.
|
142
|
+
[ 'google-order-number', 'new-financial-order-state', 'new-fulfillment-order-state',
|
143
|
+
'previous-financial-order-state', 'previous-fulfillment-order-state', 'timestamp' ].each do |tag_name|
|
144
|
+
xml_str = @xml_template %
|
145
|
+
[
|
146
|
+
@data[:serial_number], @data[:google_order_number], @data[:new_financial_order_state],
|
147
|
+
@data[:new_fulfillment_order_state], @data[:previous_financial_order_state],
|
148
|
+
@data[:previous_fulfillment_order_state], @data[:reason], @data[:timestamp].iso8601
|
149
|
+
]
|
150
|
+
|
151
|
+
xml_str = xml_str.gsub(%r{<#{tag_name}>.*?</#{tag_name}>}, '')
|
152
|
+
doc = REXML::Document.new(xml_str)
|
153
|
+
|
154
|
+
assert_raises(NoMethodError, "Removed tag: #{tag_name} - #{xml_str}") {
|
155
|
+
notification = OrderStateChangeNotification.create_from_element(doc.root, @frontend)
|
156
|
+
}
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/pickup_shipping_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 PickupShipping class.
|
35
|
+
class Google4R::Checkout::PickupShippingMethodTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@shipping = PickupShipping.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_initialization
|
43
|
+
assert_nil @shipping.name
|
44
|
+
assert_nil @shipping.price
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_pickup_shipping_method_behaves_correctly
|
48
|
+
[ :name, :name=, :price, :price= ].each do |sym|
|
49
|
+
assert_respond_to @shipping, sym
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_pickup_shipping_method_setting_attributes_works_correctly
|
54
|
+
@shipping.name = "Shipping Method Name"
|
55
|
+
assert_equal "Shipping Method Name", @shipping.name
|
56
|
+
|
57
|
+
@shipping.price = Money.new(100, "EUR")
|
58
|
+
assert_kind_of Money, @shipping.price
|
59
|
+
assert_equal 100, @shipping.price.cents
|
60
|
+
assert_equal "EUR", @shipping.price.currency
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_pickup_shipping_method_price_is_validated
|
64
|
+
# Test that PickupShippingMethod checks for its price attribute responding
|
65
|
+
# to cents and currency.
|
66
|
+
assert_raises(RuntimeError) { @shipping.price = nil }
|
67
|
+
assert_raises(RuntimeError) { @shipping.price = 10 }
|
68
|
+
assert_raises(RuntimeError) { @shipping.price = "str" }
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/private_data_parser_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 PrivateDataParser.
|
35
|
+
class Google4R::Checkout::PrivateDataParserTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@xml_str = %q{<merchant-private-item-data>
|
40
|
+
<item-note>Text 1</item-note>
|
41
|
+
<item-note>Text 2</item-note>
|
42
|
+
<nested>
|
43
|
+
<tags>value</tags>
|
44
|
+
</nested>
|
45
|
+
</merchant-private-item-data>}
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_responds_correctly
|
49
|
+
assert_respond_to PrivateDataParser, :element_to_value
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_parser_works_in_simple_example
|
53
|
+
element = REXML::Document.new(@xml_str).root.elements['//tags']
|
54
|
+
|
55
|
+
assert_equal 'value', PrivateDataParser.element_to_value(element)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_parser_works_in_complex_example
|
59
|
+
doc = REXML::Document.new(@xml_str)
|
60
|
+
|
61
|
+
hash =
|
62
|
+
{
|
63
|
+
'item-note' => [ 'Text 1', 'Text 2' ],
|
64
|
+
'nested' => { 'tags' => 'value' }
|
65
|
+
}
|
66
|
+
assert_equal hash, PrivateDataParser.element_to_value(doc.root)
|
67
|
+
end
|
68
|
+
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 'test/checkout/frontend_configuration'
|
31
|
+
|
32
|
+
require 'google4r/checkout'
|
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,41 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/shipping_method_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 ShippingMethod class.
|
35
|
+
class Google4R::Checkout::ShippingMethodTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def test_shipping_method_raises_runtime_error_on_initialisation
|
39
|
+
assert_raises(RuntimeError) { ShippingMethod.new }
|
40
|
+
end
|
41
|
+
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 'test/checkout/frontend_configuration'
|
31
|
+
|
32
|
+
require 'google4r/checkout'
|
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
|
+
@cart = @command.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 @cart, sym
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_initialized_correctly
|
78
|
+
assert_equal @command, @cart.owner
|
79
|
+
assert_equal nil, @cart.expires_at
|
80
|
+
assert_equal [], @cart.items
|
81
|
+
assert_equal @command, @cart.owner
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_accessors_work_correctly
|
85
|
+
hash = { 'foo' => [ { 'bar' => 'baz' }, "d'oh", 2 ] }
|
86
|
+
@cart.private_data = hash.dup
|
87
|
+
assert_equal hash, @cart.private_data
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_setting_private_data_only_works_with_a_hash
|
91
|
+
assert_raises(RuntimeError) { @cart.private_data = 1 }
|
92
|
+
assert_raises(RuntimeError) { @cart.private_data = nil }
|
93
|
+
assert_raises(RuntimeError) { @cart.private_data = 'Foobar' }
|
94
|
+
assert_raises(RuntimeError) { @cart.private_data = [] }
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_create_item_works_correctly_with_block
|
98
|
+
the_item = nil
|
99
|
+
|
100
|
+
res =
|
101
|
+
@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 @cart.items.include?(the_item)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_create_item_works_correctly_without_block
|
112
|
+
item = @cart.create_item
|
113
|
+
|
114
|
+
assert @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, 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, 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
|
+
cart = ShoppingCart.create_from_element(element, nil)
|
140
|
+
|
141
|
+
assert_equal Time.parse("2007-12-31T23:59:59-05:00"), cart.expires_at unless optional_tag_names.include?('cart-expiration')
|
142
|
+
assert_equal [ :item1, :item2 ], cart.items
|
143
|
+
assert_equal({ 'affiliate-code' => '01234' }, cart.private_data) unless optional_tag_names.include?('merchant-private-data')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|