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,173 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/merchant_calculated_shipping_test.rb
|
4
|
+
# Author: Tony Chan <api.htchan at gmail dot com>
|
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 FlatRateShipping class.
|
35
|
+
class Google4R::Checkout::MerchantCalculatedShippingTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@shipping = MerchantCalculatedShipping.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_merchant_calculated_shipping_method_behaves_correctly
|
43
|
+
[ :name, :name=, :price, :price=,
|
44
|
+
:shipping_restrictions_allowed_areas, :shipping_restrictions_excluded_areas,
|
45
|
+
:address_filters_allowed_areas, :address_filters_excluded_areas,
|
46
|
+
:address_filters_allow_us_po_box, :shipping_restrictions_allow_us_po_box,
|
47
|
+
:create_allowed_area, :create_excluded_area, :create_area
|
48
|
+
].each do |symbol|
|
49
|
+
assert_respond_to @shipping, symbol
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_initialization
|
54
|
+
assert_nil @shipping.name
|
55
|
+
assert_nil @shipping.price
|
56
|
+
assert_equal [], @shipping.shipping_restrictions_allowed_areas
|
57
|
+
assert_equal [], @shipping.shipping_restrictions_excluded_areas
|
58
|
+
assert_equal [], @shipping.address_filters_allowed_areas
|
59
|
+
assert_equal [], @shipping.address_filters_excluded_areas
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_merchant_calculated_shipping_setting_attributes_works_correctly
|
63
|
+
@shipping.name = "Shipping Method Name"
|
64
|
+
assert_equal "Shipping Method Name", @shipping.name
|
65
|
+
|
66
|
+
@shipping.price = Money.new(100, "EUR")
|
67
|
+
assert_kind_of Money, @shipping.price
|
68
|
+
assert_equal 100, @shipping.price.cents
|
69
|
+
assert_equal "EUR", @shipping.price.currency.iso_code
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_merchant_calculated_shipping_price_is_validated
|
73
|
+
# Test that MerchantCalculatedShipping checks for its price attribute responding
|
74
|
+
# to cents and currency.
|
75
|
+
assert_raises(RuntimeError) { @shipping.price = nil }
|
76
|
+
assert_raises(RuntimeError) { @shipping.price = 10 }
|
77
|
+
assert_raises(RuntimeError) { @shipping.price = "str" }
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_create_allowed_excluded_areas_works_with_block
|
81
|
+
[ [ :shipping_restrictions_allowed_areas, :create_allowed_area ],
|
82
|
+
[ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
|
83
|
+
read_sym, create_sym = pair
|
84
|
+
|
85
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
86
|
+
|
87
|
+
the_area = nil
|
88
|
+
|
89
|
+
res =
|
90
|
+
@shipping.send(create_sym, clazz) do |area|
|
91
|
+
the_area = area
|
92
|
+
assert_kind_of clazz, area
|
93
|
+
end
|
94
|
+
|
95
|
+
assert_equal res, the_area
|
96
|
+
assert @shipping.send(read_sym).include?(the_area)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_create_allowed_excluded_areas_works_without_block
|
102
|
+
[ [ :shipping_restrictions_allowed_areas, :create_allowed_area],
|
103
|
+
[ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
|
104
|
+
read_sym, create_sym = pair
|
105
|
+
|
106
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
107
|
+
area = @shipping.send(create_sym, clazz)
|
108
|
+
|
109
|
+
assert_kind_of clazz, area
|
110
|
+
|
111
|
+
assert @shipping.send(read_sym).include?(area)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_create_shipping_restrictions_allowed_excluded_areas_works_with_block
|
117
|
+
[ [ :shipping_restrictions_allowed_areas, :create_shipping_restrictions_allowed_area ],
|
118
|
+
[ :shipping_restrictions_excluded_areas, :create_shipping_restrictions_excluded_area ] ].each do |pair|
|
119
|
+
read_sym, create_sym = pair
|
120
|
+
|
121
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
122
|
+
|
123
|
+
the_area = nil
|
124
|
+
|
125
|
+
res =
|
126
|
+
@shipping.send(create_sym, clazz) do |area|
|
127
|
+
the_area = area
|
128
|
+
assert_kind_of clazz, area
|
129
|
+
end
|
130
|
+
|
131
|
+
assert_equal res, the_area
|
132
|
+
assert @shipping.send(read_sym).include?(the_area)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_create_shipping_restrictions_allowed_excluded_areas_works_without_block
|
138
|
+
[ [ :shipping_restrictions_allowed_areas, :create_shipping_restrictions_allowed_area],
|
139
|
+
[ :shipping_restrictions_excluded_areas, :create_shipping_restrictions_excluded_area ] ].each do |pair|
|
140
|
+
read_sym, create_sym = pair
|
141
|
+
|
142
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
143
|
+
area = @shipping.send(create_sym, clazz)
|
144
|
+
|
145
|
+
assert_kind_of clazz, area
|
146
|
+
|
147
|
+
assert @shipping.send(read_sym).include?(area)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_create_allowed_excluded_areas_validates_parameter
|
153
|
+
[ :create_allowed_area, :create_excluded_area ].each do |sym|
|
154
|
+
assert_raises(RuntimeError) { @shipping.send(sym, String) }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_new_create_area_with_merchant_calculated_shipping
|
159
|
+
[ [ :shipping_restrictions, :allowed_areas ],
|
160
|
+
[ :shipping_restrictions, :excluded_areas ],
|
161
|
+
[ :address_filters, :allowed_areas ],
|
162
|
+
[ :address_filters, :excluded_areas ] ].each do |pair|
|
163
|
+
type_sym, area_sym = pair
|
164
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
165
|
+
area = @shipping.send(:create_area, type_sym, area_sym, clazz)
|
166
|
+
|
167
|
+
assert_kind_of clazz, area
|
168
|
+
|
169
|
+
assert @shipping.send((type_sym.to_s + '_' + area_sym.to_s).to_sym).include?(area)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/merchant_calculation_callback_test.rb
|
4
|
+
# Author: Tony Chan <api dot 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
|
+
# Test for the class NewOrderConfirmation.
|
35
|
+
class Google4R::Checkout::MerchantCalculationCallbackTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@xml_str = %q{<?xml version="1.0" encoding="UTF-8"?>
|
40
|
+
<merchant-calculation-callback xmlns="http://checkout.google.com/schema/2">
|
41
|
+
<shopping-cart>
|
42
|
+
<merchant-private-data>
|
43
|
+
<affiliate-code>01234</affiliate-code>
|
44
|
+
</merchant-private-data>
|
45
|
+
<cart-expiration>
|
46
|
+
<good-until-date>2007-12-31T23:59:59-05:00</good-until-date>
|
47
|
+
</cart-expiration>
|
48
|
+
<items>
|
49
|
+
<item>
|
50
|
+
<merchant-item-id>GGLAA1453</merchant-item-id>
|
51
|
+
<item-name>Dry Food Pack</item-name>
|
52
|
+
<item-description>One pack of nutritious dried food for emergencies.</item-description>
|
53
|
+
<quantity>1</quantity>
|
54
|
+
<tax-table-selector>food</tax-table-selector>
|
55
|
+
<unit-price currency="USD">4.99</unit-price>
|
56
|
+
</item>
|
57
|
+
<item>
|
58
|
+
<merchant-item-id>MGS2GBMP3</merchant-item-id>
|
59
|
+
<item-name>Megasound 2GB MP3 Player</item-name>
|
60
|
+
<item-description>This portable MP3 player stores 500 songs.</item-description>
|
61
|
+
<quantity>1</quantity>
|
62
|
+
<unit-price currency="USD">179.99</unit-price>
|
63
|
+
<merchant-private-item-data>
|
64
|
+
<merchant-product-id>1234567890</merchant-product-id>
|
65
|
+
</merchant-private-item-data>
|
66
|
+
</item>
|
67
|
+
</items>
|
68
|
+
</shopping-cart>
|
69
|
+
<buyer-language>en_US</buyer-language>
|
70
|
+
<calculate>
|
71
|
+
<addresses>
|
72
|
+
<anonymous-address id="739030698069958">
|
73
|
+
<country-code>US</country-code>
|
74
|
+
<city>Mountain View</city>
|
75
|
+
<region>CA</region>
|
76
|
+
<postal-code>94043</postal-code>
|
77
|
+
</anonymous-address>
|
78
|
+
<anonymous-address id="421273450774618">
|
79
|
+
<country-code>US</country-code>
|
80
|
+
<city>New York</city>
|
81
|
+
<region>NY</region>
|
82
|
+
<postal-code>10022</postal-code>
|
83
|
+
</anonymous-address>
|
84
|
+
</addresses>
|
85
|
+
<tax>true</tax>
|
86
|
+
<shipping>
|
87
|
+
<method name="SuperShip"/>
|
88
|
+
<method name="UPS Ground"/>
|
89
|
+
</shipping>
|
90
|
+
<merchant-code-strings>
|
91
|
+
<merchant-code-string code="GiftCert012345"/>
|
92
|
+
<merchant-code-string code="FirstVisitCoupon"/>
|
93
|
+
</merchant-code-strings>
|
94
|
+
</calculate>
|
95
|
+
</merchant-calculation-callback>}
|
96
|
+
|
97
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
98
|
+
@frontend.tax_table_factory = TestTaxTableFactory.new
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_responds_correctly
|
102
|
+
assert_respond_to MerchantCalculationCallback, :create_from_element
|
103
|
+
|
104
|
+
callback = MerchantCalculationCallback.new(@frontend)
|
105
|
+
|
106
|
+
[ :shopping_cart, :shopping_cart=,
|
107
|
+
:buyer_language, :buyer_language=,
|
108
|
+
:anonymous_addresses, :tax, :tax=,
|
109
|
+
:shipping_methods, :merchant_code_strings
|
110
|
+
].each do |symbol|
|
111
|
+
assert_respond_to callback, symbol
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_create_from_element_works_correctly
|
116
|
+
# Build up some Mocha expectations.
|
117
|
+
|
118
|
+
expect = ShoppingCart.stubs(:create_from_element)
|
119
|
+
expect.times(1).returns(:shopping_cart)
|
120
|
+
expect.with { |element, owner| element.name == 'shopping-cart' and owner.kind_of?(MerchantCalculationCallback) }
|
121
|
+
|
122
|
+
expect = AnonymousAddress.stubs(:create_from_element)
|
123
|
+
expect.times(2).returns(:anonymous_address, :anonymous_address2)
|
124
|
+
expect.with { |element| element.name == 'anonymous-address' }
|
125
|
+
|
126
|
+
# Create the new notification.
|
127
|
+
merchantCalculationCallback = MerchantCalculationCallback.create_from_element(REXML::Document.new(@xml_str).root, @frontend)
|
128
|
+
|
129
|
+
# perform the assertions
|
130
|
+
assert_equal :shopping_cart, merchantCalculationCallback.shopping_cart
|
131
|
+
assert_equal 'en_US', merchantCalculationCallback.buyer_language
|
132
|
+
assert_equal 'true', merchantCalculationCallback.tax
|
133
|
+
assert_equal [:anonymous_address, :anonymous_address2], merchantCalculationCallback.anonymous_addresses
|
134
|
+
assert_equal ['SuperShip', 'UPS Ground'], merchantCalculationCallback.shipping_methods
|
135
|
+
assert_equal ['GiftCert012345', 'FirstVisitCoupon'], merchantCalculationCallback.merchant_code_strings
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/merchant_calculation_result_test.rb
|
4
|
+
# Author: Tony Chan <api dot 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
|
+
# Test for the class NewOrderConfirmation.
|
35
|
+
class Google4R::Checkout::MerchantCalculationResultTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
# Build up some Mocha expectations.
|
40
|
+
expect = Money.stubs(:new)
|
41
|
+
expect.times(2).returns(:shipping_rate, :total_tax)
|
42
|
+
|
43
|
+
@result = MerchantCalculationResult.new('UPS Ground', '1234567890', Money.new(1000, 'USD'), true, Money.new(2000, 'USD'))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_responds_correctly
|
47
|
+
|
48
|
+
[ :shipping_name, :shipping_name=,
|
49
|
+
:address_id, :address_id=,
|
50
|
+
:shipping_rate, :shipping_rate=,
|
51
|
+
:shippable, :shippable=,
|
52
|
+
:total_tax, :total_tax=,
|
53
|
+
:merchant_code_results
|
54
|
+
].each do |symbol|
|
55
|
+
assert_respond_to @result, symbol
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_create_merchant_code_result_works_correctly
|
60
|
+
expect = CouponResult.stubs(:new)
|
61
|
+
expect.times(1).returns(:coupon_result)
|
62
|
+
|
63
|
+
expect = GiftCertificateResult.stubs(:new)
|
64
|
+
expect.times(1).returns(:gift_certificate_result)
|
65
|
+
|
66
|
+
# Create the new CouponResult and GiftCertificationResult instances.
|
67
|
+
@result.create_merchant_code_result(CouponResult)
|
68
|
+
@result.create_merchant_code_result(GiftCertificateResult)
|
69
|
+
|
70
|
+
# perform the assertions
|
71
|
+
assert_equal 'UPS Ground', @result.shipping_name
|
72
|
+
assert_equal '1234567890', @result.address_id
|
73
|
+
assert_equal :shipping_rate, @result.shipping_rate
|
74
|
+
assert_equal true, @result.shippable
|
75
|
+
assert_equal :total_tax, @result.total_tax
|
76
|
+
assert_equal [:coupon_result, :gift_certificate_result], @result.merchant_code_results
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/merchant_calculation_results_test.rb
|
4
|
+
# Author: Tony Chan <api dot 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
|
+
# Test for the class NewOrderConfirmation.
|
35
|
+
class Google4R::Checkout::MerchantCalculationResultsTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@xml_str = %q{<?xml version='1.0' encoding='UTF-8'?>
|
40
|
+
<merchant-calculation-results xmlns='http://checkout.google.com/schema/2'>
|
41
|
+
<results>
|
42
|
+
<result address-id='739030698069958' shipping-name='SuperShip'>
|
43
|
+
<shipping-rate currency='USD'>7.03</shipping-rate>
|
44
|
+
<shippable>true</shippable>
|
45
|
+
<merchant-code-results>
|
46
|
+
<coupon-result>
|
47
|
+
<valid>true</valid>
|
48
|
+
<code>FirstVisitCoupon</code>
|
49
|
+
<calculated-amount currency='USD'>5.00</calculated-amount>
|
50
|
+
<message>Congratulations! You saved $5.00 on your first visit!</message>
|
51
|
+
</coupon-result>
|
52
|
+
<gift-certificate-result>
|
53
|
+
<valid>true</valid>
|
54
|
+
<code>GiftCert012345</code>
|
55
|
+
<calculated-amount currency='USD'>10.00</calculated-amount>
|
56
|
+
<message>You used your Gift Certificate!</message>
|
57
|
+
</gift-certificate-result>
|
58
|
+
</merchant-code-results>
|
59
|
+
</result>
|
60
|
+
<result address-id='739030698069958' shipping-name='UPS Ground'>
|
61
|
+
<shipping-rate currency='USD'>5.56</shipping-rate>
|
62
|
+
<shippable>true</shippable>
|
63
|
+
<total-tax currency='USD'>14.67</total-tax>
|
64
|
+
<merchant-code-results>
|
65
|
+
<coupon-result>
|
66
|
+
<valid>true</valid>
|
67
|
+
<code>FirstVisitCoupon</code>
|
68
|
+
<calculated-amount currency='USD'>5.00</calculated-amount>
|
69
|
+
<message>Congratulations! You saved $5.00 on your first visit!</message>
|
70
|
+
</coupon-result>
|
71
|
+
<gift-certificate-result>
|
72
|
+
<valid>true</valid>
|
73
|
+
<code>GiftCert012345</code>
|
74
|
+
<calculated-amount currency='USD'>10.00</calculated-amount>
|
75
|
+
<message>You used your Gift Certificate!</message>
|
76
|
+
</gift-certificate-result>
|
77
|
+
</merchant-code-results>
|
78
|
+
</result>
|
79
|
+
<result address-id='421273450774618' shipping-name='SuperShip'>
|
80
|
+
<shipping-rate currency='USD'>9.66</shipping-rate>
|
81
|
+
<shippable>true</shippable>
|
82
|
+
<total-tax currency='USD'>17.57</total-tax>
|
83
|
+
<merchant-code-results>
|
84
|
+
<coupon-result>
|
85
|
+
<valid>true</valid>
|
86
|
+
<code>FirstVisitCoupon</code>
|
87
|
+
<calculated-amount currency='USD'>5.00</calculated-amount>
|
88
|
+
<message>Congratulations! You saved $5.00 on your first visit!</message>
|
89
|
+
</coupon-result>
|
90
|
+
<gift-certificate-result>
|
91
|
+
<valid>true</valid>
|
92
|
+
<code>GiftCert012345</code>
|
93
|
+
<calculated-amount currency='USD'>10.00</calculated-amount>
|
94
|
+
<message>You used your Gift Certificate!</message>
|
95
|
+
</gift-certificate-result>
|
96
|
+
</merchant-code-results>
|
97
|
+
</result>
|
98
|
+
<result address-id='421273450774618' shipping-name='UPS Ground'>
|
99
|
+
<shipping-rate currency='USD'>7.68</shipping-rate>
|
100
|
+
<shippable>true</shippable>
|
101
|
+
<total-tax currency='USD'>17.57</total-tax>
|
102
|
+
<merchant-code-results>
|
103
|
+
<coupon-result>
|
104
|
+
<valid>true</valid>
|
105
|
+
<code>FirstVisitCoupon</code>
|
106
|
+
<calculated-amount currency='USD'>5.00</calculated-amount>
|
107
|
+
<message>Congratulations! You saved $5.00 on your first visit!</message>
|
108
|
+
</coupon-result>
|
109
|
+
<gift-certificate-result>
|
110
|
+
<valid>true</valid>
|
111
|
+
<code>GiftCert012345</code>
|
112
|
+
<calculated-amount currency='USD'>10.00</calculated-amount>
|
113
|
+
<message>You used your Gift Certificate!</message>
|
114
|
+
</gift-certificate-result>
|
115
|
+
</merchant-code-results>
|
116
|
+
</result>
|
117
|
+
</results>
|
118
|
+
</merchant-calculation-results>}
|
119
|
+
|
120
|
+
@results = MerchantCalculationResults.new
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_responds_correctly
|
125
|
+
|
126
|
+
[ :merchant_calculation_results
|
127
|
+
].each do |symbol|
|
128
|
+
assert_respond_to @results, symbol
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_to_xml_works_correctly
|
133
|
+
@coupon_result = CouponResult.new(true, 'FirstVisitCoupon', Money.new(500, 'USD'), 'Congratulations! You saved $5.00 on your first visit!')
|
134
|
+
@gift_certificate_result = GiftCertificateResult.new(true, 'GiftCert012345', Money.new(1000, 'USD'), 'You used your Gift Certificate!')
|
135
|
+
|
136
|
+
@results.create_merchant_calculation_result do |result|
|
137
|
+
result.shipping_name = 'SuperShip'
|
138
|
+
result.address_id = '739030698069958'
|
139
|
+
result.shipping_rate = Money.new(703, 'USD')
|
140
|
+
result.shippable = true
|
141
|
+
result.create_merchant_code_result(@coupon_result)
|
142
|
+
result.create_merchant_code_result(@gift_certificate_result)
|
143
|
+
end
|
144
|
+
|
145
|
+
@results.create_merchant_calculation_result do |result|
|
146
|
+
result.shipping_name = 'UPS Ground'
|
147
|
+
result.address_id = '739030698069958'
|
148
|
+
result.shipping_rate = Money.new(556, 'USD')
|
149
|
+
result.shippable = true
|
150
|
+
result.total_tax = Money.new(1467, 'USD')
|
151
|
+
result.create_merchant_code_result(@coupon_result)
|
152
|
+
result.create_merchant_code_result(@gift_certificate_result)
|
153
|
+
end
|
154
|
+
|
155
|
+
@results.create_merchant_calculation_result do |result|
|
156
|
+
result.shipping_name = 'SuperShip'
|
157
|
+
result.address_id = '421273450774618'
|
158
|
+
result.shipping_rate = Money.new(966, 'USD')
|
159
|
+
result.shippable = true
|
160
|
+
result.total_tax = Money.new(1757, 'USD')
|
161
|
+
result.create_merchant_code_result(@coupon_result)
|
162
|
+
result.create_merchant_code_result(@gift_certificate_result)
|
163
|
+
end
|
164
|
+
|
165
|
+
@results.create_merchant_calculation_result do |result|
|
166
|
+
result.shipping_name = 'UPS Ground'
|
167
|
+
result.address_id = '421273450774618'
|
168
|
+
result.shipping_rate = Money.new(768, 'USD')
|
169
|
+
result.shippable = true
|
170
|
+
result.total_tax = Money.new(1757, 'USD')
|
171
|
+
result.create_merchant_code_result(@coupon_result)
|
172
|
+
result.create_merchant_code_result(@gift_certificate_result)
|
173
|
+
end
|
174
|
+
|
175
|
+
xml = @results.to_xml
|
176
|
+
@results.merchant_calculation_results.each do |result|
|
177
|
+
selector = "merchant-calculation-results > results"
|
178
|
+
selector << " > result[address-id='#{result.address_id}'][shipping-name='#{result.shipping_name}']"
|
179
|
+
|
180
|
+
assert_element_text_equals(result.shipping_rate.to_s,
|
181
|
+
"#{selector} > shipping-rate[currency='#{result.shipping_rate.currency.iso_code}']", xml)
|
182
|
+
assert_element_text_equals(result.shippable ? "true" : "false", "#{selector} > shippable", xml)
|
183
|
+
|
184
|
+
selector << " > merchant-code-results"
|
185
|
+
|
186
|
+
cr_selector = "#{selector} > coupon-result"
|
187
|
+
cr = result.merchant_code_results.select { |r| r.kind_of? CouponResult }.first
|
188
|
+
assert_element_text_equals(cr.valid ? "true" : "false", "#{cr_selector} > valid", xml)
|
189
|
+
assert_element_text_equals(cr.code, "#{cr_selector} > code", xml)
|
190
|
+
assert_element_text_equals(cr.calculated_amount.to_s,
|
191
|
+
"#{cr_selector} > calculated-amount[currency='#{cr.calculated_amount.currency.iso_code}']", xml)
|
192
|
+
assert_element_text_equals(cr.message, "#{cr_selector} > message", xml)
|
193
|
+
|
194
|
+
gc_selector = "#{selector} > gift-certificate-result"
|
195
|
+
gc = result.merchant_code_results.select { |r| r.kind_of? GiftCertificateResult }.first
|
196
|
+
assert_element_text_equals(gc.valid ? "true" : "false", "#{gc_selector} > valid", xml)
|
197
|
+
assert_element_text_equals(gc.code, "#{gc_selector} > code", xml)
|
198
|
+
assert_element_text_equals(gc.calculated_amount.to_s,
|
199
|
+
"#{gc_selector} > calculated-amount[currency='#{gc.calculated_amount.currency.iso_code}']", xml)
|
200
|
+
assert_element_text_equals(gc.message, "#{gc_selector} > message", xml)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|