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,178 @@
|
|
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
|
+
# perform the assertions
|
176
|
+
assert_strings_equal @xml_str, @results.to_xml
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/merchant_code_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 MerchantCode.
|
35
|
+
class Google4R::Checkout::MerchantCodeResultTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_responds_correctly
|
43
|
+
adjustment = CouponResult.new(true, 'some_code', Money.new(1000, 'USD'), 'A message')
|
44
|
+
|
45
|
+
[ :valid, :valid=, :code, :code=, :calculated_amount,
|
46
|
+
:calculated_amount=, :message, :message=,
|
47
|
+
].each do |sym|
|
48
|
+
assert_respond_to adjustment, sym
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/merchant_code_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 MerchantCode.
|
35
|
+
class Google4R::Checkout::MerchantCodeTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@valid_adjustment_types =
|
40
|
+
[
|
41
|
+
[ "GIFT_CERTIFICATE", 'gift-certificate-adjustment' ],
|
42
|
+
[ "COUPON", 'coupon-adjustment' ],
|
43
|
+
]
|
44
|
+
|
45
|
+
@optional_tag_names = [ 'calculated-amount', 'message' ]
|
46
|
+
|
47
|
+
@invalid_adjustment_types = [ 'invalid-adjustment' ]
|
48
|
+
|
49
|
+
@xml_str = %q{<?xml version="1.0" encodig="UTF-8"?>
|
50
|
+
<%s>
|
51
|
+
<applied-amount currency="%s">%s</applied-amount>
|
52
|
+
<code>%s</code>
|
53
|
+
<calculated-amount currency="%s">%s</calculated-amount>
|
54
|
+
<message>%s</message>
|
55
|
+
</%s>}
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_constants_are_defined
|
59
|
+
assert defined?(MerchantCode::GIFT_CERTIFICATE)
|
60
|
+
assert defined?(MerchantCode::COUPON)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_responds_correctly
|
64
|
+
adjustment = MerchantCode.new
|
65
|
+
|
66
|
+
[ :applied_amount, :applied_amount=, :code, :code=, :calculated_amount,
|
67
|
+
:calculated_amount=, :message, :message=,
|
68
|
+
].each do |sym|
|
69
|
+
assert_respond_to adjustment, sym
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_create_from_element_works_with_valid_adjustment_types
|
74
|
+
@valid_adjustment_types.each do |pair|
|
75
|
+
type, tag_name = pair
|
76
|
+
|
77
|
+
@optional_tag_names.power.each do |optional_tag_names|
|
78
|
+
xml_str = @xml_str %
|
79
|
+
[
|
80
|
+
tag_name, 'USD', '10.00', 'some-code', 'USD', '20.00', 'Message!', tag_name
|
81
|
+
]
|
82
|
+
|
83
|
+
optional_tag_names.each { |name| xml_str = xml_str.gsub(%r{<#{name}.*?</#{name}>}, '') }
|
84
|
+
|
85
|
+
xml_doc = REXML::Document.new(xml_str)
|
86
|
+
xml_element = xml_doc.root.elements["/#{tag_name}"]
|
87
|
+
|
88
|
+
adjustment = MerchantCode.create_from_element(xml_element)
|
89
|
+
|
90
|
+
assert_equal Money.new(1000, 'USD'), adjustment.applied_amount
|
91
|
+
assert_equal type, adjustment.type
|
92
|
+
assert_equal 'some-code', adjustment.code
|
93
|
+
|
94
|
+
if not optional_tag_names.include?('calculated-amount') then
|
95
|
+
assert_equal Money.new(2000, 'USD'), adjustment.calculated_amount
|
96
|
+
else
|
97
|
+
assert_nil adjustment.calculated_amount
|
98
|
+
end
|
99
|
+
if not optional_tag_names.include?('message') then
|
100
|
+
assert_equal 'Message!', adjustment.message
|
101
|
+
else
|
102
|
+
assert_nil adjustment.message
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_create_from_element_raises_argument_error_with_invalid_shipping_adjustment_types
|
109
|
+
@invalid_adjustment_types.each do |tag_name|
|
110
|
+
xml_str = @xml_str %
|
111
|
+
[
|
112
|
+
tag_name, 'USD', '10.00', 'some-code', 'USD', '20.00', 'Message!', tag_name
|
113
|
+
]
|
114
|
+
|
115
|
+
xml_element = REXML::Document.new(xml_str).root
|
116
|
+
|
117
|
+
assert_raises(ArgumentError) do
|
118
|
+
adjustment = MerchantCode.create_from_element(xml_element)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/new_order_confirmation_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 NewOrderConfirmation.
|
35
|
+
class Google4R::Checkout::NewOrderNotificationTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
40
|
+
<new-order-notification xmlns="http://checkout.google.com/schema/2" serial-number="8571632143">
|
41
|
+
<google-order-number>6014423719</google-order-number>
|
42
|
+
<buyer-billing-address />
|
43
|
+
<buyer-id>294873009217523</buyer-id>
|
44
|
+
<buyer-marketing-preferences />
|
45
|
+
<buyer-shipping-address />
|
46
|
+
<financial-order-state>REVIEWING</financial-order-state>
|
47
|
+
<fulfillment-order-state>NEW</fulfillment-order-state>
|
48
|
+
<google-order-number>6014423719</google-order-number>
|
49
|
+
<order-adjustment />
|
50
|
+
<order-total currency="USD">321.98</order-total>
|
51
|
+
<shopping-cart />
|
52
|
+
<timestamp>2006-03-18T17:32:11</timestamp>
|
53
|
+
</new-order-notification>}
|
54
|
+
|
55
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
56
|
+
@frontend.tax_table_factory = TestTaxTableFactory.new
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_responds_correctly
|
60
|
+
assert_respond_to NewOrderNotification, :create_from_element
|
61
|
+
|
62
|
+
notification = NewOrderNotification.new(@frontend)
|
63
|
+
|
64
|
+
[ :serial_number, :google_order_number, :buyer_billing_address, :buyer_shipping_address,
|
65
|
+
:buyer_id, :marketing_preferences, :financial_order_state, :fulfillment_order_state,
|
66
|
+
:google_order_number, :order_adjustment, :order_total, :shopping_cart, :timestamp,
|
67
|
+
:serial_number=, :google_order_number=, :buyer_billing_address=, :buyer_shipping_address=,
|
68
|
+
:buyer_id=, :marketing_preferences=, :financial_order_state=, :fulfillment_order_state=,
|
69
|
+
:google_order_number=, :order_adjustment=, :order_total=, :shopping_cart=, :timestamp=,
|
70
|
+
].each do |symbol|
|
71
|
+
assert_respond_to notification, symbol
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_create_from_element_works_correctly
|
76
|
+
# Build up some Mocha expectations.
|
77
|
+
expect = Address.stubs(:create_from_element)
|
78
|
+
expect.times(1).returns(:buyer_billing_address)
|
79
|
+
expect.with{ |element| element.name == 'buyer-billing-address' }
|
80
|
+
|
81
|
+
expect = Address.stubs(:create_from_element)
|
82
|
+
expect.times(1).returns(:buyer_shipping_address)
|
83
|
+
expect.with{ |element| element.name == 'buyer-shipping-address' }
|
84
|
+
|
85
|
+
expect = MarketingPreferences.stubs(:create_from_element)
|
86
|
+
expect.times(1).returns(:marketing_preferences)
|
87
|
+
expect.with{ |element| element.name == 'buyer-marketing-preferences' }
|
88
|
+
|
89
|
+
expect = OrderAdjustment.stubs(:create_from_element)
|
90
|
+
expect.times(1).returns(:order_adjustment)
|
91
|
+
expect.with{ |element| element.name == 'order-adjustment' }
|
92
|
+
|
93
|
+
expect = ShoppingCart.stubs(:create_from_element)
|
94
|
+
expect.times(1).returns(:shopping_cart)
|
95
|
+
expect.with { |element, owner| element.name == 'shopping-cart' and owner.kind_of?(NewOrderNotification) }
|
96
|
+
|
97
|
+
# Create the new notification.
|
98
|
+
notification = NewOrderNotification.create_from_element(REXML::Document.new(@xml_str).root, @frontend)
|
99
|
+
|
100
|
+
# perform the assertions
|
101
|
+
assert_equal "8571632143", notification.serial_number
|
102
|
+
assert_equal "6014423719", notification.google_order_number
|
103
|
+
assert_equal :buyer_billing_address, notification.buyer_billing_address
|
104
|
+
assert_equal :buyer_shipping_address, notification.buyer_shipping_address
|
105
|
+
assert_equal "294873009217523", notification.buyer_id
|
106
|
+
assert_equal :marketing_preferences, notification.marketing_preferences
|
107
|
+
assert_equal "REVIEWING", notification.financial_order_state
|
108
|
+
assert_equal "NEW", notification.fulfillment_order_state
|
109
|
+
assert_equal "6014423719", notification.google_order_number
|
110
|
+
assert_equal :order_adjustment, notification.order_adjustment
|
111
|
+
assert_equal Money.new(32198, "USD"), notification.order_total
|
112
|
+
assert_equal :shopping_cart, notification.shopping_cart
|
113
|
+
assert_equal Time.parse("2006-03-18T17:32:11"), notification.timestamp
|
114
|
+
end
|
115
|
+
end
|