google4r-checkout 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/CHANGES +40 -0
  2. data/LICENSE +22 -0
  3. data/README +76 -0
  4. data/lib/google4r/checkout.rb +33 -0
  5. data/lib/google4r/checkout/commands.rb +260 -0
  6. data/lib/google4r/checkout/frontend.rb +108 -0
  7. data/lib/google4r/checkout/notifications.rb +549 -0
  8. data/lib/google4r/checkout/shared.rb +541 -0
  9. data/lib/google4r/checkout/xml_generation.rb +313 -0
  10. data/test/integration/checkout_command_test.rb +103 -0
  11. data/test/unit/address_test.rb +131 -0
  12. data/test/unit/area_test.rb +44 -0
  13. data/test/unit/checkout_command_test.rb +116 -0
  14. data/test/unit/checkout_command_xml_generator_test.rb +203 -0
  15. data/test/unit/command_test.rb +115 -0
  16. data/test/unit/flat_rate_shipping_test.rb +114 -0
  17. data/test/unit/frontend_test.rb +63 -0
  18. data/test/unit/item_test.rb +159 -0
  19. data/test/unit/marketing_preferences_test.rb +65 -0
  20. data/test/unit/merchant_code_test.rb +122 -0
  21. data/test/unit/new_order_notification_test.rb +115 -0
  22. data/test/unit/notification_acknowledgement_test.rb +43 -0
  23. data/test/unit/notification_handler_test.rb +93 -0
  24. data/test/unit/order_adjustment_test.rb +119 -0
  25. data/test/unit/order_state_change_notification_test.rb +159 -0
  26. data/test/unit/pickup_shipping_test.rb +70 -0
  27. data/test/unit/postal_area_test.rb +71 -0
  28. data/test/unit/private_data_parser_test.rb +68 -0
  29. data/test/unit/shipping_adjustment_test.rb +100 -0
  30. data/test/unit/shipping_method_test.rb +41 -0
  31. data/test/unit/shopping_cart_test.rb +146 -0
  32. data/test/unit/tax_rule_test.rb +70 -0
  33. data/test/unit/tax_table_test.rb +82 -0
  34. data/test/unit/us_country_area_test.rb +76 -0
  35. data/test/unit/us_state_area_test.rb +70 -0
  36. data/test/unit/us_zip_area_test.rb +66 -0
  37. data/test/unit/world_area_test.rb +48 -0
  38. data/var/cacert.pem +7815 -0
  39. metadata +92 -0
@@ -0,0 +1,44 @@
1
+ require 'google4r/checkout'
2
+
3
+ require 'test/frontend_configuration'
4
+ #--
5
+ # Project: google_checkout4r
6
+ # File: test/unit/area_test.rb
7
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
8
+ # Copyright: (c) 2007 by Manuel Holtgrewe
9
+ # License: MIT License as follows:
10
+ #
11
+ # Permission is hereby granted, free of charge, to any person obtaining
12
+ # a copy of this software and associated documentation files (the
13
+ # "Software"), to deal in the Software without restriction, including
14
+ # without limitation the rights to use, copy, modify, merge, publish,
15
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
16
+ # persons to whom the Software is furnished to do so, subject to the
17
+ # following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be included
20
+ # in all copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
28
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ #++
30
+
31
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
32
+
33
+ require 'google4r/checkout'
34
+
35
+ require 'test/frontend_configuration'
36
+
37
+ # Test for the class Area.
38
+ class Google4R::Checkout::AreaTest < Test::Unit::TestCase
39
+ include Google4R::Checkout
40
+
41
+ def test_instanciating_area_raises_runtime_error
42
+ assert_raises(RuntimeError) { Area.new }
43
+ end
44
+ end
@@ -0,0 +1,116 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/checkout_command_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
+ # Tests for the CheckoutCommand class.
35
+ class Google4R::Checkout::CheckoutCommandTest < 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
+ @command = @frontend.create_checkout_command
42
+ end
43
+
44
+ def test_tax_table_factory_works_correctly
45
+ TestTaxTableFactory.any_instance.stubs(:effective_tax_tables_at).returns([:tax_table])
46
+
47
+ frontend = Frontend.new(FRONTEND_CONFIGURATION)
48
+ frontend.tax_table_factory = TestTaxTableFactory.new
49
+ command = frontend.create_checkout_command
50
+
51
+ assert_equal [:tax_table], command.tax_tables
52
+ end
53
+
54
+ def test_initialized_correctly
55
+ assert_equal @frontend, @command.frontend
56
+ assert_kind_of ShoppingCart, @command.shopping_cart
57
+ assert_equal [], @command.shipping_methods
58
+ assert_nil @command.edit_cart_url
59
+ assert_nil @command.continue_shopping_url
60
+ assert_nil @command.request_buyer_phone_number
61
+ end
62
+
63
+ def test_command_behaves_correctly
64
+ [ :frontend, :shopping_cart, :tax_tables, :shipping_methods, :create_shipping_method,
65
+ :edit_cart_url, :edit_cart_url=, :continue_shopping_url, :continue_shopping_url=,
66
+ :request_buyer_phone_number, :request_buyer_phone_number=
67
+ ].each do |symbol|
68
+ assert_respond_to @command, symbol
69
+ end
70
+ end
71
+
72
+ def test_accessors_work_correctly
73
+ @command.edit_cart_url = "edit cart url"
74
+ assert_equal "edit cart url", @command.edit_cart_url
75
+
76
+ @command.continue_shopping_url = "continue shopping url"
77
+ assert_equal "continue shopping url", @command.continue_shopping_url
78
+
79
+ @command.request_buyer_phone_number = true
80
+ assert_equal true, @command.request_buyer_phone_number
81
+ end
82
+
83
+ def test_create_shipping_method_works_correctly_with_block
84
+ [ PickupShipping, FlatRateShipping ].each do |clazz|
85
+
86
+ shipping = nil
87
+
88
+ res =
89
+ @command.create_shipping_method(clazz) do |obj|
90
+ shipping = obj
91
+ assert_kind_of clazz, obj
92
+ end
93
+
94
+ assert_equal res, shipping
95
+ assert @command.shipping_methods.include?(shipping)
96
+ end
97
+ end
98
+
99
+ def test_create_shipping_method_works_correctly_without_block
100
+ [ PickupShipping, FlatRateShipping ].each do |clazz|
101
+ obj = @command.create_shipping_method(clazz)
102
+
103
+ assert_kind_of clazz, obj
104
+
105
+ assert @command.shipping_methods.include?(obj)
106
+ end
107
+ end
108
+
109
+ def test_create_shipping_method_raises_exception_on_invalid_clazz_parameter
110
+ assert_raises(ArgumentError) { @command.create_shipping_method(String) }
111
+ end
112
+
113
+ def test_to_xml_does_not_raise_exception
114
+ assert_nothing_raised { @command.to_xml }
115
+ end
116
+ end
@@ -0,0 +1,203 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/checkout_command_xml_generator_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
+ require 'tempfile'
35
+ require 'open3'
36
+ require 'rexml/document'
37
+
38
+ # Test for the class UsZipArea.
39
+ #
40
+ # TODO: Make the tests querying Google Checkout's diagnose service and the XSD validation optional.
41
+ class Google4R::Checkout::CheckoutCommandXmlGeneratorTest < Test::Unit::TestCase
42
+ include Google4R::Checkout
43
+
44
+ def setup
45
+ @schema_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'xml', 'apiv2.xsd'))
46
+ @expected_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'xml', 'test_check_persisting_works_expected.xml'))
47
+
48
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
49
+ @frontend.tax_table_factory = TestTaxTableFactory.new
50
+ @command = @frontend.create_checkout_command
51
+ @generator = CheckoutCommandXmlGenerator.new(@command)
52
+ end
53
+
54
+ # Note that this is not really a good test. We do not actually compare anything.
55
+ # Instead, we simply generate some XML, validate it using XSD via xmllint and then
56
+ # compare it to the output that we validated by reading it earlier.
57
+ def test_check_persisting_works
58
+ tax_tables = Array.new
59
+ table = TaxTable.new(false)
60
+ table.name = 'Default Table'
61
+ table.create_rule do |rule|
62
+ rule.rate = 0.04
63
+ rule.area = UsCountryArea.new
64
+ rule.area.area = UsCountryArea::ALL
65
+ end
66
+ table.create_rule do |rule|
67
+ rule.area=Google4R::Checkout::PostalArea.new('GB', 'S6*')
68
+ rule.shipping_taxed=true
69
+ rule.rate=0.03
70
+ end
71
+ table.create_rule do |rule|
72
+ rule.area=Google4R::Checkout::WorldArea.new
73
+ rule.shipping_taxed=true
74
+ rule.rate=0.10
75
+ end
76
+ tax_tables << table
77
+ nondefault_table = TaxTable.new(false)
78
+ nondefault_table.name = 'Special Table'
79
+ nondefault_table.create_rule do |rule|
80
+ rule.rate = 0.02
81
+ rule.area = UsCountryArea.new
82
+ rule.area.area = UsCountryArea::ALL
83
+ end
84
+ tax_tables << nondefault_table
85
+
86
+ TestTaxTableFactory.any_instance.stubs(:effective_tax_tables_at).returns(tax_tables)
87
+ @frontend.tax_table_factory = TestTaxTableFactory.new
88
+ @command = @frontend.create_checkout_command
89
+
90
+ @command.continue_shopping_url = 'http://wwww.example.com/continue_shopping'
91
+ @command.edit_cart_url = 'http://wwww.example.com/edit_cart'
92
+ @command.request_buyer_phone_number = false
93
+ @generator = CheckoutCommandXmlGenerator.new(@command)
94
+
95
+ @command.shopping_cart.expires_at = Time.parse('2007-11-29T15:33:20 UTC')
96
+
97
+ @command.create_shipping_method(PickupShipping) do |shipping|
98
+ shipping.name = 'Pickup Test Shipping'
99
+ shipping.price = Money.new(100, 'USD')
100
+ end
101
+
102
+ @command.create_shipping_method(FlatRateShipping) do |shipping|
103
+ shipping.name = 'State Test Shipping'
104
+ shipping.price = Money.new(100, 'USD')
105
+
106
+ shipping.create_allowed_area(UsStateArea) { |area| area.state = 'CA' }
107
+ shipping.create_excluded_area(UsStateArea) { |area| area.state = 'TX' }
108
+ end
109
+
110
+ @command.create_shipping_method(FlatRateShipping) do |shipping|
111
+ shipping.name = 'Country Area Test Shipping'
112
+ shipping.price = Money.new(100, 'USD')
113
+
114
+ shipping.create_allowed_area(UsCountryArea) { |area| area.area = UsCountryArea::FULL_50_STATES }
115
+ shipping.create_excluded_area(UsCountryArea) { |area| area.area = UsCountryArea::CONTINENTAL_48 }
116
+ end
117
+
118
+ @command.create_shipping_method(FlatRateShipping) do |shipping|
119
+ shipping.name = 'Zip Test Shipping'
120
+ shipping.price = Money.new(100, 'USD')
121
+
122
+ shipping.create_allowed_area(UsZipArea) { |area| area.pattern = '1*' }
123
+ shipping.create_excluded_area(UsZipArea) { |area| area.pattern = '12*' }
124
+ end
125
+
126
+ @command.shopping_cart.private_data = { 'we' => 'can pass in some data here'.split }
127
+
128
+ 1.upto(10) do |i|
129
+ @command.shopping_cart.create_item do |item|
130
+ item.name = "Item Name #{i}"
131
+ item.description = "Description #{i}"
132
+ item.unit_price = Money.new(i * 1000, 'USD')
133
+ item.quantity = i * 2
134
+ item.id = "Merchant ID #{i}"
135
+ if i == 1 then
136
+ item.private_data = { 'some' => { 'data' => 'Yeah, Yeah!' }, 'bars' => { 'bar' => [ 1, 2 ] } }
137
+ end
138
+
139
+ item.tax_table = nondefault_table if i % 2 == 1
140
+ end
141
+ end
142
+
143
+ xml_str = @generator.generate
144
+ assert_xml_validates_against_xml_schema(@schema_path, xml_str)
145
+ assert_string_equals_file_contents(@expected_path, xml_str)
146
+ assert_google_checkout_diagnose_returns_no_warnings(xml_str)
147
+ end
148
+
149
+ # Test that values within hashes are persisted correctly.
150
+ def test_process_hash_processes_hash_values_correctly
151
+ element = REXML::Element.new('root')
152
+ @generator.instance_eval { process_hash(element, { 'key' => 'value' }) }
153
+ assert_equal "<root><key>value</key></root>", element.to_s
154
+ end
155
+
156
+ protected
157
+
158
+ def assert_google_checkout_diagnose_returns_no_warnings(xml_str)
159
+ tmpfile = Tempfile.new('xml_output')
160
+ tmpfile << xml_str
161
+ tmpfile.flush
162
+
163
+ url = "https://%s:%s@sandbox.google.com/checkout/cws/v2/Merchant/%s/request/diagnose" %
164
+ [ FRONTEND_CONFIGURATION[:merchant_id], FRONTEND_CONFIGURATION[:merchant_key],
165
+ FRONTEND_CONFIGURATION[:merchant_id] ]
166
+
167
+ stdin, stdout, stderr = Open3.popen3("curl", "-d", "@#{tmpfile.path}", url)
168
+ outstr = stdout.read
169
+ errstr = stderr.read
170
+
171
+ assert (outstr != ''), 'curl command not available'
172
+
173
+ # Check that there is no <warnings> tag in the XML.
174
+ xml_document = REXML::Document.new(outstr)
175
+ assert 0, xml_document.root.elements.to_a('//warnings').size
176
+
177
+ tmpfile.close!
178
+ end
179
+
180
+ def assert_xml_validates_against_xml_schema(schema_path, xml_str)
181
+ tmpfile = Tempfile.new('xml_output')
182
+ tmpfile << xml_str
183
+ tmpfile.flush
184
+
185
+ #puts "---\n#{xml_str}\n---"
186
+
187
+ stdin, stdout, stderr = Open3.popen3("xmllint", "--schema", schema_path, tmpfile.path)
188
+ outstr = stdout.read
189
+ errstr = stderr.read
190
+ if errstr !~ /validates$/ then
191
+ assert false, "The document did not validate: ---\nOUT:#{outstr}\nERR:#{errstr}\n---"
192
+ else
193
+ assert true
194
+ end
195
+
196
+ tmpfile.close!
197
+ end
198
+
199
+ def assert_string_equals_file_contents(expected_path, xml_str)
200
+ file_contents = File.open(expected_path, 'r') { |f| f.read }
201
+ assert_strings_equal file_contents, xml_str
202
+ end
203
+ end
@@ -0,0 +1,115 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/command_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
+ require 'net/http'
35
+
36
+ require 'base64'
37
+
38
+ class TestCommand < Google4R::Checkout::Command
39
+ XML_REPRESENTATION = "<?xml version='1.0' ?><root />"
40
+
41
+ def to_xml
42
+ XML_REPRESENTATION
43
+ end
44
+ end
45
+
46
+ # Test for the class Command.
47
+ class Google4R::Checkout::CommandTest < Test::Unit::TestCase
48
+ include Google4R::Checkout
49
+
50
+ def setup
51
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
52
+ @frontend.tax_table_factory = TestTaxTableFactory.new
53
+ @command = TestCommand.new(@frontend)
54
+ end
55
+
56
+ def test_sending_fails_if_certificate_validation_fails
57
+ OpenSSL::SSL::SSLSocket.any_instance.stubs(:connect).raises(OpenSSL::SSL::SSLError, 'certificate verify failed')
58
+
59
+ assert_raises(OpenSSL::SSL::SSLError) { @command.send_to_google_checkout }
60
+ end
61
+
62
+ def test_to_xml_raises_not_implemented_error
63
+ assert_raises(NotImplementedError) { Command.new(Frontend.new(FRONTEND_CONFIGURATION)).to_xml }
64
+ end
65
+
66
+ def test_unknown_xml_response_in_body_raises_runtime_error
67
+ mock_body = '<?xml version="1.0" ?><unexpected-tag />'
68
+
69
+ success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
70
+ success_response.expects(:body).returns(mock_body)
71
+
72
+ Net::HTTP.any_instance.stubs(:request).returns(success_response)
73
+
74
+ assert_raises(RuntimeError) { @command.send_to_google_checkout }
75
+ end
76
+
77
+ def test_invalid_response_code_raises_runtime_error
78
+ unknown_response = mock()
79
+ unknown_response.expects(:code)
80
+ unknown_response.expects(:message)
81
+
82
+ Net::HTTP.any_instance.stubs(:request).returns(unknown_response)
83
+
84
+ assert_raises(RuntimeError) { @command.send_to_google_checkout }
85
+ end
86
+
87
+ def test_error_tag_in_response_code_raises_google_checkout_error
88
+ mock_body = '<?xml version="1.0" encoding="UTF-8"?><error xmlns="http://checkout.google.com/schema/2" serial-number="foo-bar"><error-message>Malformed URL component: expected id: (\d{10})|(\d{15}), but got something-different</error-message></error>'
89
+
90
+ error_response = Net::HTTPClientError.new(Net::HTTP.version_1_2, 400, "Bad Request")
91
+ error_response.expects(:body).returns(mock_body)
92
+
93
+ Net::HTTP.any_instance.stubs(:request).returns(error_response)
94
+
95
+ assert_raises(GoogleCheckoutError) { @command.send_to_google_checkout }
96
+ end
97
+
98
+ def test_send_to_google_checkout_works_correctly_if_200_is_returned
99
+ mock_body = '<?xml version="1.0" encoding="UTF-8"?><checkout-redirect xmlns="http://checkout.google.com/schema/2" serial-number="foo-bar"><redirect-url>https://sandbox.google.com/checkout/view/buy?o=shoppingcart&amp;shoppingcart=foo-bar</redirect-url></checkout-redirect>'
100
+
101
+ success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
102
+ success_response.expects(:body).returns(mock_body)
103
+
104
+ Net::HTTP.any_instance.stubs(:request).returns(success_response)
105
+
106
+ Net::HTTP::Post.any_instance.expects(:basic_auth).with(FRONTEND_CONFIGURATION[:merchant_id],
107
+ FRONTEND_CONFIGURATION[:merchant_key])
108
+
109
+ result = @command.send_to_google_checkout
110
+
111
+ assert_kind_of CheckoutRedirectResponse, result
112
+ assert_equal 'foo-bar', result.serial_number
113
+ assert_equal 'https://sandbox.google.com/checkout/view/buy?o=shoppingcart&shoppingcart=foo-bar', result.redirect_url
114
+ end
115
+ end