archerfinley-google4r-checkout-1.0.5 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +93 -0
- data/LICENSE +22 -0
- data/README +58 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/google4r-checkout-1.0.5-1.0.5.gem +0 -0
- data/google4r-checkout-1.0.5.gemspec +174 -0
- data/lib/google4r/checkout.rb +34 -0
- data/lib/google4r/checkout/commands.rb +567 -0
- data/lib/google4r/checkout/frontend.rb +210 -0
- data/lib/google4r/checkout/merchant_calculation.rb +321 -0
- data/lib/google4r/checkout/notifications.rb +708 -0
- data/lib/google4r/checkout/shared.rb +1086 -0
- data/lib/google4r/checkout/utils.rb +94 -0
- data/lib/google4r/checkout/xml_generation.rb +880 -0
- data/test/integration/checkout_command_test.rb +174 -0
- data/test/unit/add_merchant_order_number_command_test.rb +70 -0
- data/test/unit/add_tracking_data_command_test.rb +75 -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 +66 -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 +66 -0
- data/test/unit/backorder_items_command_test.rb +83 -0
- data/test/unit/callback_handler_test.rb +83 -0
- data/test/unit/cancel_items_command_test.rb +89 -0
- data/test/unit/cancel_order_command_test.rb +83 -0
- data/test/unit/carrier_calculated_shipping_test.rb +57 -0
- data/test/unit/charge_amount_notification_test.rb +64 -0
- data/test/unit/charge_order_command_test.rb +77 -0
- data/test/unit/chargeback_amount_notification_test.rb +65 -0
- data/test/unit/checkout_command_test.rb +125 -0
- data/test/unit/checkout_command_xml_generator_test.rb +218 -0
- data/test/unit/command_test.rb +116 -0
- data/test/unit/deliver_order_command_test.rb +70 -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 +132 -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 +172 -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 +178 -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 +111 -0
- data/test/unit/order_state_change_notification_test.rb +158 -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 +65 -0
- data/test/unit/refund_order_command_test.rb +86 -0
- data/test/unit/reset_items_shipping_information_command_test.rb +83 -0
- data/test/unit/return_items_command_test.rb +83 -0
- data/test/unit/risk_information_notification_test.rb +98 -0
- data/test/unit/send_buyer_message_command_test.rb +73 -0
- data/test/unit/ship_items_command_test.rb +101 -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 +82 -0
- data/test/unit/tracking_data_test.rb +54 -0
- data/test/unit/unarchive_order_command_test.rb +66 -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 +189 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/marketing_preferences_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 MarketingPreferences.
|
35
|
+
class Google4R::Checkout::MarketingPreferencesTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
40
|
+
<marketing-preferences>
|
41
|
+
<email-allowed>%s</email-allowed>
|
42
|
+
</marketing-preferences>
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_responds_correctly
|
47
|
+
@preferences = MarketingPreferences.new
|
48
|
+
|
49
|
+
[ :email_allowed, :email_allowed= ].each do |symbol|
|
50
|
+
assert_respond_to @preferences, symbol
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_create_from_element_works_correctly
|
55
|
+
{ 'true' => true, 'True' => true, 'TRUE' => true, 'false' => false, 'Frue' => false,
|
56
|
+
'FALSE' => false }.each do |str, bool|
|
57
|
+
xml_str = @xml_str % str
|
58
|
+
|
59
|
+
element = REXML::Document.new(xml_str).root
|
60
|
+
pref = MarketingPreferences.create_from_element(element)
|
61
|
+
|
62
|
+
assert_equal bool, pref.email_allowed
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,172 @@
|
|
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
|
+
:create_allowed_area, :create_excluded_area, :create_area
|
47
|
+
].each do |symbol|
|
48
|
+
assert_respond_to @shipping, symbol
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_initialization
|
53
|
+
assert_nil @shipping.name
|
54
|
+
assert_nil @shipping.price
|
55
|
+
assert_equal [], @shipping.shipping_restrictions_allowed_areas
|
56
|
+
assert_equal [], @shipping.shipping_restrictions_excluded_areas
|
57
|
+
assert_equal [], @shipping.address_filters_allowed_areas
|
58
|
+
assert_equal [], @shipping.address_filters_excluded_areas
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_merchant_calculated_shipping_setting_attributes_works_correctly
|
62
|
+
@shipping.name = "Shipping Method Name"
|
63
|
+
assert_equal "Shipping Method Name", @shipping.name
|
64
|
+
|
65
|
+
@shipping.price = Money.new(100, "EUR")
|
66
|
+
assert_kind_of Money, @shipping.price
|
67
|
+
assert_equal 100, @shipping.price.cents
|
68
|
+
assert_equal "EUR", @shipping.price.currency
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_merchant_calculated_shipping_price_is_validated
|
72
|
+
# Test that MerchantCalculatedShipping checks for its price attribute responding
|
73
|
+
# to cents and currency.
|
74
|
+
assert_raises(RuntimeError) { @shipping.price = nil }
|
75
|
+
assert_raises(RuntimeError) { @shipping.price = 10 }
|
76
|
+
assert_raises(RuntimeError) { @shipping.price = "str" }
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_create_allowed_excluded_areas_works_with_block
|
80
|
+
[ [ :shipping_restrictions_allowed_areas, :create_allowed_area ],
|
81
|
+
[ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
|
82
|
+
read_sym, create_sym = pair
|
83
|
+
|
84
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
85
|
+
|
86
|
+
the_area = nil
|
87
|
+
|
88
|
+
res =
|
89
|
+
@shipping.send(create_sym, clazz) do |area|
|
90
|
+
the_area = area
|
91
|
+
assert_kind_of clazz, area
|
92
|
+
end
|
93
|
+
|
94
|
+
assert_equal res, the_area
|
95
|
+
assert @shipping.send(read_sym).include?(the_area)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_create_allowed_excluded_areas_works_without_block
|
101
|
+
[ [ :shipping_restrictions_allowed_areas, :create_allowed_area],
|
102
|
+
[ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
|
103
|
+
read_sym, create_sym = pair
|
104
|
+
|
105
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
106
|
+
area = @shipping.send(create_sym, clazz)
|
107
|
+
|
108
|
+
assert_kind_of clazz, area
|
109
|
+
|
110
|
+
assert @shipping.send(read_sym).include?(area)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_create_shipping_restrictions_allowed_excluded_areas_works_with_block
|
116
|
+
[ [ :shipping_restrictions_allowed_areas, :create_shipping_restrictions_allowed_area ],
|
117
|
+
[ :shipping_restrictions_excluded_areas, :create_shipping_restrictions_excluded_area ] ].each do |pair|
|
118
|
+
read_sym, create_sym = pair
|
119
|
+
|
120
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
121
|
+
|
122
|
+
the_area = nil
|
123
|
+
|
124
|
+
res =
|
125
|
+
@shipping.send(create_sym, clazz) do |area|
|
126
|
+
the_area = area
|
127
|
+
assert_kind_of clazz, area
|
128
|
+
end
|
129
|
+
|
130
|
+
assert_equal res, the_area
|
131
|
+
assert @shipping.send(read_sym).include?(the_area)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_create_shipping_restrictions_allowed_excluded_areas_works_without_block
|
137
|
+
[ [ :shipping_restrictions_allowed_areas, :create_shipping_restrictions_allowed_area],
|
138
|
+
[ :shipping_restrictions_excluded_areas, :create_shipping_restrictions_excluded_area ] ].each do |pair|
|
139
|
+
read_sym, create_sym = pair
|
140
|
+
|
141
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
142
|
+
area = @shipping.send(create_sym, clazz)
|
143
|
+
|
144
|
+
assert_kind_of clazz, area
|
145
|
+
|
146
|
+
assert @shipping.send(read_sym).include?(area)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_create_allowed_excluded_areas_validates_parameter
|
152
|
+
[ :create_allowed_area, :create_excluded_area ].each do |sym|
|
153
|
+
assert_raises(RuntimeError) { @shipping.send(sym, String) }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_new_create_area_with_merchant_calculated_shipping
|
158
|
+
[ [ :shipping_restrictions, :allowed_areas ],
|
159
|
+
[ :shipping_restrictions, :excluded_areas ],
|
160
|
+
[ :address_filters, :allowed_areas ],
|
161
|
+
[ :address_filters, :excluded_areas ] ].each do |pair|
|
162
|
+
type_sym, area_sym = pair
|
163
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
164
|
+
area = @shipping.send(:create_area, type_sym, area_sym, clazz)
|
165
|
+
|
166
|
+
assert_kind_of clazz, area
|
167
|
+
|
168
|
+
assert @shipping.send((type_sym.to_s + '_' + area_sym.to_s).to_sym).include?(area)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
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(1).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 = CouponResult.stubs(:new)
|
41
|
+
expect.times(1).returns(:coupon_result)
|
42
|
+
|
43
|
+
expect = GiftCertificateResult.stubs(:new)
|
44
|
+
expect.times(1).returns(:gift_certificate_result)
|
45
|
+
|
46
|
+
expect = Money.stubs(:new)
|
47
|
+
expect.times(1).returns(:shipping_rate, :total_tax)
|
48
|
+
|
49
|
+
@result = MerchantCalculationResult.new('UPS Ground', '1234567890', Money.new(1000, 'USD'), true, Money.new(2000, 'USD'))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_responds_correctly
|
53
|
+
|
54
|
+
[ :shipping_name, :shipping_name=,
|
55
|
+
:address_id, :address_id=,
|
56
|
+
:shipping_rate, :shipping_rate=,
|
57
|
+
:shippable, :shippable=,
|
58
|
+
:total_tax, :total_tax=,
|
59
|
+
:merchant_code_results
|
60
|
+
].each do |symbol|
|
61
|
+
assert_respond_to @result, symbol
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_create_merchant_code_result_works_correctly
|
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
|