google4r-checkout 1.0.2 → 1.0.3

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.
@@ -0,0 +1,69 @@
1
+ require 'google4r/checkout'
2
+
3
+ require 'test/frontend_configuration'
4
+ #--
5
+ # Project: google_checkout4r
6
+ # File: test/unit/item_info_test.rb
7
+ # Author: Tony Chan <api.htchan at gmail dot com>
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 ItemInfo.
38
+ class Google4R::Checkout::ItemInfoTest < Test::Unit::TestCase
39
+ include Google4R::Checkout
40
+
41
+ def setup
42
+ @item_info = ItemInfo.new('A1')
43
+ @item_info.create_tracking_data('UPS', '55555555')
44
+ @item_info.create_tracking_data('FedEx', '12345678')
45
+ end
46
+
47
+ def test_initialization_works
48
+ assert_kind_of ItemInfo, @item_info
49
+ end
50
+
51
+ def test_responds_correctly
52
+ [ :merchant_item_id, :tracking_data_arr].each do |sym|
53
+ assert_respond_to @item_info, sym
54
+ end
55
+ end
56
+
57
+ def test_merchant_item_id
58
+ assert_equal('A1', @item_info.merchant_item_id)
59
+ end
60
+
61
+ def test_tracking_data_arr
62
+ tracking_data = @item_info.tracking_data_arr[0]
63
+ assert_equal('UPS', tracking_data.carrier)
64
+ assert_equal('55555555', tracking_data.tracking_number)
65
+ tracking_data = @item_info.tracking_data_arr[1]
66
+ assert_equal('FedEx', tracking_data.carrier)
67
+ assert_equal('12345678', tracking_data.tracking_number)
68
+ end
69
+ end
@@ -43,6 +43,7 @@ class Google4R::Checkout::ItemTest < Test::Unit::TestCase
43
43
  <item>
44
44
  <item-name>MegaSound 2GB MP3 Player</item-name>
45
45
  <item-description>Portable MP3 player - stores 500 songs</item-description>
46
+ <item-weight unit='LB' value='2.2'/>
46
47
  <unit-price currency="USD">178.00</unit-price>
47
48
  <quantity>1</quantity>
48
49
  <merchant-item-id>MGS2GBMP3</merchant-item-id>
@@ -54,6 +55,10 @@ class Google4R::Checkout::ItemTest < Test::Unit::TestCase
54
55
  </nested>
55
56
  </merchant-private-item-data>
56
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>
57
62
  </item>}
58
63
 
59
64
  @optional_tags = [ 'merchant-item-id', 'merchant-private-item-data', 'tax-table-selector' ]
@@ -61,12 +66,13 @@ class Google4R::Checkout::ItemTest < Test::Unit::TestCase
61
66
  @command = @frontend.create_checkout_command
62
67
  @shopping_cart = @command.shopping_cart
63
68
  @item = @shopping_cart.create_item
69
+ @digital_content = @item.digital_content
64
70
  end
65
71
 
66
72
  def test_item_behaves_correctly
67
73
  [ :shopping_cart, :name, :name=, :description, :description=, :unit_price, :unit_price=,
68
74
  :quantity, :quantity=, :id, :id=, :private_data, :private_data=,
69
- :tax_table, :tax_table=
75
+ :tax_table, :tax_table=, :digital_content, :weight, :weight=
70
76
  ].each do |symbol|
71
77
  assert_respond_to @item, symbol
72
78
  end
@@ -81,6 +87,7 @@ class Google4R::Checkout::ItemTest < Test::Unit::TestCase
81
87
  assert_nil @item.private_data
82
88
  assert_nil @item.id
83
89
  assert_nil @item.tax_table
90
+ assert_nil @item.digital_content
84
91
  end
85
92
 
86
93
  def test_item_setters_work
@@ -101,6 +108,9 @@ class Google4R::Checkout::ItemTest < Test::Unit::TestCase
101
108
 
102
109
  @item.private_data = Hash.new
103
110
  assert_equal Hash.new, @item.private_data
111
+
112
+ @item.weight = Weight.new(2.2)
113
+ assert_equal Weight, @item.weight.class
104
114
  end
105
115
 
106
116
  def test_set_tax_table_works
@@ -145,6 +155,8 @@ class Google4R::Checkout::ItemTest < Test::Unit::TestCase
145
155
  assert_equal Money.new(17800, 'USD'), item.unit_price
146
156
  assert_equal 1, item.quantity
147
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
148
160
 
149
161
  hash =
150
162
  {
@@ -39,7 +39,7 @@ class Google4R::Checkout::MerchantCalculatedShippingTest < Test::Unit::TestCase
39
39
  @shipping = MerchantCalculatedShipping.new
40
40
  end
41
41
 
42
- def test_flat_rate_shipping_method_behaves_correctly
42
+ def test_merchant_calculated_shipping_method_behaves_correctly
43
43
  [ :name, :name=, :price, :price=,
44
44
  :shipping_restrictions_allowed_areas, :shipping_restrictions_excluded_areas,
45
45
  :address_filters_allowed_areas, :address_filters_excluded_areas,
@@ -69,7 +69,7 @@ class Google4R::Checkout::MerchantCalculatedShippingTest < Test::Unit::TestCase
69
69
  end
70
70
 
71
71
  def test_merchant_calculated_shipping_price_is_validated
72
- # Test that FlatRateShippingMethod checks for its price attribute responding
72
+ # Test that MerchantCalculatedShipping checks for its price attribute responding
73
73
  # to cents and currency.
74
74
  assert_raises(RuntimeError) { @shipping.price = nil }
75
75
  assert_raises(RuntimeError) { @shipping.price = 10 }
@@ -111,6 +111,42 @@ class Google4R::Checkout::MerchantCalculatedShippingTest < Test::Unit::TestCase
111
111
  end
112
112
  end
113
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
114
150
 
115
151
  def test_create_allowed_excluded_areas_validates_parameter
116
152
  [ :create_allowed_area, :create_excluded_area ].each do |sym|
@@ -118,7 +154,7 @@ class Google4R::Checkout::MerchantCalculatedShippingTest < Test::Unit::TestCase
118
154
  end
119
155
  end
120
156
 
121
- def test_new_create_area_with_flat_rate_shipping
157
+ def test_new_create_area_with_merchant_calculated_shipping
122
158
  [ [ :shipping_restrictions, :allowed_areas ],
123
159
  [ :shipping_restrictions, :excluded_areas ],
124
160
  [ :address_filters, :allowed_areas ],
@@ -35,9 +35,33 @@ require 'test/frontend_configuration'
35
35
  class Google4R::Checkout::NotificationAcknowledgementTest < Test::Unit::TestCase
36
36
  include Google4R::Checkout
37
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
+ <chargeback-amount-notification xmlns="http://checkout.google.com/schema/2"
45
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
46
+ <google-order-number>841171949013218</google-order-number>
47
+ <latest-chargeback-amount currency="GBP">226.06</latest-chargeback-amount>
48
+ <total-chargeback-amount currency="GBP">226.06</total-chargeback-amount>
49
+ <timestamp>2006-03-18T20:25:31</timestamp>
50
+ </chargeback-amount-notification>
51
+ }
52
+ end
53
+
38
54
  def test_to_xml_works_as_expected
39
55
  ack = NotificationAcknowledgement.new
40
- str = %q{<?xml version="1.0" encoding="UTF-8"?><notification-acknowledgment xmlns="http://checkout.google.com/schema/2"/>}
56
+ str = %q{<?xml version='1.0' encoding='UTF-8'?><notification-acknowledgment xmlns='http://checkout.google.com/schema/2'/>}
57
+ assert_equal str, ack.to_xml
58
+ end
59
+
60
+ def test_to_xml_with_serial_number
61
+ root = REXML::Document.new(@example_xml).root
62
+ notification = ChargebackAmountNotification.create_from_element(root, @frontend)
63
+ ack = NotificationAcknowledgement.new(notification)
64
+ str = %q{<?xml version='1.0' encoding='UTF-8'?><notification-acknowledgment serial-number='bea6bc1b-e1e2-44fe-80ff-0180e33a2614' xmlns='http://checkout.google.com/schema/2'/>}
41
65
  assert_equal str, ack.to_xml
42
66
  end
43
67
  end
@@ -0,0 +1,83 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/reset_items_shipping_information_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 ResetItemsShippingInformationCommand class.
35
+ class Google4R::Checkout::ResetItemsShippingInformationCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_reset_items_shipping_information_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
+ <reset-items-shipping-information 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
+ </reset-items-shipping-information>}
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,83 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/return_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 ReturnItemsCommand class.
35
+ class Google4R::Checkout::ReturnItemsCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_return_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
+ <return-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
+ </return-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,101 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/ship_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 ShipItemsCommand class.
35
+ class Google4R::Checkout::ShipItemsCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_ship_items_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.send_email = true
44
+ @item_info_1 = ItemInfo.new('A1')
45
+ @item_info_1.create_tracking_data('UPS', 55555555)
46
+ @item_info_2 = ItemInfo.new('A2')
47
+ @item_info_2.create_tracking_data('FedEx', 12345678)
48
+ @command.item_info_arr = [@item_info_1, @item_info_2]
49
+
50
+
51
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
52
+ <ship-items xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
53
+ <item-shipping-information-list>
54
+ <item-shipping-information>
55
+ <item-id>
56
+ <merchant-item-id>A1</merchant-item-id>
57
+ </item-id>
58
+ <tracking-data-list>
59
+ <tracking-data>
60
+ <carrier>UPS</carrier>
61
+ <tracking-number>55555555</tracking-number>
62
+ </tracking-data>
63
+ </tracking-data-list>
64
+ </item-shipping-information>
65
+ <item-shipping-information>
66
+ <item-id>
67
+ <merchant-item-id>A2</merchant-item-id>
68
+ </item-id>
69
+ <tracking-data-list>
70
+ <tracking-data>
71
+ <carrier>FedEx</carrier>
72
+ <tracking-number>12345678</tracking-number>
73
+ </tracking-data>
74
+ </tracking-data-list>
75
+ </item-shipping-information>
76
+ </item-shipping-information-list>
77
+ <send-email>true</send-email>
78
+ </ship-items>}
79
+ end
80
+
81
+ def test_behaves_correctly
82
+ [ :google_order_number, :item_info_arr, :send_email,
83
+ :google_order_number=, :item_info_arr=, :send_email= ].each do |symbol|
84
+ assert_respond_to @command, symbol
85
+ end
86
+ end
87
+
88
+ def test_xml_send_email
89
+ assert_strings_equal(@sample_xml, @command.to_xml)
90
+ end
91
+
92
+ def test_accessors
93
+ assert_equal('841171949013218', @command.google_order_number)
94
+ assert @command.send_email
95
+ end
96
+
97
+ def test_to_xml_does_not_raise_exception
98
+ assert_nothing_raised { @command.to_xml }
99
+ end
100
+
101
+ end