google4r-checkout 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -60,4 +60,17 @@ class Google4R::Checkout::FrontendTest < Test::Unit::TestCase
60
60
  def test_create_notification_handler_works_correctly
61
61
  assert_kind_of NotificationHandler, @frontend.create_notification_handler
62
62
  end
63
- end
63
+
64
+ def test_create_charge_order_command_works_correctly
65
+ assert_kind_of ChargeOrderCommand, @frontend.create_charge_order_command
66
+ end
67
+
68
+ def test_create_deliver_order_command_works
69
+ assert_kind_of DeliverOrderCommand, @frontend.create_deliver_order_command
70
+ end
71
+
72
+ def test_create_cancel_order_command_works
73
+ assert_kind_of CancelOrderCommand, @frontend.create_cancel_order_command
74
+ end
75
+
76
+ end
@@ -51,17 +51,37 @@ class Google4R::Checkout::NotificationHandlerTest < Test::Unit::TestCase
51
51
  '<order-state-change-notification xmlns="http://checkout.google.com/schema/2" />',
52
52
  'order-state-change-notification',
53
53
  OrderStateChangeNotification
54
- ]
54
+ ],
55
+ [
56
+ '<risk-information-notification xmlns="http://checkout.google.com/schema/2" />',
57
+ 'risk-information-notification',
58
+ RiskInformationNotification
59
+ ],
60
+ [
61
+ '<charge-amount-notification xmlns="http://checkout.google.com/schema/2" />',
62
+ 'charge-amount-notification',
63
+ ChargeAmountNotification
64
+ ],
65
+ [
66
+ '<refund-amount-notification xmlns="http://checkout.google.com/schema/2" />',
67
+ 'refund-amount-notification',
68
+ RefundAmountNotification
69
+ ],
70
+ [
71
+ '<chargeback-amount-notification xmlns="http://checkout.google.com/schema/2" />',
72
+ 'chargeback-amount-notification',
73
+ ChargebackAmountNotification
74
+ ],
75
+ [
76
+ '<authorization-amount-notification xmlns="http://checkout.google.com/schema/2" />',
77
+ 'authorization-amount-notification',
78
+ AuthorizationAmountNotification
79
+ ],
55
80
  ]
56
81
 
57
82
  @xmls_with_unknown_tags =
58
83
  [
59
- '<unknown-notification />',
60
- %q{<risk-information-notification xmlns="http://checkout.google.com/schema/2" />},
61
- %q{<charge-amount-notification xmlns="http://checkout.google.com/schema/2" />},
62
- %q{<refund-amount-notification xmlns="http://checkout.google.com/schema/2" />},
63
- %q{<chargeback-amount-notification xmlns="http://checkout.google.com/schema/2" />},
64
- %q{<authorization-amount-notification xmlns="http://checkout.google.com/schema/2" />}
84
+ '<unknown-notification />'
65
85
  ]
66
86
  end
67
87
 
@@ -90,4 +110,4 @@ class Google4R::Checkout::NotificationHandlerTest < Test::Unit::TestCase
90
110
  assert_raises(UnknownNotificationType) { @notification_handler.handle(xml_str) }
91
111
  end
92
112
  end
93
- end
113
+ end
@@ -47,8 +47,7 @@ class Google4R::Checkout::OrderStateChangeNotificationTest < Test::Unit::TestCas
47
47
  @data[:timestamp] = Time.new
48
48
 
49
49
  @xml_template = %q{<?xml version="1.0" encoding="UTF-8"?>
50
- <order-state-change-notification xmlns="http://checkout.google.com/schema/2"
51
- serial-number="%s">
50
+ <order-state-change-notification xmlns="http://checkout.google.com/schema/2" serial-number="%s">
52
51
  <google-order-number>%s</google-order-number>
53
52
  <new-financial-order-state>%s</new-financial-order-state>
54
53
  <new-fulfillment-order-state>%s</new-fulfillment-order-state>
@@ -0,0 +1,195 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/refund_amount_notification_test.rb
4
+ # Author: Tony Chan <api.htchan AT gmail.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
+ require 'rexml/document'
32
+ require 'test/frontend_configuration'
33
+
34
+ # Test for the class RefundAmountNotification
35
+ class Google4R::Checkout::RefundAmountNotificationTest < 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
+ @example_xml = %q{
43
+ <?xml version="1.0" encoding="UTF-8"?>
44
+ <refund-amount-notification xmlns="http://checkout.google.com/schema/2"
45
+ serial-number="d669f8c7-6d75-4ad6-9278-d2fc997d15f2">
46
+ <google-order-number>841171949013218</google-order-number>
47
+ <latest-refund-amount currency="GBP">226.06</latest-refund-amount>
48
+ <total-refund-amount currency="GBP">226.06</total-refund-amount>
49
+ <timestamp>2006-03-18T20:25:31</timestamp>
50
+ </refund-amount-notification>
51
+ }
52
+ end
53
+
54
+ def test_create_from_element_works_correctly
55
+ root = REXML::Document.new(@example_xml).root
56
+
57
+ notification = RefundAmountNotification.create_from_element(root, @frontend)
58
+
59
+ assert_equal 'd669f8c7-6d75-4ad6-9278-d2fc997d15f2', notification.serial_number
60
+ assert_equal '841171949013218', notification.google_order_number
61
+ assert_equal Time.parse('2006-03-18T20:25:31'), notification.timestamp
62
+ assert_equal(Money.new(22606, 'GBP'), notification.total_refund_amount)
63
+ assert_equal(Money.new(22606, 'GBP'), notification.latest_refund_amount)
64
+ end
65
+ end
66
+ #--
67
+ # Project: google_checkout4r
68
+ # File: test/unit/refund_amount_notification_test.rb
69
+ # Author: Tony Chan <api.htchan AT gmail.com>
70
+ # Copyright: (c) 2007 by Tony Chan
71
+ # License: MIT License as follows:
72
+ #
73
+ # Permission is hereby granted, free of charge, to any person obtaining
74
+ # a copy of this software and associated documentation files (the
75
+ # "Software"), to deal in the Software without restriction, including
76
+ # without limitation the rights to use, copy, modify, merge, publish,
77
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
78
+ # persons to whom the Software is furnished to do so, subject to the
79
+ # following conditions:
80
+ #
81
+ # The above copyright notice and this permission notice shall be included
82
+ # in all copies or substantial portions of the Software.
83
+ #
84
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
85
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
86
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
87
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
88
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
89
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
90
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
91
+ #++
92
+
93
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
94
+
95
+ require 'google4r/checkout'
96
+ require 'rexml/document'
97
+ require 'test/frontend_configuration'
98
+
99
+ # Test for the class RefundAmountNotification
100
+ class Google4R::Checkout::RefundAmountNotificationTest < Test::Unit::TestCase
101
+ include Google4R::Checkout
102
+
103
+ def setup
104
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
105
+ @frontend.tax_table_factory = TestTaxTableFactory.new
106
+
107
+ @example_xml = %q{
108
+ <?xml version="1.0" encoding="UTF-8"?>
109
+ <refund-amount-notification xmlns="http://checkout.google.com/schema/2"
110
+ serial-number="d669f8c7-6d75-4ad6-9278-d2fc997d15f2">
111
+ <google-order-number>841171949013218</google-order-number>
112
+ <latest-refund-amount currency="GBP">226.06</latest-refund-amount>
113
+ <total-refund-amount currency="GBP">226.06</total-refund-amount>
114
+ <timestamp>2006-03-18T20:25:31</timestamp>
115
+ </refund-amount-notification>
116
+ }
117
+ end
118
+
119
+ def test_create_from_element_works_correctly
120
+ root = REXML::Document.new(@example_xml).root
121
+
122
+ notification = RefundAmountNotification.create_from_element(root, @frontend)
123
+
124
+ assert_equal 'd669f8c7-6d75-4ad6-9278-d2fc997d15f2', notification.serial_number
125
+ assert_equal '841171949013218', notification.google_order_number
126
+ assert_equal Time.parse('2006-03-18T20:25:31'), notification.timestamp
127
+ assert_equal(Money.new(22606, 'GBP'), notification.total_refund_amount)
128
+ assert_equal(Money.new(22606, 'GBP'), notification.latest_refund_amount)
129
+ end
130
+ end
131
+ #--
132
+ # Project: google_checkout4r
133
+ # File: test/unit/refund_amount_notification_test.rb
134
+ # Author: Tony Chan <api.htchan AT gmail.com>
135
+ # Copyright: (c) 2007 by Tony Chan
136
+ # License: MIT License as follows:
137
+ #
138
+ # Permission is hereby granted, free of charge, to any person obtaining
139
+ # a copy of this software and associated documentation files (the
140
+ # "Software"), to deal in the Software without restriction, including
141
+ # without limitation the rights to use, copy, modify, merge, publish,
142
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
143
+ # persons to whom the Software is furnished to do so, subject to the
144
+ # following conditions:
145
+ #
146
+ # The above copyright notice and this permission notice shall be included
147
+ # in all copies or substantial portions of the Software.
148
+ #
149
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
150
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
151
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
152
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
153
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
154
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
155
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
156
+ #++
157
+
158
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
159
+
160
+ require 'google4r/checkout'
161
+ require 'rexml/document'
162
+ require 'test/frontend_configuration'
163
+
164
+ # Test for the class RefundAmountNotification
165
+ class Google4R::Checkout::RefundAmountNotificationTest < Test::Unit::TestCase
166
+ include Google4R::Checkout
167
+
168
+ def setup
169
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
170
+ @frontend.tax_table_factory = TestTaxTableFactory.new
171
+
172
+ @example_xml = %q{
173
+ <?xml version="1.0" encoding="UTF-8"?>
174
+ <refund-amount-notification xmlns="http://checkout.google.com/schema/2"
175
+ serial-number="d669f8c7-6d75-4ad6-9278-d2fc997d15f2">
176
+ <google-order-number>841171949013218</google-order-number>
177
+ <latest-refund-amount currency="GBP">226.06</latest-refund-amount>
178
+ <total-refund-amount currency="GBP">226.06</total-refund-amount>
179
+ <timestamp>2006-03-18T20:25:31</timestamp>
180
+ </refund-amount-notification>
181
+ }
182
+ end
183
+
184
+ def test_create_from_element_works_correctly
185
+ root = REXML::Document.new(@example_xml).root
186
+
187
+ notification = RefundAmountNotification.create_from_element(root, @frontend)
188
+
189
+ assert_equal 'd669f8c7-6d75-4ad6-9278-d2fc997d15f2', notification.serial_number
190
+ assert_equal '841171949013218', notification.google_order_number
191
+ assert_equal Time.parse('2006-03-18T20:25:31'), notification.timestamp
192
+ assert_equal(Money.new(22606, 'GBP'), notification.total_refund_amount)
193
+ assert_equal(Money.new(22606, 'GBP'), notification.latest_refund_amount)
194
+ end
195
+ end
@@ -0,0 +1,258 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/refund_order_command_test.rb
4
+ # Author: Tony Chan <api.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
+ # Tests for the RefundOrderCommand class.
35
+ class Google4R::Checkout::RefundOrderCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_refund_order_command
41
+ @command.google_order_number = '841171949013218'
42
+ @command.amount = Money.new(1000, 'USD')
43
+ @command.comment = 'Discount for inconvenience; ship replacement item'
44
+ @command.reason = 'Damaged Merchandise'
45
+
46
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
47
+ <refund-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
48
+ <amount currency='USD'>10.00</amount>
49
+ <comment>Discount for inconvenience; ship replacement item</comment>
50
+ <reason>Damaged Merchandise</reason>
51
+ </refund-order>}
52
+
53
+ @sample_reason_only=%Q{<?xml version='1.0' encoding='UTF-8'?>
54
+ <refund-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
55
+ <reason>Damaged Merchandise</reason>
56
+ </refund-order>}
57
+ end
58
+
59
+ def test_behaves_correctly
60
+ [ :google_order_number, :amount, :reason, :comment ].each do |symbol|
61
+ assert_respond_to @command, symbol
62
+ end
63
+ end
64
+
65
+ def test_xml_with_amount
66
+ @command.amount = nil
67
+ @command.comment = nil
68
+ assert_strings_equal(@sample_reason_only, @command.to_xml)
69
+ end
70
+
71
+ def test_accessors
72
+ assert_equal('841171949013218', @command.google_order_number)
73
+ assert_equal(Money.new(1000, 'USD'), @command.amount)
74
+ assert_equal('Discount for inconvenience; ship replacement item', @command.comment)
75
+ assert_equal('Damaged Merchandise', @command.reason)
76
+ end
77
+
78
+ def test_xml_generation
79
+ assert_strings_equal(@sample_xml, @command.to_xml)
80
+ end
81
+
82
+ def test_to_xml_does_not_raise_exception
83
+ assert_nothing_raised { @command.to_xml }
84
+ end
85
+
86
+ end
87
+ #--
88
+ # Project: google_checkout4r
89
+ # File: test/unit/refund_order_command_test.rb
90
+ # Author: Tony Chan <api.htchan at gmail dot com>
91
+ # Copyright: (c) 2007 by Tony Chan
92
+ # License: MIT License as follows:
93
+ #
94
+ # Permission is hereby granted, free of charge, to any person obtaining
95
+ # a copy of this software and associated documentation files (the
96
+ # "Software"), to deal in the Software without restriction, including
97
+ # without limitation the rights to use, copy, modify, merge, publish,
98
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
99
+ # persons to whom the Software is furnished to do so, subject to the
100
+ # following conditions:
101
+ #
102
+ # The above copyright notice and this permission notice shall be included
103
+ # in all copies or substantial portions of the Software.
104
+ #
105
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
106
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
107
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
108
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
109
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
110
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
111
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
112
+ #++
113
+
114
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
115
+
116
+ require 'google4r/checkout'
117
+
118
+ require 'test/frontend_configuration'
119
+
120
+ # Tests for the RefundOrderCommand class.
121
+ class Google4R::Checkout::RefundOrderCommandTest < Test::Unit::TestCase
122
+ include Google4R::Checkout
123
+
124
+ def setup
125
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
126
+ @command = @frontend.create_refund_order_command
127
+ @command.google_order_number = '841171949013218'
128
+ @command.amount = Money.new(1000, 'USD')
129
+ @command.comment = 'Discount for inconvenience; ship replacement item'
130
+ @command.reason = 'Damaged Merchandise'
131
+
132
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
133
+ <refund-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
134
+ <amount currency='USD'>10.00</amount>
135
+ <comment>Discount for inconvenience; ship replacement item</comment>
136
+ <reason>Damaged Merchandise</reason>
137
+ </refund-order>}
138
+
139
+ @sample_reason_only=%Q{<?xml version='1.0' encoding='UTF-8'?>
140
+ <refund-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
141
+ <reason>Damaged Merchandise</reason>
142
+ </refund-order>}
143
+ end
144
+
145
+ def test_behaves_correctly
146
+ [ :google_order_number, :amount, :reason, :comment ].each do |symbol|
147
+ assert_respond_to @command, symbol
148
+ end
149
+ end
150
+
151
+ def test_xml_with_amount
152
+ @command.amount = nil
153
+ @command.comment = nil
154
+ assert_strings_equal(@sample_reason_only, @command.to_xml)
155
+ end
156
+
157
+ def test_accessors
158
+ assert_equal('841171949013218', @command.google_order_number)
159
+ assert_equal(Money.new(1000, 'USD'), @command.amount)
160
+ assert_equal('Discount for inconvenience; ship replacement item', @command.comment)
161
+ assert_equal('Damaged Merchandise', @command.reason)
162
+ end
163
+
164
+ def test_xml_generation
165
+ assert_strings_equal(@sample_xml, @command.to_xml)
166
+ end
167
+
168
+ def test_to_xml_does_not_raise_exception
169
+ assert_nothing_raised { @command.to_xml }
170
+ end
171
+
172
+ end
173
+ #--
174
+ # Project: google_checkout4r
175
+ # File: test/unit/refund_order_command_test.rb
176
+ # Author: Tony Chan <api.htchan at gmail dot com>
177
+ # Copyright: (c) 2007 by Tony Chan
178
+ # License: MIT License as follows:
179
+ #
180
+ # Permission is hereby granted, free of charge, to any person obtaining
181
+ # a copy of this software and associated documentation files (the
182
+ # "Software"), to deal in the Software without restriction, including
183
+ # without limitation the rights to use, copy, modify, merge, publish,
184
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
185
+ # persons to whom the Software is furnished to do so, subject to the
186
+ # following conditions:
187
+ #
188
+ # The above copyright notice and this permission notice shall be included
189
+ # in all copies or substantial portions of the Software.
190
+ #
191
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
192
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
193
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
194
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
195
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
196
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
197
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
198
+ #++
199
+
200
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
201
+
202
+ require 'google4r/checkout'
203
+
204
+ require 'test/frontend_configuration'
205
+
206
+ # Tests for the RefundOrderCommand class.
207
+ class Google4R::Checkout::RefundOrderCommandTest < Test::Unit::TestCase
208
+ include Google4R::Checkout
209
+
210
+ def setup
211
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
212
+ @command = @frontend.create_refund_order_command
213
+ @command.google_order_number = '841171949013218'
214
+ @command.amount = Money.new(1000, 'USD')
215
+ @command.comment = 'Discount for inconvenience; ship replacement item'
216
+ @command.reason = 'Damaged Merchandise'
217
+
218
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
219
+ <refund-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
220
+ <amount currency='USD'>10.00</amount>
221
+ <comment>Discount for inconvenience; ship replacement item</comment>
222
+ <reason>Damaged Merchandise</reason>
223
+ </refund-order>}
224
+
225
+ @sample_reason_only=%Q{<?xml version='1.0' encoding='UTF-8'?>
226
+ <refund-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
227
+ <reason>Damaged Merchandise</reason>
228
+ </refund-order>}
229
+ end
230
+
231
+ def test_behaves_correctly
232
+ [ :google_order_number, :amount, :reason, :comment ].each do |symbol|
233
+ assert_respond_to @command, symbol
234
+ end
235
+ end
236
+
237
+ def test_xml_with_amount
238
+ @command.amount = nil
239
+ @command.comment = nil
240
+ assert_strings_equal(@sample_reason_only, @command.to_xml)
241
+ end
242
+
243
+ def test_accessors
244
+ assert_equal('841171949013218', @command.google_order_number)
245
+ assert_equal(Money.new(1000, 'USD'), @command.amount)
246
+ assert_equal('Discount for inconvenience; ship replacement item', @command.comment)
247
+ assert_equal('Damaged Merchandise', @command.reason)
248
+ end
249
+
250
+ def test_xml_generation
251
+ assert_strings_equal(@sample_xml, @command.to_xml)
252
+ end
253
+
254
+ def test_to_xml_does_not_raise_exception
255
+ assert_nothing_raised { @command.to_xml }
256
+ end
257
+
258
+ end