google4r 0.0.1

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.
Files changed (39) hide show
  1. data/CHANGES +5 -0
  2. data/LICENSE +22 -0
  3. data/README +75 -0
  4. data/lib/google4r/checkout.rb +36 -0
  5. data/lib/google4r/checkout/commands.rb +267 -0
  6. data/lib/google4r/checkout/frontend.rb +100 -0
  7. data/lib/google4r/checkout/notifications.rb +533 -0
  8. data/lib/google4r/checkout/shared.rb +501 -0
  9. data/lib/google4r/checkout/xml_generation.rb +271 -0
  10. data/lib/google4r/maps.rb +174 -0
  11. data/test/checkout/integration/checkout_command_test.rb +103 -0
  12. data/test/checkout/unit/address_test.rb +131 -0
  13. data/test/checkout/unit/area_test.rb +41 -0
  14. data/test/checkout/unit/checkout_command_test.rb +112 -0
  15. data/test/checkout/unit/checkout_command_xml_generator_test.rb +187 -0
  16. data/test/checkout/unit/command_test.rb +126 -0
  17. data/test/checkout/unit/flat_rate_shipping_test.rb +114 -0
  18. data/test/checkout/unit/frontend_test.rb +63 -0
  19. data/test/checkout/unit/item_test.rb +159 -0
  20. data/test/checkout/unit/marketing_preferences_test.rb +65 -0
  21. data/test/checkout/unit/merchant_code_test.rb +122 -0
  22. data/test/checkout/unit/new_order_notification_test.rb +115 -0
  23. data/test/checkout/unit/notification_acknowledgement_test.rb +43 -0
  24. data/test/checkout/unit/notification_handler_test.rb +93 -0
  25. data/test/checkout/unit/order_adjustment_test.rb +95 -0
  26. data/test/checkout/unit/order_state_change_notification_test.rb +159 -0
  27. data/test/checkout/unit/pickup_shipping_test.rb +70 -0
  28. data/test/checkout/unit/private_data_parser_test.rb +68 -0
  29. data/test/checkout/unit/shipping_adjustment_test.rb +100 -0
  30. data/test/checkout/unit/shipping_method_test.rb +41 -0
  31. data/test/checkout/unit/shopping_cart_test.rb +146 -0
  32. data/test/checkout/unit/tax_rule_test.rb +65 -0
  33. data/test/checkout/unit/tax_table_test.rb +82 -0
  34. data/test/checkout/unit/us_country_area_test.rb +76 -0
  35. data/test/checkout/unit/us_state_area_test.rb +70 -0
  36. data/test/checkout/unit/us_zip_area_test.rb +66 -0
  37. data/test/maps/geocoder_test.rb +143 -0
  38. data/var/cacert.pem +7815 -0
  39. metadata +100 -0
@@ -0,0 +1,65 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/marketing_preferences_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 'test/checkout/frontend_configuration'
31
+
32
+ require 'google4r/checkout'
33
+
34
+ # Test for the class MarketingPreferences.
35
+ class Google4R::Checkout::MarketingPreferencesTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
40
+ <marketing-preferences>
41
+ <email-allowed>%s</email-allowed>
42
+ </marketing-preferences>
43
+ }
44
+ end
45
+
46
+ def test_responds_correctly
47
+ @preferences = MarketingPreferences.new
48
+
49
+ [ :email_allowed, :email_allowed= ].each do |symbol|
50
+ assert_respond_to @preferences, symbol
51
+ end
52
+ end
53
+
54
+ def test_create_from_element_works_correctly
55
+ { 'true' => true, 'True' => true, 'TRUE' => true, 'false' => false, 'Frue' => false,
56
+ 'FALSE' => false }.each do |str, bool|
57
+ xml_str = @xml_str % str
58
+
59
+ element = REXML::Document.new(xml_str).root
60
+ pref = MarketingPreferences.create_from_element(element)
61
+
62
+ assert_equal bool, pref.email_allowed
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,122 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/merchant_code_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 'test/checkout/frontend_configuration'
31
+
32
+ require 'google4r/checkout'
33
+
34
+ # Test for the class MerchantCode.
35
+ class Google4R::Checkout::MerchantCodeTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @valid_adjustment_types =
40
+ [
41
+ [ "GIFT_CERTIFICATE", 'gift-certificate-adjustment' ],
42
+ [ "COUPON", 'coupon-adjustment' ],
43
+ ]
44
+
45
+ @optional_tag_names = [ 'calculated-amount', 'message' ]
46
+
47
+ @invalid_adjustment_types = [ 'invalid-adjustment' ]
48
+
49
+ @xml_str = %q{<?xml version="1.0" encodig="UTF-8"?>
50
+ <%s>
51
+ <applied-amount currency="%s">%s</applied-amount>
52
+ <code>%s</code>
53
+ <calculated-amount currency="%s">%s</calculated-amount>
54
+ <message>%s</message>
55
+ </%s>}
56
+ end
57
+
58
+ def test_constants_are_defined
59
+ assert defined?(MerchantCode::GIFT_CERTIFICATE)
60
+ assert defined?(MerchantCode::COUPON)
61
+ end
62
+
63
+ def test_responds_correctly
64
+ adjustment = MerchantCode.new
65
+
66
+ [ :applied_amount, :applied_amount=, :code, :code=, :calculated_amount,
67
+ :calculated_amount=, :message, :message=,
68
+ ].each do |sym|
69
+ assert_respond_to adjustment, sym
70
+ end
71
+ end
72
+
73
+ def test_create_from_element_works_with_valid_adjustment_types
74
+ @valid_adjustment_types.each do |pair|
75
+ type, tag_name = pair
76
+
77
+ @optional_tag_names.power.each do |optional_tag_names|
78
+ xml_str = @xml_str %
79
+ [
80
+ tag_name, 'USD', '10.00', 'some-code', 'USD', '20.00', 'Message!', tag_name
81
+ ]
82
+
83
+ optional_tag_names.each { |name| xml_str = xml_str.gsub(%r{<#{name}.*?</#{name}>}, '') }
84
+
85
+ xml_doc = REXML::Document.new(xml_str)
86
+ xml_element = xml_doc.root.elements["/#{tag_name}"]
87
+
88
+ adjustment = MerchantCode.create_from_element(xml_element)
89
+
90
+ assert_equal Money.new(1000, 'USD'), adjustment.applied_amount
91
+ assert_equal type, adjustment.type
92
+ assert_equal 'some-code', adjustment.code
93
+
94
+ if not optional_tag_names.include?('calculated-amount') then
95
+ assert_equal Money.new(2000, 'USD'), adjustment.calculated_amount
96
+ else
97
+ assert_nil adjustment.calculated_amount
98
+ end
99
+ if not optional_tag_names.include?('message') then
100
+ assert_equal 'Message!', adjustment.message
101
+ else
102
+ assert_nil adjustment.message
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ def test_create_from_element_raises_exception_with_invalid_shipping_adjustment_types
109
+ @invalid_adjustment_types.each do |tag_name|
110
+ xml_str = @xml_str %
111
+ [
112
+ tag_name, 'USD', '10.00', 'some-code', 'USD', '20.00', 'Message!', tag_name
113
+ ]
114
+
115
+ xml_element = REXML::Document.new(xml_str).root
116
+
117
+ assert_raises(RuntimeError) do
118
+ adjustment = MerchantCode.create_from_element(xml_element)
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,115 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/new_order_confirmation_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 'test/checkout/frontend_configuration'
31
+
32
+ require 'google4r/checkout'
33
+
34
+ # Test for the class NewOrderConfirmation.
35
+ class Google4R::Checkout::NewOrderNotificationTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
40
+ <new-order-notification xmlns="http://checkout.google.com/schema/2" serial-number="8571632143">
41
+ <google-order-number>6014423719</google-order-number>
42
+ <buyer-billing-address />
43
+ <buyer-id>294873009217523</buyer-id>
44
+ <buyer-marketing-preferences />
45
+ <buyer-shipping-address />
46
+ <financial-order-state>REVIEWING</financial-order-state>
47
+ <fulfillment-order-state>NEW</fulfillment-order-state>
48
+ <google-order-number>6014423719</google-order-number>
49
+ <order-adjustment />
50
+ <order-total currency="USD">321.98</order-total>
51
+ <shopping-cart />
52
+ <timestamp>2006-03-18T17:32:11</timestamp>
53
+ </new-order-notification>}
54
+
55
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
56
+ @frontend.tax_table_factory = TestTaxTableFactory.new
57
+ end
58
+
59
+ def test_responds_correctly
60
+ assert_respond_to NewOrderNotification, :create_from_element
61
+
62
+ notification = NewOrderNotification.new(@frontend)
63
+
64
+ [ :serial_number, :google_order_number, :buyer_billing_address, :buyer_shipping_address,
65
+ :buyer_id, :marketing_preferences, :financial_order_state, :fulfillment_order_state,
66
+ :google_order_number, :order_adjustment, :order_total, :shopping_cart, :timestamp,
67
+ :serial_number=, :google_order_number=, :buyer_billing_address=, :buyer_shipping_address=,
68
+ :buyer_id=, :marketing_preferences=, :financial_order_state=, :fulfillment_order_state=,
69
+ :google_order_number=, :order_adjustment=, :order_total=, :shopping_cart=, :timestamp=,
70
+ ].each do |symbol|
71
+ assert_respond_to notification, symbol
72
+ end
73
+ end
74
+
75
+ def test_create_from_element_works_correctly
76
+ # Build up some Mocha expectations.
77
+ expect = Address.stubs(:create_from_element)
78
+ expect.times(1).returns(:buyer_billing_address)
79
+ expect.with{ |element| element.name == 'buyer-billing-address' }
80
+
81
+ expect = Address.stubs(:create_from_element)
82
+ expect.times(1).returns(:buyer_shipping_address)
83
+ expect.with{ |element| element.name == 'buyer-shipping-address' }
84
+
85
+ expect = MarketingPreferences.stubs(:create_from_element)
86
+ expect.times(1).returns(:marketing_preferences)
87
+ expect.with{ |element| element.name == 'buyer-marketing-preferences' }
88
+
89
+ expect = OrderAdjustment.stubs(:create_from_element)
90
+ expect.times(1).returns(:order_adjustment)
91
+ expect.with{ |element| element.name == 'order-adjustment' }
92
+
93
+ expect = ShoppingCart.stubs(:create_from_element)
94
+ expect.times(1).returns(:shopping_cart)
95
+ expect.with { |element, owner| element.name == 'shopping-cart' and owner.kind_of?(NewOrderNotification) }
96
+
97
+ # Create the new notification.
98
+ notification = NewOrderNotification.create_from_element(REXML::Document.new(@xml_str).root, @frontend)
99
+
100
+ # perform the assertions
101
+ assert_equal "8571632143", notification.serial_number
102
+ assert_equal "6014423719", notification.google_order_number
103
+ assert_equal :buyer_billing_address, notification.buyer_billing_address
104
+ assert_equal :buyer_shipping_address, notification.buyer_shipping_address
105
+ assert_equal "294873009217523", notification.buyer_id
106
+ assert_equal :marketing_preferences, notification.marketing_preferences
107
+ assert_equal "REVIEWING", notification.financial_order_state
108
+ assert_equal "NEW", notification.fulfillment_order_state
109
+ assert_equal "6014423719", notification.google_order_number
110
+ assert_equal :order_adjustment, notification.order_adjustment
111
+ assert_equal Money.new(32198, "USD"), notification.order_total
112
+ assert_equal :shopping_cart, notification.shopping_cart
113
+ assert_equal Time.parse("2006-03-18T17:32:11"), notification.timestamp
114
+ end
115
+ end
@@ -0,0 +1,43 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/notification_acknowledgement_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 'test/checkout/frontend_configuration'
31
+
32
+ require 'google4r/checkout'
33
+
34
+ # Test for the class NotificationAcknowledgement.
35
+ class Google4R::Checkout::NotificationAcknowledgementTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def test_to_xml_works_as_expected
39
+ ack = NotificationAcknowledgement.new
40
+ str = %q{<?xml version="1.0" encoding="UTF-8"?><notification-acknowledgment xmlns="http://checkout.google.com/schema/2"/>}
41
+ assert_equal str, ack.to_xml
42
+ end
43
+ end
@@ -0,0 +1,93 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/notification_handler_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 'test/checkout/frontend_configuration'
31
+
32
+ require 'google4r/checkout'
33
+
34
+ # Test for the class NotificationHandler.
35
+ class Google4R::Checkout::NotificationHandlerTest < 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
+ @notification_handler = @frontend.create_notification_handler
42
+
43
+ @xmls_with_known_tags =
44
+ [
45
+ [
46
+ '<new-order-notification xmlns="http://checkout.google.com/schema/2" />',
47
+ 'new-order-notification',
48
+ NewOrderNotification
49
+ ],
50
+ [
51
+ '<order-state-change-notification xmlns="http://checkout.google.com/schema/2" />',
52
+ 'order-state-change-notification',
53
+ OrderStateChangeNotification
54
+ ]
55
+ ]
56
+
57
+ @xmls_with_unknown_tags =
58
+ [
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" />}
65
+ ]
66
+ end
67
+
68
+ def test_handler_gets_initialized_correctly
69
+ assert_equal @frontend, @notification_handler.frontend
70
+ end
71
+
72
+ def test_returns_correct_notification_class_for_known_notifications
73
+ @xmls_with_known_tags.each do |triple|
74
+ xml_str, tag_name, klass = triple
75
+
76
+ expect = klass.stubs(:create_from_element)
77
+ expect.times(1).returns(:foo)
78
+ expect.with { |element, frontend| element.name == tag_name and frontend == @frontend }
79
+
80
+ result = nil
81
+ assert_nothing_raised {
82
+ result = @notification_handler.handle(xml_str)
83
+ }
84
+ assert_equal :foo, result
85
+ end
86
+ end
87
+
88
+ def test_raises_exception_on_unknown_notifications
89
+ @xmls_with_unknown_tags.each do |xml_str|
90
+ assert_raises(UnknownNotificationType) { @notification_handler.handle(xml_str) }
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,95 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/order_adjustment_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 'test/checkout/frontend_configuration'
31
+
32
+ require 'google4r/checkout'
33
+
34
+ # Test for the class OrderAdjustment.
35
+ class Google4R::Checkout::OrderAdjustmentTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
40
+ <order-adjustment>
41
+ <merchant-calculation-successful>true</merchant-calculation-successful>
42
+ <merchant-codes>
43
+ <dummy-adjustment-one />
44
+ <dummy-adjustment-two />
45
+ </merchant-codes>
46
+ <total-tax currency="USD">11.05</total-tax>
47
+ <adjustment-total currency="USD">12.05</adjustment-total>
48
+ <shipping>
49
+ <%s />
50
+ </shipping>
51
+ </order-adjustment>}
52
+ @shipping_adjustments = [ 'flat-rate-shipping-adjustment', 'pickup-shipping-adjustment' ]
53
+ end
54
+
55
+ def test_reponds_correctly
56
+ assert_respond_to OrderAdjustment, :create_from_element
57
+
58
+ adjustment = OrderAdjustment.new
59
+
60
+ [ :adjustment_total, :adjustment_total=, :merchant_calculation_successful,
61
+ :merchant_calculation_successful, :merchant_codes, :merchant_codes=,
62
+ :shipping, :shipping=, :total_tax, :total_tax=
63
+ ].each do |symbol|
64
+ assert_respond_to adjustment, symbol
65
+ end
66
+ end
67
+
68
+ def test_create_from_xml_works_correctly
69
+ @shipping_adjustments.each do |adjustment_name|
70
+ # Build Mocha Expectations
71
+ expect = MerchantCode.stubs(:create_from_element)
72
+ expect.with { |element| element.name == 'dummy-adjustment-one' }
73
+ expect.times(1).returns(:dummy_adjustment1)
74
+
75
+ expect = MerchantCode.stubs(:create_from_element)
76
+ expect.with { |element| element.name == 'dummy-adjustment-two' }
77
+ expect.times(1).returns(:dummy_adjustment2)
78
+
79
+ expect = ShippingAdjustment.stubs(:create_from_element)
80
+ expect.with { |element| element.name == adjustment_name }
81
+ expect.times(1).returns(adjustment_name.to_sym)
82
+
83
+ # Create the adjustment
84
+ element = REXML::Document.new(@xml_str % [ adjustment_name ]).root
85
+ adjustment = OrderAdjustment.create_from_element(element)
86
+
87
+ # Assert!
88
+ assert_equal Money.new(1205, 'USD'), adjustment.adjustment_total
89
+ assert_equal true, adjustment.merchant_calculation_successful
90
+ assert_equal [ :dummy_adjustment1, :dummy_adjustment2 ], adjustment.merchant_codes
91
+ assert_equal adjustment_name.to_sym, adjustment.shipping
92
+ assert_equal Money.new(1105, 'USD'), adjustment.total_tax
93
+ end
94
+ end
95
+ end