google4r-checkout 1.0.1 → 1.0.2

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,75 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/anonymous_address_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 Address.
35
+ class Google4R::Checkout::AnonymousAddressTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+
40
+ @xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
41
+ <anonymous-address id="739030698069958">
42
+ <country-code>US</country-code>
43
+ <city>Mountain View</city>
44
+ <region>CA</region>
45
+ <postal-code>94043</postal-code>
46
+ </anonymous-address>}
47
+
48
+ end
49
+
50
+ def test_responds_correctly
51
+ address = Address.new
52
+
53
+ [ :address_id, :address_id=,
54
+ :country_code, :country_code=,
55
+ :city, :city=, :region, :region=,
56
+ :postal_code, :postal_code=
57
+ ].each do |symbol|
58
+ assert_respond_to address, symbol
59
+ end
60
+ end
61
+
62
+ def test_creating_anonymous_address
63
+
64
+ document = REXML::Document.new(@xml_str)
65
+
66
+ anonymous_address = AnonymousAddress.create_from_element(document.elements['/anonymous-address'])
67
+
68
+ assert_equal '739030698069958', anonymous_address.address_id
69
+ assert_equal 'US', anonymous_address.country_code
70
+ assert_equal 'Mountain View', anonymous_address.city
71
+ assert_equal 'CA', anonymous_address.region
72
+ assert_equal '94043', anonymous_address.postal_code
73
+
74
+ end
75
+ end
@@ -0,0 +1,83 @@
1
+ #--
2
+ # Project: google4r
3
+ # File: test/unit/callback_handler_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 CallbackHandler.
35
+ class Google4R::Checkout::CallbackHandlerTest < 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
+ @callback_handler = @frontend.create_callback_handler
42
+
43
+ @xmls_with_known_tags =
44
+ [
45
+ [
46
+ '<merchant-calculation-callback xmlns="http://checkout.google.com/schema/2" />',
47
+ 'merchant-calculation-callback',
48
+ MerchantCalculationCallback
49
+ ]
50
+ ]
51
+
52
+ @xmls_with_unknown_tags =
53
+ [
54
+ '<unknown-callback/>'
55
+ ]
56
+ end
57
+
58
+ def test_handler_gets_initialized_correctly
59
+ assert_equal @frontend, @callback_handler.frontend
60
+ end
61
+
62
+ def test_returns_correct_callback_class_for_known_callback
63
+ @xmls_with_known_tags.each do |triple|
64
+ xml_str, tag_name, klass = triple
65
+
66
+ expect = klass.stubs(:create_from_element)
67
+ expect.times(1).returns(:foo)
68
+ expect.with { |element, frontend| element.name == tag_name and frontend == @frontend }
69
+
70
+ result = nil
71
+ assert_nothing_raised {
72
+ result = @callback_handler.handle(xml_str)
73
+ }
74
+ assert_equal :foo, result
75
+ end
76
+ end
77
+
78
+ def test_raises_exception_on_unknown_callback
79
+ @xmls_with_unknown_tags.each do |xml_str|
80
+ assert_raises(UnknownCallbackType) { @callback_handler.handle(xml_str) }
81
+ end
82
+ end
83
+ end
@@ -63,7 +63,11 @@ class Google4R::Checkout::CheckoutCommandTest < Test::Unit::TestCase
63
63
  def test_command_behaves_correctly
64
64
  [ :frontend, :shopping_cart, :tax_tables, :shipping_methods, :create_shipping_method,
65
65
  :edit_cart_url, :edit_cart_url=, :continue_shopping_url, :continue_shopping_url=,
66
- :request_buyer_phone_number, :request_buyer_phone_number=
66
+ :request_buyer_phone_number, :request_buyer_phone_number=,
67
+ :merchant_calculations_url, :merchant_calculations_url=,
68
+ :accept_merchant_coupons, :accept_merchant_coupons=,
69
+ :accept_gift_certificates, :accept_gift_certificates=,
70
+ :platform_id, :platform_id=
67
71
  ].each do |symbol|
68
72
  assert_respond_to @command, symbol
69
73
  end
@@ -81,7 +85,7 @@ class Google4R::Checkout::CheckoutCommandTest < Test::Unit::TestCase
81
85
  end
82
86
 
83
87
  def test_create_shipping_method_works_correctly_with_block
84
- [ PickupShipping, FlatRateShipping ].each do |clazz|
88
+ [ PickupShipping, FlatRateShipping, MerchantCalculatedShipping ].each do |clazz|
85
89
 
86
90
  shipping = nil
87
91
 
@@ -97,7 +101,7 @@ class Google4R::Checkout::CheckoutCommandTest < Test::Unit::TestCase
97
101
  end
98
102
 
99
103
  def test_create_shipping_method_works_correctly_without_block
100
- [ PickupShipping, FlatRateShipping ].each do |clazz|
104
+ [ PickupShipping, FlatRateShipping, MerchantCalculatedShipping ].each do |clazz|
101
105
  obj = @command.create_shipping_method(clazz)
102
106
 
103
107
  assert_kind_of clazz, obj
@@ -1,7 +1,8 @@
1
1
  #--
2
2
  # Project: google_checkout4r
3
3
  # File: test/unit/checkout_command_xml_generator_test.rb
4
- # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
4
+ # Authors: Manuel Holtgrewe <purestorm at ggnore dot net>
5
+ # Tony Chan <api.htchan at gmail dot com>
5
6
  # Copyright: (c) 2007 by Manuel Holtgrewe
6
7
  # License: MIT License as follows:
7
8
  #
@@ -97,6 +98,11 @@ class Google4R::Checkout::CheckoutCommandXmlGeneratorTest < Test::Unit::TestCase
97
98
  @command.continue_shopping_url = 'http://wwww.example.com/continue_shopping'
98
99
  @command.edit_cart_url = 'http://wwww.example.com/edit_cart'
99
100
  @command.request_buyer_phone_number = false
101
+ @command.merchant_calculations_url = 'http://www.example.com/merchant_calcuations'
102
+ @command.accept_merchant_coupons = true
103
+ @command.accept_gift_certificates = true
104
+ @command.platform_id = '1234567890'
105
+
100
106
  @generator = CheckoutCommandXmlGenerator.new(@command)
101
107
 
102
108
  @command.shopping_cart.expires_at = Time.parse('2007-11-29T15:33:20 UTC')
@@ -1,7 +1,8 @@
1
1
  #--
2
2
  # Project: google_checkout4r
3
3
  # File: test/unit/shipping_method_test.rb
4
- # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
4
+ # Authors: Manuel Holtgrewe <purestorm at ggnore dot net>
5
+ # Tony Chan <api.htchan at gmail dot com>
5
6
  # Copyright: (c) 2007 by Manuel Holtgrewe
6
7
  # License: MIT License as follows:
7
8
  #
@@ -32,10 +33,10 @@ require 'google4r/checkout'
32
33
  require 'test/frontend_configuration'
33
34
 
34
35
  # Test for the ShippingMethod class.
35
- class Google4R::Checkout::ShippingMethodTest < Test::Unit::TestCase
36
+ class Google4R::Checkout::DeliveryMethodTest < Test::Unit::TestCase
36
37
  include Google4R::Checkout
37
38
 
38
39
  def test_shipping_method_raises_runtime_error_on_initialisation
39
- assert_raises(RuntimeError) { ShippingMethod.new }
40
+ assert_raises(RuntimeError) { DeliveryMethod.new }
40
41
  end
41
42
  end
@@ -1,7 +1,8 @@
1
1
  #--
2
2
  # Project: google_checkout4r
3
- # File: test/unit/area_test.rb
4
- # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
3
+ # File: test/unit/flat_rate_shipping_test.rb
4
+ # Authors: Manuel Holtgrewe <purestorm at ggnore dot net>
5
+ # Tony Chan <api.htchan at gmail dot com>
5
6
  # Copyright: (c) 2007 by Manuel Holtgrewe
6
7
  # License: MIT License as follows:
7
8
  #
@@ -41,7 +42,8 @@ class Google4R::Checkout::FlatRateShippingMethodTest < Test::Unit::TestCase
41
42
 
42
43
  def test_flat_rate_shipping_method_behaves_correctly
43
44
  [ :name, :name=, :price, :price=,
44
- :allowed_areas, :create_allowed_area, :excluded_areas, :create_excluded_area
45
+ :shipping_restrictions_allowed_areas, :shipping_restrictions_excluded_areas,
46
+ :create_allowed_area, :create_excluded_area, :create_area
45
47
  ].each do |symbol|
46
48
  assert_respond_to @shipping, symbol
47
49
  end
@@ -50,8 +52,8 @@ class Google4R::Checkout::FlatRateShippingMethodTest < Test::Unit::TestCase
50
52
  def test_initialization
51
53
  assert_nil @shipping.name
52
54
  assert_nil @shipping.price
53
- assert_equal [], @shipping.allowed_areas
54
- assert_equal [], @shipping.excluded_areas
55
+ assert_equal [], @shipping.shipping_restrictions_allowed_areas
56
+ assert_equal [], @shipping.shipping_restrictions_excluded_areas
55
57
  end
56
58
 
57
59
  def test_flat_rate_shipping_method_setting_attributes_works_correctly
@@ -72,8 +74,9 @@ class Google4R::Checkout::FlatRateShippingMethodTest < Test::Unit::TestCase
72
74
  assert_raises(RuntimeError) { @shipping.price = "str" }
73
75
  end
74
76
 
75
- def test_create_create_allowed_excluded_areas_works_with_block
76
- [ [ :allowed_areas, :create_allowed_area], [ :excluded_areas, :create_excluded_area ] ].each do |pair|
77
+ def test_create_allowed_excluded_areas_works_with_block
78
+ [ [ :shipping_restrictions_allowed_areas, :create_allowed_area],
79
+ [ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
77
80
  read_sym, create_sym = pair
78
81
 
79
82
  [ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
@@ -92,8 +95,9 @@ class Google4R::Checkout::FlatRateShippingMethodTest < Test::Unit::TestCase
92
95
  end
93
96
  end
94
97
 
95
- def test_create_create_allowed_excluded_areas_works_without_block
96
- [ [ :allowed_areas, :create_allowed_area], [ :excluded_areas, :create_excluded_area ] ].each do |pair|
98
+ def test_create_allowed_excluded_areas_works_without_block
99
+ [ [ :shipping_restrictions_allowed_areas, :create_allowed_area],
100
+ [ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
97
101
  read_sym, create_sym = pair
98
102
 
99
103
  [ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
@@ -106,9 +110,23 @@ class Google4R::Checkout::FlatRateShippingMethodTest < Test::Unit::TestCase
106
110
  end
107
111
  end
108
112
 
109
- def test_create_create_allowed_excluded_areas_validates_parameter
113
+ def test_create_allowed_excluded_areas_validates_parameter
110
114
  [ :create_allowed_area, :create_excluded_area ].each do |sym|
111
115
  assert_raises(RuntimeError) { @shipping.send(sym, String) }
112
116
  end
113
117
  end
118
+
119
+ def test_new_create_area_with_flat_rate_shipping
120
+ [ [ :shipping_restrictions, :allowed_areas ],
121
+ [ :shipping_restrictions, :excluded_areas ] ].each do |pair|
122
+ type_sym, area_sym = pair
123
+ [ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
124
+ area = @shipping.send(:create_area, type_sym, area_sym, clazz)
125
+
126
+ assert_kind_of clazz, area
127
+
128
+ assert @shipping.send((type_sym.to_s + '_' + area_sym.to_s).to_sym).include?(area)
129
+ end
130
+ end
131
+ end
114
132
  end
@@ -0,0 +1,136 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/merchant_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::MerchantCalculatedShippingTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @shipping = MerchantCalculatedShipping.new
40
+ end
41
+
42
+ def test_flat_rate_shipping_method_behaves_correctly
43
+ [ :name, :name=, :price, :price=,
44
+ :shipping_restrictions_allowed_areas, :shipping_restrictions_excluded_areas,
45
+ :address_filters_allowed_areas, :address_filters_excluded_areas,
46
+ :create_allowed_area, :create_excluded_area, :create_area
47
+ ].each do |symbol|
48
+ assert_respond_to @shipping, symbol
49
+ end
50
+ end
51
+
52
+ def test_initialization
53
+ assert_nil @shipping.name
54
+ assert_nil @shipping.price
55
+ assert_equal [], @shipping.shipping_restrictions_allowed_areas
56
+ assert_equal [], @shipping.shipping_restrictions_excluded_areas
57
+ assert_equal [], @shipping.address_filters_allowed_areas
58
+ assert_equal [], @shipping.address_filters_excluded_areas
59
+ end
60
+
61
+ def test_merchant_calculated_shipping_setting_attributes_works_correctly
62
+ @shipping.name = "Shipping Method Name"
63
+ assert_equal "Shipping Method Name", @shipping.name
64
+
65
+ @shipping.price = Money.new(100, "EUR")
66
+ assert_kind_of Money, @shipping.price
67
+ assert_equal 100, @shipping.price.cents
68
+ assert_equal "EUR", @shipping.price.currency
69
+ end
70
+
71
+ def test_merchant_calculated_shipping_price_is_validated
72
+ # Test that FlatRateShippingMethod checks for its price attribute responding
73
+ # to cents and currency.
74
+ assert_raises(RuntimeError) { @shipping.price = nil }
75
+ assert_raises(RuntimeError) { @shipping.price = 10 }
76
+ assert_raises(RuntimeError) { @shipping.price = "str" }
77
+ end
78
+
79
+ def test_create_allowed_excluded_areas_works_with_block
80
+ [ [ :shipping_restrictions_allowed_areas, :create_allowed_area ],
81
+ [ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
82
+ read_sym, create_sym = pair
83
+
84
+ [ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
85
+
86
+ the_area = nil
87
+
88
+ res =
89
+ @shipping.send(create_sym, clazz) do |area|
90
+ the_area = area
91
+ assert_kind_of clazz, area
92
+ end
93
+
94
+ assert_equal res, the_area
95
+ assert @shipping.send(read_sym).include?(the_area)
96
+ end
97
+ end
98
+ end
99
+
100
+ def test_create_allowed_excluded_areas_works_without_block
101
+ [ [ :shipping_restrictions_allowed_areas, :create_allowed_area],
102
+ [ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
103
+ read_sym, create_sym = pair
104
+
105
+ [ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
106
+ area = @shipping.send(create_sym, clazz)
107
+
108
+ assert_kind_of clazz, area
109
+
110
+ assert @shipping.send(read_sym).include?(area)
111
+ end
112
+ end
113
+ end
114
+
115
+ def test_create_allowed_excluded_areas_validates_parameter
116
+ [ :create_allowed_area, :create_excluded_area ].each do |sym|
117
+ assert_raises(RuntimeError) { @shipping.send(sym, String) }
118
+ end
119
+ end
120
+
121
+ def test_new_create_area_with_flat_rate_shipping
122
+ [ [ :shipping_restrictions, :allowed_areas ],
123
+ [ :shipping_restrictions, :excluded_areas ],
124
+ [ :address_filters, :allowed_areas ],
125
+ [ :address_filters, :excluded_areas ] ].each do |pair|
126
+ type_sym, area_sym = pair
127
+ [ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
128
+ area = @shipping.send(:create_area, type_sym, area_sym, clazz)
129
+
130
+ assert_kind_of clazz, area
131
+
132
+ assert @shipping.send((type_sym.to_s + '_' + area_sym.to_s).to_sym).include?(area)
133
+ end
134
+ end
135
+ end
136
+ end