google4r-checkout 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,83 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/backorder_items_command_test.rb
4
+ # Author: Tony Chan <api.htchan at gmail dot com>
5
+ # Copyright: (c) 2007 by Dan Dukeson
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 BackorderItemsCommand class.
35
+ class Google4R::Checkout::BackorderItemsCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_backorder_items_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.send_email = true
44
+ @item_info1 = ItemInfo.new('A1')
45
+ @item_info2 = ItemInfo.new('B2')
46
+ @command.item_info_arr = [@item_info1, @item_info2]
47
+
48
+
49
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
50
+ <backorder-items xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
51
+ <item-ids>
52
+ <item-id>
53
+ <merchant-item-id>A1</merchant-item-id>
54
+ </item-id>
55
+ <item-id>
56
+ <merchant-item-id>B2</merchant-item-id>
57
+ </item-id>
58
+ </item-ids>
59
+ <send-email>true</send-email>
60
+ </backorder-items>}
61
+ end
62
+
63
+ def test_behaves_correctly
64
+ [ :google_order_number, :item_info_arr, :send_email,
65
+ :google_order_number=, :item_info_arr=, :send_email= ].each do |symbol|
66
+ assert_respond_to @command, symbol
67
+ end
68
+ end
69
+
70
+ def test_xml_send_email
71
+ assert_strings_equal(@sample_xml, @command.to_xml)
72
+ end
73
+
74
+ def test_accessors
75
+ assert_equal('841171949013218', @command.google_order_number)
76
+ assert @command.send_email
77
+ end
78
+
79
+ def test_to_xml_does_not_raise_exception
80
+ assert_nothing_raised { @command.to_xml }
81
+ end
82
+
83
+ end
@@ -0,0 +1,89 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/cancel_items_command_test.rb
4
+ # Author: Tony Chan <api.htchan at gmail dot com>
5
+ # Copyright: (c) 2007 by Dan Dukeson
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 CancelItemsCommand class.
35
+ class Google4R::Checkout::CancelItemsCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_cancel_items_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.send_email = true
44
+ @item_info1 = ItemInfo.new('A1')
45
+ @item_info2 = ItemInfo.new('B2')
46
+ @command.item_info_arr = [@item_info1, @item_info2]
47
+ @command.reason = 'This item is no longer manufactured.'
48
+ @command.comment = 'Suggested replacement is model XBR2700.'
49
+
50
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
51
+ <cancel-items xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
52
+ <item-ids>
53
+ <item-id>
54
+ <merchant-item-id>A1</merchant-item-id>
55
+ </item-id>
56
+ <item-id>
57
+ <merchant-item-id>B2</merchant-item-id>
58
+ </item-id>
59
+ </item-ids>
60
+ <send-email>true</send-email>
61
+ <reason>This item is no longer manufactured.</reason>
62
+ <comment>Suggested replacement is model XBR2700.</comment>
63
+ </cancel-items>}
64
+ end
65
+
66
+ def test_behaves_correctly
67
+ [ :google_order_number, :item_info_arr, :send_email,
68
+ :google_order_number=, :item_info_arr=, :send_email=,
69
+ :reason, :reason=, :comment, :comment=].each do |symbol|
70
+ assert_respond_to @command, symbol
71
+ end
72
+ end
73
+
74
+ def test_xml_send_email
75
+ assert_strings_equal(@sample_xml, @command.to_xml)
76
+ end
77
+
78
+ def test_accessors
79
+ assert_equal('841171949013218', @command.google_order_number)
80
+ assert @command.send_email
81
+ assert_equal('This item is no longer manufactured.', @command.reason)
82
+ assert_equal('Suggested replacement is model XBR2700.', @command.comment)
83
+ end
84
+
85
+ def test_to_xml_does_not_raise_exception
86
+ assert_nothing_raised { @command.to_xml }
87
+ end
88
+
89
+ end
@@ -0,0 +1,57 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/carrier_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::CarrierCalculatedShippingTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @shipping = CarrierCalculatedShipping.new
40
+ end
41
+
42
+ def test_carrier_calculated_shipping_method_behaves_correctly
43
+ [ :carrier_calculated_shipping_options, :shipping_packages,
44
+ :create_carrier_calculated_shipping_option,
45
+ :create_shipping_package,
46
+ :create_from_element
47
+ ].each do |symbol|
48
+ assert_respond_to @shipping, symbol
49
+ end
50
+ end
51
+
52
+ def test_initialization
53
+ assert_equal [], @shipping.carrier_calculated_shipping_options
54
+ assert_equal [], @shipping.shipping_packages
55
+ end
56
+
57
+ end
@@ -82,6 +82,11 @@ class Google4R::Checkout::CheckoutCommandTest < Test::Unit::TestCase
82
82
 
83
83
  @command.request_buyer_phone_number = true
84
84
  assert_equal true, @command.request_buyer_phone_number
85
+
86
+ assert_nil @command.analytics_data
87
+ @command.analytics_data = 'abcd1234defgh5678ijklmn'
88
+ assert_equal 'abcd1234defgh5678ijklmn', @command.analytics_data
89
+
85
90
  end
86
91
 
87
92
  def test_create_shipping_method_works_correctly_with_block
@@ -117,4 +122,4 @@ class Google4R::Checkout::CheckoutCommandTest < Test::Unit::TestCase
117
122
  def test_to_xml_does_not_raise_exception
118
123
  assert_nothing_raised { @command.to_xml }
119
124
  end
120
- end
125
+ end
@@ -102,6 +102,7 @@ class Google4R::Checkout::CheckoutCommandXmlGeneratorTest < Test::Unit::TestCase
102
102
  @command.accept_merchant_coupons = true
103
103
  @command.accept_gift_certificates = true
104
104
  @command.platform_id = '1234567890'
105
+ @command.analytics_data = 'abcd1234defgh5678ijklmn'
105
106
 
106
107
  @generator = CheckoutCommandXmlGenerator.new(@command)
107
108
 
@@ -59,8 +59,9 @@ class Google4R::Checkout::CommandTest < Test::Unit::TestCase
59
59
  assert_raises(OpenSSL::SSL::SSLError) { @command.send_to_google_checkout }
60
60
  end
61
61
 
62
- def test_to_xml_raises_not_implemented_error
63
- assert_raises(NotImplementedError) { Command.new(Frontend.new(FRONTEND_CONFIGURATION)).to_xml }
62
+ def test_instantiate_abstract_class
63
+ assert_raises(RuntimeError) { Command.new(Frontend.new(FRONTEND_CONFIGURATION)) }
64
+ assert_raises(RuntimeError) { ItemsCommand.new(Frontend.new(FRONTEND_CONFIGURATION)) }
64
65
  end
65
66
 
66
67
  def test_unknown_xml_response_in_body_raises_runtime_error
@@ -0,0 +1,105 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/digital_content_test.rb
4
+ # Author: Tony Chan <api.htchan at gmail dot com>
5
+ # Copyright: (c) 2007 by Dan Dukeson
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 ShipItemsCommand class.
35
+ class Google4R::Checkout::DigitalContentTest < 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
+ @email_delivery_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
43
+ <digital-content>
44
+ <display-disposition>OPTIMISTIC</display-disposition>
45
+ <email-delivery>true</email-delivery>
46
+ </digital-content>}
47
+
48
+ @key_url_delivery_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
49
+ <digital-content>
50
+ <display-disposition>PESSIMISTIC</display-disposition>
51
+ <description>
52
+ Please go to &amp;lt;a href=&quot;http://supersoft.example.com&quot;&amp;gt;our website&amp;lt;/a&amp;gt;,
53
+ and enter your access key so that you can download our software.
54
+ </description>
55
+ <key>1456-1514-3657-2198</key>
56
+ <url>http://supersoft.example.com</url>
57
+ </digital-content>}
58
+
59
+ @description_delivery_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
60
+ <digital-content>
61
+ <display-disposition>OPTIMISTIC</display-disposition>
62
+ <description>
63
+ It may take up to 24 hours to process your new storage. You will
64
+ be able to see your increased storage on your
65
+ &amp;lt;a href=&quot;http://login.example.com&quot;&amp;gt;account page&amp;lt;/a&amp;gt;.
66
+ </description>
67
+ </digital-content>}
68
+
69
+
70
+ @optional_tags = [ 'merchant-item-id', 'merchant-private-item-data', 'tax-table-selector' ]
71
+
72
+ @command = @frontend.create_checkout_command
73
+ @shopping_cart = @command.shopping_cart
74
+ @item = @shopping_cart.create_item
75
+ @item.create_digital_content
76
+ end
77
+
78
+ def test_behaves_correctly
79
+ [ :description, :description=, :display_disposition,
80
+ :display_disposition=, :email_delivery,
81
+ :email_delivery=, :key, :key=, :url, :url= ].each do |symbol|
82
+ assert_respond_to @item.digital_content, symbol
83
+ end
84
+ end
85
+
86
+ def test_create_from_element_works
87
+ digital_content = Item::DigitalContent.create_from_element(REXML::Document.new(@email_delivery_str).root)
88
+ assert_equal 'OPTIMISTIC', digital_content.display_disposition
89
+ assert_equal "true", digital_content.email_delivery
90
+
91
+ digital_content = Item::DigitalContent.create_from_element(REXML::Document.new(@key_url_delivery_str).root)
92
+ assert_equal 'PESSIMISTIC', digital_content.display_disposition
93
+ assert_nil digital_content.email_delivery
94
+ assert_equal '1456-1514-3657-2198', digital_content.key
95
+ assert_equal 'http://supersoft.example.com', digital_content.url
96
+
97
+ digital_content = Item::DigitalContent.create_from_element(REXML::Document.new(@description_delivery_str).root)
98
+ assert_equal 'OPTIMISTIC', digital_content.display_disposition
99
+ assert_nospace_equal %q{It may take up to 24 hours to process your new
100
+ storage. You will be able to see your increased storage on your &amp;lt;a
101
+ href=&quot;http://login.example.com&quot;&amp;gt;account page&amp;lt;/a&amp;gt;.},
102
+ REXML::Text.new(digital_content.description).to_s
103
+ end
104
+
105
+ end
@@ -46,31 +46,91 @@ class Google4R::Checkout::FrontendTest < Test::Unit::TestCase
46
46
  end
47
47
 
48
48
  def test_frontend_behaves_correctly
49
- [ :create_checkout_command, :configuration, :tax_table_factory,
50
- :tax_table_factory=
49
+ [ :configuration, :tax_table_factory, :tax_table_factory=,
50
+ :create_notification_handler, :create_callback_handler,
51
+ :create_deliver_order_command, :create_charge_order_command,
52
+ :create_checkout_command, :create_cancel_order_command,
53
+ :create_refund_order_command, :create_send_buyer_message_command,
54
+ :create_authorize_order_command, :create_add_merchant_order_number_command,
55
+ :create_add_tracking_data_command, :create_archive_order_command,
56
+ :create_unarchive_order_command, :create_ship_items_command,
57
+ :create_backorder_items_command, :create_return_items_command,
58
+ :create_cancel_items_command, :create_reset_items_shipping_information_command
51
59
  ].each do |symbol|
52
60
  assert_respond_to @frontend, symbol
53
61
  end
54
62
  end
55
63
 
56
- def test_create_checkout_command_works_correctly
57
- assert_kind_of CheckoutCommand, @frontend.create_checkout_command
58
- end
59
-
60
64
  def test_create_notification_handler_works_correctly
61
65
  assert_kind_of NotificationHandler, @frontend.create_notification_handler
62
66
  end
67
+
68
+ def test_create_callback_handler_works_correctly
69
+ assert_kind_of CallbackHandler, @frontend.create_callback_handler
70
+ end
63
71
 
72
+ def test_create_deliver_order_command_works_correctly
73
+ assert_kind_of DeliverOrderCommand, @frontend.create_deliver_order_command
74
+ end
75
+
64
76
  def test_create_charge_order_command_works_correctly
65
77
  assert_kind_of ChargeOrderCommand, @frontend.create_charge_order_command
66
78
  end
67
-
68
- def test_create_deliver_order_command_works
69
- assert_kind_of DeliverOrderCommand, @frontend.create_deliver_order_command
79
+
80
+ def test_create_checkout_command_works_correctly
81
+ assert_kind_of CheckoutCommand, @frontend.create_checkout_command
70
82
  end
71
83
 
72
- def test_create_cancel_order_command_works
84
+ def test_create_cancel_order_command_works_correctly
73
85
  assert_kind_of CancelOrderCommand, @frontend.create_cancel_order_command
74
86
  end
87
+
88
+ def test_create_refund_order_command_works_correctly
89
+ assert_kind_of RefundOrderCommand, @frontend.create_refund_order_command
90
+ end
91
+
92
+ def test_create_send_buyer_message_command_works_correctly
93
+ assert_kind_of SendBuyerMessageCommand, @frontend.create_send_buyer_message_command
94
+ end
95
+
96
+ def test_create_authorize_order_command_works_correctly
97
+ assert_kind_of AuthorizeOrderCommand, @frontend.create_authorize_order_command
98
+ end
99
+
100
+ def test_create_add_merchant_order_number_command_works_correctly
101
+ assert_kind_of AddMerchantOrderNumberCommand, @frontend.create_add_merchant_order_number_command
102
+ end
103
+
104
+ def test_create_add_tracking_data_command_works_correctly
105
+ assert_kind_of AddTrackingDataCommand, @frontend.create_add_tracking_data_command
106
+ end
107
+
108
+ def test_create_archive_order_command_works_correctly
109
+ assert_kind_of ArchiveOrderCommand, @frontend.create_archive_order_command
110
+ end
111
+
112
+ def test_create_unarchive_order_command_works_correctly
113
+ assert_kind_of UnarchiveOrderCommand, @frontend.create_unarchive_order_command
114
+ end
115
+
116
+ def test_create_ship_items_command_works_correctly
117
+ assert_kind_of ShipItemsCommand, @frontend.create_ship_items_command
118
+ end
119
+
120
+ def test_create_backorder_items_command_works_correctly
121
+ assert_kind_of BackorderItemsCommand, @frontend.create_backorder_items_command
122
+ end
123
+
124
+ def test_create_return_items_command_works_correctly
125
+ assert_kind_of ReturnItemsCommand, @frontend.create_return_items_command
126
+ end
127
+
128
+ def test_create_cancel_items_command_works_correctly
129
+ assert_kind_of CancelItemsCommand, @frontend.create_cancel_items_command
130
+ end
131
+
132
+ def test_create_reset_items_shipping_information_command_works_correctly
133
+ assert_kind_of ResetItemsShippingInformationCommand, @frontend.create_reset_items_shipping_information_command
134
+ end
75
135
 
76
136
  end