nbudin-google4r-checkout 1.0.6
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/.gitignore +3 -0
- data/CHANGES +83 -0
- data/LICENSE +22 -0
- data/README +58 -0
- data/Rakefile +80 -0
- data/VERSION +1 -0
- data/lib/google4r/checkout/commands.rb +515 -0
- data/lib/google4r/checkout/frontend.rb +204 -0
- data/lib/google4r/checkout/merchant_calculation.rb +321 -0
- data/lib/google4r/checkout/notifications.rb +708 -0
- data/lib/google4r/checkout/shared.rb +1249 -0
- data/lib/google4r/checkout/utils.rb +94 -0
- data/lib/google4r/checkout/xml_generation.rb +920 -0
- data/lib/google4r/checkout.rb +34 -0
- data/test/frontend_configuration.rb +13 -0
- data/test/integration/checkout_command_test.rb +246 -0
- data/test/test_helper.rb +115 -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 +136 -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_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/test/xml/apiv2.xsd +997 -0
- data/test/xml/test_check_persisting_works_expected.xml +213 -0
- data/var/cacert.pem +7815 -0
- metadata +200 -0
@@ -0,0 +1,171 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/area_test.rb
|
4
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
6
|
+
# License: MIT License as follows:
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
13
|
+
# persons to whom the Software is furnished to do so, subject to the
|
14
|
+
# following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be included
|
17
|
+
# in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
20
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
22
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
23
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
24
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
25
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
#++
|
27
|
+
|
28
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
29
|
+
|
30
|
+
require 'google4r/checkout'
|
31
|
+
|
32
|
+
require 'test/frontend_configuration'
|
33
|
+
|
34
|
+
# 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
|
+
<item-weight unit='LB' value='2.2'/>
|
47
|
+
<unit-price currency="USD">178.00</unit-price>
|
48
|
+
<quantity>1</quantity>
|
49
|
+
<merchant-item-id>MGS2GBMP3</merchant-item-id>
|
50
|
+
<merchant-private-item-data>
|
51
|
+
<item-note>Text 1</item-note>
|
52
|
+
<item-note>Text 2</item-note>
|
53
|
+
<nested>
|
54
|
+
<tags>value</tags>
|
55
|
+
</nested>
|
56
|
+
</merchant-private-item-data>
|
57
|
+
<tax-table-selector>Some Table</tax-table-selector>
|
58
|
+
<digital-content>
|
59
|
+
<display-disposition>OPTIMISTIC</display-disposition>
|
60
|
+
<email-delivery>true</email-delivery>
|
61
|
+
</digital-content>
|
62
|
+
</item>}
|
63
|
+
|
64
|
+
@optional_tags = [ 'merchant-item-id', 'merchant-private-item-data', 'tax-table-selector' ]
|
65
|
+
|
66
|
+
@command = @frontend.create_checkout_command
|
67
|
+
@shopping_cart = @command.shopping_cart
|
68
|
+
@item = @shopping_cart.create_item
|
69
|
+
@digital_content = @item.digital_content
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_item_behaves_correctly
|
73
|
+
[ :shopping_cart, :name, :name=, :description, :description=, :unit_price, :unit_price=,
|
74
|
+
:quantity, :quantity=, :id, :id=, :private_data, :private_data=,
|
75
|
+
:tax_table, :tax_table=, :digital_content, :weight, :weight=
|
76
|
+
].each do |symbol|
|
77
|
+
assert_respond_to @item, symbol
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_item_gets_initialized_correctly
|
82
|
+
assert_equal @shopping_cart, @item.shopping_cart
|
83
|
+
assert_nil @item.name
|
84
|
+
assert_nil @item.description
|
85
|
+
assert_nil @item.unit_price
|
86
|
+
assert_nil @item.quantity
|
87
|
+
assert_nil @item.private_data
|
88
|
+
assert_nil @item.id
|
89
|
+
assert_nil @item.tax_table
|
90
|
+
assert_nil @item.digital_content
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_item_setters_work
|
94
|
+
@item.name = "name"
|
95
|
+
assert_equal "name", @item.name
|
96
|
+
|
97
|
+
@item.description = "description"
|
98
|
+
assert_equal "description", @item.description
|
99
|
+
|
100
|
+
@item.unit_price = Money.new(100, "EUR")
|
101
|
+
assert_equal Money.new(100, "EUR"), @item.unit_price
|
102
|
+
|
103
|
+
@item.quantity = 10
|
104
|
+
assert_equal 10, @item.quantity
|
105
|
+
|
106
|
+
@item.id = "id"
|
107
|
+
assert_equal "id", @item.id
|
108
|
+
|
109
|
+
@item.private_data = Hash.new
|
110
|
+
assert_equal Hash.new, @item.private_data
|
111
|
+
|
112
|
+
@item.weight = Weight.new(2.2)
|
113
|
+
assert_equal Weight, @item.weight.class
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_set_tax_table_works
|
117
|
+
table = @command.tax_tables.first
|
118
|
+
@item.tax_table = table
|
119
|
+
assert_equal table, @item.tax_table
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_set_tax_table_raises_if_table_is_unknown_in_command
|
123
|
+
assert_raises(RuntimeError) { @item.tax_table = TaxTable.new(false) }
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_set_private_data_only_works_with_hashes
|
127
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = 1 }
|
128
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = nil }
|
129
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = 'Foobar' }
|
130
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = [] }
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_item_price_must_be_money_instance
|
134
|
+
assert_raises(RuntimeError) { @item.unit_price = nil }
|
135
|
+
assert_raises(RuntimeError) { @item.unit_price = "String" }
|
136
|
+
assert_raises(RuntimeError) { @item.unit_price = 10 }
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_create_from_element_works
|
140
|
+
@optional_tags.power.each do |optional_tag_names|
|
141
|
+
xml_str = @xml_str
|
142
|
+
|
143
|
+
optional_tag_names.each { |name| xml_str = xml_str.gsub(%r{<#{name}.*?</#{name}>}, '') }
|
144
|
+
|
145
|
+
command = @frontend.create_checkout_command
|
146
|
+
tax_table = TaxTable.new(false)
|
147
|
+
tax_table.name = 'Some Table'
|
148
|
+
command.tax_tables << tax_table
|
149
|
+
item = Item.create_from_element(REXML::Document.new(xml_str).root, command.shopping_cart)
|
150
|
+
|
151
|
+
assert_equal command.shopping_cart, item.shopping_cart
|
152
|
+
|
153
|
+
assert_equal 'MegaSound 2GB MP3 Player', item.name
|
154
|
+
assert_equal 'Portable MP3 player - stores 500 songs', item.description
|
155
|
+
assert_equal Money.new(17800, 'USD'), item.unit_price
|
156
|
+
assert_equal 1, item.quantity
|
157
|
+
assert_equal 'MGS2GBMP3', item.id unless item.id.nil?
|
158
|
+
assert_equal 2.2, item.weight.value
|
159
|
+
assert_equal 'LB', item.weight.unit
|
160
|
+
|
161
|
+
hash =
|
162
|
+
{
|
163
|
+
'item-note' => [ 'Text 1', 'Text 2' ],
|
164
|
+
'nested' => { 'tags' => 'value' }
|
165
|
+
}
|
166
|
+
assert_equal hash, item.private_data unless optional_tag_names.include?('merchant-private-item-data')
|
167
|
+
|
168
|
+
assert_equal 'Some Table', item.tax_table.name unless optional_tag_names.include?('tax-table-selector')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -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
|