google4r-checkout-jn 1.1.jniziol

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 (79) hide show
  1. data/CHANGES +136 -0
  2. data/LICENSE +22 -0
  3. data/README.md +72 -0
  4. data/lib/google4r/checkout.rb +34 -0
  5. data/lib/google4r/checkout/commands.rb +665 -0
  6. data/lib/google4r/checkout/frontend.rb +222 -0
  7. data/lib/google4r/checkout/merchant_calculation.rb +323 -0
  8. data/lib/google4r/checkout/notifications.rb +774 -0
  9. data/lib/google4r/checkout/shared.rb +1386 -0
  10. data/lib/google4r/checkout/utils.rb +94 -0
  11. data/lib/google4r/checkout/xml_generation.rb +1023 -0
  12. data/test/frontend_configuration_example.rb +13 -0
  13. data/test/integration/checkout_command_test.rb +261 -0
  14. data/test/test_helper.rb +105 -0
  15. data/test/unit/add_merchant_order_number_command_test.rb +65 -0
  16. data/test/unit/add_tracking_data_command_test.rb +68 -0
  17. data/test/unit/address_test.rb +131 -0
  18. data/test/unit/anonymous_address_test.rb +75 -0
  19. data/test/unit/archive_order_command_test.rb +63 -0
  20. data/test/unit/area_test.rb +44 -0
  21. data/test/unit/authorization_amount_notification_test.rb +69 -0
  22. data/test/unit/authorize_order_command_test.rb +63 -0
  23. data/test/unit/backorder_items_command_test.rb +69 -0
  24. data/test/unit/callback_handler_test.rb +83 -0
  25. data/test/unit/cancel_items_command_test.rb +76 -0
  26. data/test/unit/cancel_order_command_test.rb +74 -0
  27. data/test/unit/carrier_calculated_shipping_test.rb +57 -0
  28. data/test/unit/charge_amount_notification_test.rb +72 -0
  29. data/test/unit/charge_and_ship_order_command_test.rb +69 -0
  30. data/test/unit/charge_fee_test.rb +53 -0
  31. data/test/unit/charge_order_command_test.rb +69 -0
  32. data/test/unit/chargeback_amount_notification_test.rb +69 -0
  33. data/test/unit/checkout_command_test.rb +149 -0
  34. data/test/unit/checkout_command_xml_generator_test.rb +216 -0
  35. data/test/unit/command_test.rb +116 -0
  36. data/test/unit/deliver_order_command_test.rb +65 -0
  37. data/test/unit/delivery_method_test.rb +42 -0
  38. data/test/unit/digital_content_test.rb +105 -0
  39. data/test/unit/flat_rate_shipping_test.rb +133 -0
  40. data/test/unit/frontend_test.rb +144 -0
  41. data/test/unit/item_info_test.rb +69 -0
  42. data/test/unit/item_test.rb +171 -0
  43. data/test/unit/marketing_preferences_test.rb +65 -0
  44. data/test/unit/merchant_calculated_shipping_test.rb +173 -0
  45. data/test/unit/merchant_calculation_callback_test.rb +137 -0
  46. data/test/unit/merchant_calculation_result_test.rb +78 -0
  47. data/test/unit/merchant_calculation_results_test.rb +203 -0
  48. data/test/unit/merchant_code_result_test.rb +51 -0
  49. data/test/unit/merchant_code_test.rb +122 -0
  50. data/test/unit/new_order_notification_test.rb +115 -0
  51. data/test/unit/notification_acknowledgement_test.rb +67 -0
  52. data/test/unit/notification_handler_test.rb +113 -0
  53. data/test/unit/order_adjustment_test.rb +119 -0
  54. data/test/unit/order_report_command_test.rb +109 -0
  55. data/test/unit/order_state_change_notification_test.rb +158 -0
  56. data/test/unit/parameterized_url_test.rb +57 -0
  57. data/test/unit/pickup_shipping_test.rb +70 -0
  58. data/test/unit/postal_area_test.rb +71 -0
  59. data/test/unit/private_data_parser_test.rb +68 -0
  60. data/test/unit/refund_amount_notification_test.rb +67 -0
  61. data/test/unit/refund_order_command_test.rb +79 -0
  62. data/test/unit/reset_items_shipping_information_command_test.rb +69 -0
  63. data/test/unit/return_items_command_test.rb +69 -0
  64. data/test/unit/risk_information_notification_test.rb +98 -0
  65. data/test/unit/send_buyer_message_command_test.rb +68 -0
  66. data/test/unit/ship_items_command_test.rb +81 -0
  67. data/test/unit/shipping_adjustment_test.rb +100 -0
  68. data/test/unit/shopping_cart_test.rb +146 -0
  69. data/test/unit/tax_rule_test.rb +70 -0
  70. data/test/unit/tax_table_test.rb +88 -0
  71. data/test/unit/tracking_data_test.rb +54 -0
  72. data/test/unit/unarchive_order_command_test.rb +63 -0
  73. data/test/unit/url_parameter_test.rb +55 -0
  74. data/test/unit/us_country_area_test.rb +76 -0
  75. data/test/unit/us_state_area_test.rb +70 -0
  76. data/test/unit/us_zip_area_test.rb +66 -0
  77. data/test/unit/world_area_test.rb +48 -0
  78. data/var/cacert.pem +7815 -0
  79. metadata +230 -0
@@ -0,0 +1,51 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/merchant_code_result_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 MerchantCode.
35
+ class Google4R::Checkout::MerchantCodeResultTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+
40
+ end
41
+
42
+ def test_responds_correctly
43
+ adjustment = CouponResult.new(true, 'some_code', Money.new(1000, 'USD'), 'A message')
44
+
45
+ [ :valid, :valid=, :code, :code=, :calculated_amount,
46
+ :calculated_amount=, :message, :message=,
47
+ ].each do |sym|
48
+ assert_respond_to adjustment, sym
49
+ end
50
+ end
51
+ 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 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
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_argument_error_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(ArgumentError) 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 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
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,67 @@
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 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Test for the class NotificationAcknowledgement.
35
+ class Google4R::Checkout::NotificationAcknowledgementTest < 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
+ @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
+
54
+ def test_to_xml_works_as_expected
55
+ ack = NotificationAcknowledgement.new
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'/>}
65
+ assert_equal str, ack.to_xml
66
+ end
67
+ end
@@ -0,0 +1,113 @@
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 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
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
+ '<risk-information-notification xmlns="http://checkout.google.com/schema/2" />',
57
+ 'risk-information-notification',
58
+ RiskInformationNotification
59
+ ],
60
+ [
61
+ '<charge-amount-notification xmlns="http://checkout.google.com/schema/2" />',
62
+ 'charge-amount-notification',
63
+ ChargeAmountNotification
64
+ ],
65
+ [
66
+ '<refund-amount-notification xmlns="http://checkout.google.com/schema/2" />',
67
+ 'refund-amount-notification',
68
+ RefundAmountNotification
69
+ ],
70
+ [
71
+ '<chargeback-amount-notification xmlns="http://checkout.google.com/schema/2" />',
72
+ 'chargeback-amount-notification',
73
+ ChargebackAmountNotification
74
+ ],
75
+ [
76
+ '<authorization-amount-notification xmlns="http://checkout.google.com/schema/2" />',
77
+ 'authorization-amount-notification',
78
+ AuthorizationAmountNotification
79
+ ],
80
+ ]
81
+
82
+ @xmls_with_unknown_tags =
83
+ [
84
+ '<unknown-notification />'
85
+ ]
86
+ end
87
+
88
+ def test_handler_gets_initialized_correctly
89
+ assert_equal @frontend, @notification_handler.frontend
90
+ end
91
+
92
+ def test_returns_correct_notification_class_for_known_notifications
93
+ @xmls_with_known_tags.each do |triple|
94
+ xml_str, tag_name, klass = triple
95
+
96
+ expect = klass.stubs(:create_from_element)
97
+ expect.times(1).returns(:foo)
98
+ expect.with { |element, frontend| element.name == tag_name and frontend == @frontend }
99
+
100
+ result = nil
101
+ assert_nothing_raised {
102
+ result = @notification_handler.handle(xml_str)
103
+ }
104
+ assert_equal :foo, result
105
+ end
106
+ end
107
+
108
+ def test_raises_exception_on_unknown_notifications
109
+ @xmls_with_unknown_tags.each do |xml_str|
110
+ assert_raises(UnknownNotificationType) { @notification_handler.handle(xml_str) }
111
+ end
112
+ end
113
+ end