archerfinley-google4r-checkout-1.0.5 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/CHANGES +93 -0
  2. data/LICENSE +22 -0
  3. data/README +58 -0
  4. data/Rakefile +13 -0
  5. data/VERSION +1 -0
  6. data/google4r-checkout-1.0.5-1.0.5.gem +0 -0
  7. data/google4r-checkout-1.0.5.gemspec +174 -0
  8. data/lib/google4r/checkout.rb +34 -0
  9. data/lib/google4r/checkout/commands.rb +567 -0
  10. data/lib/google4r/checkout/frontend.rb +210 -0
  11. data/lib/google4r/checkout/merchant_calculation.rb +321 -0
  12. data/lib/google4r/checkout/notifications.rb +708 -0
  13. data/lib/google4r/checkout/shared.rb +1086 -0
  14. data/lib/google4r/checkout/utils.rb +94 -0
  15. data/lib/google4r/checkout/xml_generation.rb +880 -0
  16. data/test/integration/checkout_command_test.rb +174 -0
  17. data/test/unit/add_merchant_order_number_command_test.rb +70 -0
  18. data/test/unit/add_tracking_data_command_test.rb +75 -0
  19. data/test/unit/address_test.rb +131 -0
  20. data/test/unit/anonymous_address_test.rb +75 -0
  21. data/test/unit/archive_order_command_test.rb +66 -0
  22. data/test/unit/area_test.rb +44 -0
  23. data/test/unit/authorization_amount_notification_test.rb +69 -0
  24. data/test/unit/authorize_order_command_test.rb +66 -0
  25. data/test/unit/backorder_items_command_test.rb +83 -0
  26. data/test/unit/callback_handler_test.rb +83 -0
  27. data/test/unit/cancel_items_command_test.rb +89 -0
  28. data/test/unit/cancel_order_command_test.rb +83 -0
  29. data/test/unit/carrier_calculated_shipping_test.rb +57 -0
  30. data/test/unit/charge_amount_notification_test.rb +64 -0
  31. data/test/unit/charge_order_command_test.rb +77 -0
  32. data/test/unit/chargeback_amount_notification_test.rb +65 -0
  33. data/test/unit/checkout_command_test.rb +125 -0
  34. data/test/unit/checkout_command_xml_generator_test.rb +218 -0
  35. data/test/unit/command_test.rb +116 -0
  36. data/test/unit/deliver_order_command_test.rb +70 -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 +132 -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 +172 -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 +178 -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 +111 -0
  55. data/test/unit/order_state_change_notification_test.rb +158 -0
  56. data/test/unit/pickup_shipping_test.rb +70 -0
  57. data/test/unit/postal_area_test.rb +71 -0
  58. data/test/unit/private_data_parser_test.rb +68 -0
  59. data/test/unit/refund_amount_notification_test.rb +65 -0
  60. data/test/unit/refund_order_command_test.rb +86 -0
  61. data/test/unit/reset_items_shipping_information_command_test.rb +83 -0
  62. data/test/unit/return_items_command_test.rb +83 -0
  63. data/test/unit/risk_information_notification_test.rb +98 -0
  64. data/test/unit/send_buyer_message_command_test.rb +73 -0
  65. data/test/unit/ship_items_command_test.rb +101 -0
  66. data/test/unit/shipping_adjustment_test.rb +100 -0
  67. data/test/unit/shopping_cart_test.rb +146 -0
  68. data/test/unit/tax_rule_test.rb +70 -0
  69. data/test/unit/tax_table_test.rb +82 -0
  70. data/test/unit/tracking_data_test.rb +54 -0
  71. data/test/unit/unarchive_order_command_test.rb +66 -0
  72. data/test/unit/us_country_area_test.rb +76 -0
  73. data/test/unit/us_state_area_test.rb +70 -0
  74. data/test/unit/us_zip_area_test.rb +66 -0
  75. data/test/unit/world_area_test.rb +48 -0
  76. data/var/cacert.pem +7815 -0
  77. metadata +189 -0
@@ -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
@@ -0,0 +1,119 @@
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 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
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
+
96
+ def test_create_from_xml_works_correctly_without_shiping_tag
97
+ # Build Mocha Expectations
98
+ expect = MerchantCode.stubs(:create_from_element)
99
+ expect.with { |element| element.name == 'dummy-adjustment-one' }
100
+ expect.times(1).returns(:dummy_adjustment1)
101
+
102
+ expect = MerchantCode.stubs(:create_from_element)
103
+ expect.with { |element| element.name == 'dummy-adjustment-two' }
104
+ expect.times(1).returns(:dummy_adjustment2)
105
+
106
+ expect = ShippingAdjustment.expects(:create_from_element).never
107
+
108
+ # Create the adjustment
109
+ element = REXML::Document.new(@xml_str.gsub(%r{<shipping>.*<\/shipping>}m, '')).root
110
+ adjustment = OrderAdjustment.create_from_element(element)
111
+
112
+ # Assert!
113
+ assert_equal Money.new(1205, 'USD'), adjustment.adjustment_total
114
+ assert_equal true, adjustment.merchant_calculation_successful
115
+ assert_equal [ :dummy_adjustment1, :dummy_adjustment2 ], adjustment.merchant_codes
116
+ assert_equal nil, adjustment.shipping
117
+ assert_equal Money.new(1105, 'USD'), adjustment.total_tax
118
+ end
119
+ end
@@ -0,0 +1,111 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/order_report_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::OrderReportCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_order_report_command(
41
+ Time.utc(2007, 9, 1, 0, 0, 0),
42
+ Time.utc(2007, 9, 30, 23, 59, 59))
43
+ @command.financial_state = 'CHARGED'
44
+ @command.fulfillment_state = 'NEW'
45
+ @command.date_time_zone = 'America/New_York'
46
+
47
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
48
+ <order-list-request end-date='2007-09-30T23:59:59' start-date='2007-09-01T00:00:00' xmlns='http://checkout.google.com/schema/2'>
49
+ <financial-state>CHARGED</financial-state>
50
+ <fulfillment-state>NEW</fulfillment-state>
51
+ <date-time-zone>America/New_York</date-time-zone>
52
+ </order-list-request>}
53
+ end
54
+
55
+ def test_behaves_correctly
56
+ [ :start_date, :end_date,
57
+ :financial_state, :financial_state=,
58
+ :fulfillment_state, :fulfillment_state=,
59
+ :date_time_zone, :date_time_zone= ].each do |symbol|
60
+ assert_respond_to @command, symbol
61
+ end
62
+ end
63
+
64
+ def test_to_xml
65
+ assert_strings_equal(@sample_xml, @command.to_xml)
66
+ end
67
+
68
+ def test_accessors
69
+ assert_equal('2007-09-01T00:00:00', @command.start_date)
70
+ assert_equal('2007-09-30T23:59:59', @command.end_date)
71
+ assert_equal('CHARGED', @command.financial_state)
72
+ assert_equal('NEW', @command.fulfillment_state)
73
+ assert_equal('America/New_York', @command.date_time_zone)
74
+ end
75
+
76
+ def test_good_dates
77
+ assert_nothing_raised RuntimeError do
78
+ @frontend.create_order_report_command(
79
+ Time.utc(2007, 9, 1, 0, 0, 0),
80
+ Time.utc(2007, 9, 30, 23, 59, 59))
81
+ end
82
+ end
83
+
84
+ def test_dates_should_not_be_string
85
+ assert_raise RuntimeError do
86
+ @frontend.create_order_report_command(
87
+ '2007-09-01T00:00:00',
88
+ '2007-09-30T23:59:59')
89
+ end
90
+ end
91
+
92
+ def test_end_date_before_start_date
93
+ assert_raise RuntimeError do
94
+ @frontend.create_order_report_command(
95
+ Time.utc(2007, 9, 1, 0, 0, 0),
96
+ Time.utc(2006, 9, 30, 23, 59, 59))
97
+ end
98
+ end
99
+
100
+ def test_financial_state
101
+ assert_raise RuntimeError do
102
+ @command.financial_state = 'DUMMY'
103
+ end
104
+ end
105
+
106
+ def test_fulfillment_state
107
+ assert_raise RuntimeError do
108
+ @command.fulfillment_state = 'DUMMY'
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,158 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/order_state_change_notification_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 Area.
35
+ class Google4R::Checkout::OrderStateChangeNotificationTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @data = Hash.new
40
+ @data[:serial_number] = "c821426e-7caa-4d51-9b2e-48ef7ecd6423"
41
+ @data[:google_order_number] = "841171949013218"
42
+ @data[:new_financial_order_state] = "CHARGING"
43
+ @data[:previous_fulfillment_order_state] = "NEW"
44
+ @data[:new_financial_order_state] = "CHARGEABLE"
45
+ @data[:previous_fulfillment_order_state] = "NEW"
46
+ @data[:reason] = "charge_customer"
47
+ @data[:timestamp] = Time.new
48
+
49
+ @xml_template = %q{<?xml version="1.0" encoding="UTF-8"?>
50
+ <order-state-change-notification xmlns="http://checkout.google.com/schema/2" serial-number="%s">
51
+ <google-order-number>%s</google-order-number>
52
+ <new-financial-order-state>%s</new-financial-order-state>
53
+ <new-fulfillment-order-state>%s</new-fulfillment-order-state>
54
+ <previous-financial-order-state>%s</previous-financial-order-state>
55
+ <previous-fulfillment-order-state>%s</previous-fulfillment-order-state>
56
+ <reason>%s</reason>
57
+ <timestamp>%s</timestamp>
58
+ </order-state-change-notification>
59
+ }
60
+
61
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
62
+ @frontend.tax_table_factory = TestTaxTableFactory.new
63
+ end
64
+
65
+ def test_order_state_change_notification_responds_correctly
66
+ assert_respond_to OrderStateChangeNotification, :create_from_element
67
+
68
+ notification = OrderStateChangeNotification.new(@frontend)
69
+
70
+ [ :serial_number, :google_order_number, :new_financial_order_state, :previous_fulfillment_order_state,
71
+ :new_financial_order_state, :previous_fulfillment_order_state, :reason, :timestamp,
72
+ :serial_number=, :google_order_number=, :new_financial_order_state=, :previous_fulfillment_order_state=,
73
+ :new_financial_order_state=, :previous_fulfillment_order_state=, :reason=, :timestamp
74
+ ].each do |sym|
75
+ assert_respond_to notification, sym
76
+ end
77
+ end
78
+
79
+ def test_financial_order_state_defines_correct_constants
80
+ assert defined?(FinancialOrderState::REVIEWING)
81
+ assert defined?(FinancialOrderState::CHARGEABLE)
82
+ assert defined?(FinancialOrderState::CHARGING)
83
+ assert defined?(FinancialOrderState::CHARGED)
84
+ assert defined?(FinancialOrderState::PAYMENT_DECLINED)
85
+ assert defined?(FinancialOrderState::CANCELLED)
86
+ assert defined?(FinancialOrderState::CANCELLED_BY_GOOGLE)
87
+
88
+ assert_equal "REVIEWING", FinancialOrderState::REVIEWING
89
+ assert_equal "CHARGEABLE", FinancialOrderState::CHARGEABLE
90
+ assert_equal "CHARGING", FinancialOrderState::CHARGING
91
+ assert_equal "CHARGED", FinancialOrderState::CHARGED
92
+ assert_equal "PAYMENT_DECLINED", FinancialOrderState::PAYMENT_DECLINED
93
+ assert_equal "CANCELLED", FinancialOrderState::CANCELLED
94
+ assert_equal "CANCELLED_BY_GOOGLE", FinancialOrderState::CANCELLED_BY_GOOGLE
95
+ end
96
+
97
+ def test_fulfillment_order_state_defines_correct_constants
98
+ assert defined?(FulfillmentOrderState::NEW)
99
+ assert defined?(FulfillmentOrderState::PROCESSING)
100
+ assert defined?(FulfillmentOrderState::DELIVERED)
101
+ assert defined?(FulfillmentOrderState::WILL_NOT_DELIVER)
102
+
103
+ assert_equal "NEW", FulfillmentOrderState::NEW
104
+ assert_equal "PROCESSING", FulfillmentOrderState::PROCESSING
105
+ assert_equal "DELIVERED", FulfillmentOrderState::DELIVERED
106
+ assert_equal "WILL_NOT_DELIVER", FulfillmentOrderState::WILL_NOT_DELIVER
107
+ end
108
+
109
+ # <reason> in notification
110
+ def test_create_from_xml_should_correctly_create_order_state_change_notification_with_reason
111
+ [ true, false ].each do |skip_reason|
112
+ xml_str = @xml_template %
113
+ [
114
+ @data[:serial_number], @data[:google_order_number], @data[:new_financial_order_state],
115
+ @data[:new_fulfillment_order_state], @data[:previous_financial_order_state],
116
+ @data[:previous_fulfillment_order_state], @data[:reason], @data[:timestamp].iso8601
117
+ ]
118
+
119
+ xml_str = xml_str.gsub(/<reason>.*?<\/reason>/, '') if skip_reason
120
+
121
+ notification = OrderStateChangeNotification.create_from_element(REXML::Document.new(xml_str).root, @frontend)
122
+
123
+ @data.each do |key, value|
124
+ next if skip_reason and key == :reason
125
+
126
+ if key == :timestamp then
127
+ assert_in_delta @data[:timestamp].to_f, notification.timestamp.to_f, 1
128
+ else
129
+ assert_equal @data[key], notification.send(key), "#{key}"
130
+ end
131
+ end
132
+
133
+ assert_nil notification.reason if skip_reason
134
+ end
135
+ end
136
+
137
+ def test_create_from_xml_should_raise_exception_with_missing_tags
138
+ # Remove all required tags from the XML and expect the XPath query in
139
+ # OrderStateChangeNotification#create_from_xml to evaluate to nil and thus
140
+ # raise a NoMethodError.
141
+ [ 'google-order-number', 'new-financial-order-state', 'new-fulfillment-order-state',
142
+ 'previous-financial-order-state', 'previous-fulfillment-order-state', 'timestamp' ].each do |tag_name|
143
+ xml_str = @xml_template %
144
+ [
145
+ @data[:serial_number], @data[:google_order_number], @data[:new_financial_order_state],
146
+ @data[:new_fulfillment_order_state], @data[:previous_financial_order_state],
147
+ @data[:previous_fulfillment_order_state], @data[:reason], @data[:timestamp].iso8601
148
+ ]
149
+
150
+ xml_str = xml_str.gsub(%r{<#{tag_name}>.*?</#{tag_name}>}, '')
151
+ doc = REXML::Document.new(xml_str)
152
+
153
+ assert_raises(NoMethodError, "Removed tag: #{tag_name} - #{xml_str}") {
154
+ notification = OrderStateChangeNotification.create_from_element(doc.root, @frontend)
155
+ }
156
+ end
157
+ end
158
+ end