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.
- data/CHANGES +136 -0
- data/LICENSE +22 -0
- data/README.md +72 -0
- data/lib/google4r/checkout.rb +34 -0
- data/lib/google4r/checkout/commands.rb +665 -0
- data/lib/google4r/checkout/frontend.rb +222 -0
- data/lib/google4r/checkout/merchant_calculation.rb +323 -0
- data/lib/google4r/checkout/notifications.rb +774 -0
- data/lib/google4r/checkout/shared.rb +1386 -0
- data/lib/google4r/checkout/utils.rb +94 -0
- data/lib/google4r/checkout/xml_generation.rb +1023 -0
- data/test/frontend_configuration_example.rb +13 -0
- data/test/integration/checkout_command_test.rb +261 -0
- data/test/test_helper.rb +105 -0
- data/test/unit/add_merchant_order_number_command_test.rb +65 -0
- data/test/unit/add_tracking_data_command_test.rb +68 -0
- data/test/unit/address_test.rb +131 -0
- data/test/unit/anonymous_address_test.rb +75 -0
- data/test/unit/archive_order_command_test.rb +63 -0
- data/test/unit/area_test.rb +44 -0
- data/test/unit/authorization_amount_notification_test.rb +69 -0
- data/test/unit/authorize_order_command_test.rb +63 -0
- data/test/unit/backorder_items_command_test.rb +69 -0
- data/test/unit/callback_handler_test.rb +83 -0
- data/test/unit/cancel_items_command_test.rb +76 -0
- data/test/unit/cancel_order_command_test.rb +74 -0
- data/test/unit/carrier_calculated_shipping_test.rb +57 -0
- data/test/unit/charge_amount_notification_test.rb +72 -0
- data/test/unit/charge_and_ship_order_command_test.rb +69 -0
- data/test/unit/charge_fee_test.rb +53 -0
- data/test/unit/charge_order_command_test.rb +69 -0
- data/test/unit/chargeback_amount_notification_test.rb +69 -0
- data/test/unit/checkout_command_test.rb +149 -0
- data/test/unit/checkout_command_xml_generator_test.rb +216 -0
- data/test/unit/command_test.rb +116 -0
- data/test/unit/deliver_order_command_test.rb +65 -0
- data/test/unit/delivery_method_test.rb +42 -0
- data/test/unit/digital_content_test.rb +105 -0
- data/test/unit/flat_rate_shipping_test.rb +133 -0
- data/test/unit/frontend_test.rb +144 -0
- data/test/unit/item_info_test.rb +69 -0
- data/test/unit/item_test.rb +171 -0
- data/test/unit/marketing_preferences_test.rb +65 -0
- data/test/unit/merchant_calculated_shipping_test.rb +173 -0
- data/test/unit/merchant_calculation_callback_test.rb +137 -0
- data/test/unit/merchant_calculation_result_test.rb +78 -0
- data/test/unit/merchant_calculation_results_test.rb +203 -0
- data/test/unit/merchant_code_result_test.rb +51 -0
- data/test/unit/merchant_code_test.rb +122 -0
- data/test/unit/new_order_notification_test.rb +115 -0
- data/test/unit/notification_acknowledgement_test.rb +67 -0
- data/test/unit/notification_handler_test.rb +113 -0
- data/test/unit/order_adjustment_test.rb +119 -0
- data/test/unit/order_report_command_test.rb +109 -0
- data/test/unit/order_state_change_notification_test.rb +158 -0
- data/test/unit/parameterized_url_test.rb +57 -0
- data/test/unit/pickup_shipping_test.rb +70 -0
- data/test/unit/postal_area_test.rb +71 -0
- data/test/unit/private_data_parser_test.rb +68 -0
- data/test/unit/refund_amount_notification_test.rb +67 -0
- data/test/unit/refund_order_command_test.rb +79 -0
- data/test/unit/reset_items_shipping_information_command_test.rb +69 -0
- data/test/unit/return_items_command_test.rb +69 -0
- data/test/unit/risk_information_notification_test.rb +98 -0
- data/test/unit/send_buyer_message_command_test.rb +68 -0
- data/test/unit/ship_items_command_test.rb +81 -0
- data/test/unit/shipping_adjustment_test.rb +100 -0
- data/test/unit/shopping_cart_test.rb +146 -0
- data/test/unit/tax_rule_test.rb +70 -0
- data/test/unit/tax_table_test.rb +88 -0
- data/test/unit/tracking_data_test.rb +54 -0
- data/test/unit/unarchive_order_command_test.rb +63 -0
- data/test/unit/url_parameter_test.rb +55 -0
- data/test/unit/us_country_area_test.rb +76 -0
- data/test/unit/us_state_area_test.rb +70 -0
- data/test/unit/us_zip_area_test.rb +66 -0
- data/test/unit/world_area_test.rb +48 -0
- data/var/cacert.pem +7815 -0
- metadata +230 -0
@@ -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,109 @@
|
|
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
|
+
end
|
47
|
+
|
48
|
+
def test_behaves_correctly
|
49
|
+
[ :start_date, :end_date,
|
50
|
+
:financial_state, :financial_state=,
|
51
|
+
:fulfillment_state, :fulfillment_state=,
|
52
|
+
:date_time_zone, :date_time_zone= ].each do |symbol|
|
53
|
+
assert_respond_to @command, symbol
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_to_xml
|
58
|
+
selector = "order-list-request[start-date='#{@command.start_date}'][end-date='#{@command.end_date}']"
|
59
|
+
xml = @command.to_xml
|
60
|
+
|
61
|
+
assert_element_text_equals(@command.financial_state, "#{selector} > financial-state", xml)
|
62
|
+
assert_element_text_equals(@command.fulfillment_state, "#{selector} > fulfillment-state", xml)
|
63
|
+
assert_element_text_equals(@command.date_time_zone, "#{selector} > date-time-zone", xml)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_accessors
|
67
|
+
assert_equal('2007-09-01T00:00:00', @command.start_date)
|
68
|
+
assert_equal('2007-09-30T23:59:59', @command.end_date)
|
69
|
+
assert_equal('CHARGED', @command.financial_state)
|
70
|
+
assert_equal('NEW', @command.fulfillment_state)
|
71
|
+
assert_equal('America/New_York', @command.date_time_zone)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_good_dates
|
75
|
+
assert_nothing_raised RuntimeError do
|
76
|
+
@frontend.create_order_report_command(
|
77
|
+
Time.utc(2007, 9, 1, 0, 0, 0),
|
78
|
+
Time.utc(2007, 9, 30, 23, 59, 59))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_dates_should_not_be_string
|
83
|
+
assert_raise RuntimeError do
|
84
|
+
@frontend.create_order_report_command(
|
85
|
+
'2007-09-01T00:00:00',
|
86
|
+
'2007-09-30T23:59:59')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_end_date_before_start_date
|
91
|
+
assert_raise RuntimeError do
|
92
|
+
@frontend.create_order_report_command(
|
93
|
+
Time.utc(2007, 9, 1, 0, 0, 0),
|
94
|
+
Time.utc(2006, 9, 30, 23, 59, 59))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_financial_state
|
99
|
+
assert_raise RuntimeError do
|
100
|
+
@command.financial_state = 'DUMMY'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_fulfillment_state
|
105
|
+
assert_raise RuntimeError do
|
106
|
+
@command.fulfillment_state = 'DUMMY'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
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
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/paramterized_url_test.rb
|
4
|
+
# Author: Johnathan Niziol <johnathan.niziol at canadadrugs dot com>
|
5
|
+
# Copyright: (c) 2011 by Johnathan Niziol
|
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 Parameterized class.
|
35
|
+
class Google4R::Checkout::ParameterizedUrlTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@parameterized_url = ParameterizedUrl.new("http://testurl.com")
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_parameterized_url_behaves_correctly
|
43
|
+
assert_respond_to @parameterized_url, :url
|
44
|
+
assert_respond_to @parameterized_url, :create_url_parameter
|
45
|
+
assert_respond_to @parameterized_url, :url_parameters
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_initialized_correctly
|
49
|
+
assert_equal "http://testurl.com", @parameterized_url.url
|
50
|
+
assert_equal [], @parameterized_url.url_parameters
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_accessors_work_correctly
|
54
|
+
@parameterized_url.url = "url"
|
55
|
+
assert_equal "url", @parameterized_url.url
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/pickup_shipping_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 PickupShipping class.
|
35
|
+
class Google4R::Checkout::PickupShippingMethodTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@shipping = PickupShipping.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_initialization
|
43
|
+
assert_nil @shipping.name
|
44
|
+
assert_nil @shipping.price
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_pickup_shipping_method_behaves_correctly
|
48
|
+
[ :name, :name=, :price, :price= ].each do |sym|
|
49
|
+
assert_respond_to @shipping, sym
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_pickup_shipping_method_setting_attributes_works_correctly
|
54
|
+
@shipping.name = "Shipping Method Name"
|
55
|
+
assert_equal "Shipping Method Name", @shipping.name
|
56
|
+
|
57
|
+
@shipping.price = Money.new(100, "EUR")
|
58
|
+
assert_kind_of Money, @shipping.price
|
59
|
+
assert_equal 100, @shipping.price.cents
|
60
|
+
assert_equal "EUR", @shipping.price.currency.iso_code
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_pickup_shipping_method_price_is_validated
|
64
|
+
# Test that PickupShippingMethod checks for its price attribute responding
|
65
|
+
# to cents and currency.
|
66
|
+
assert_raises(RuntimeError) { @shipping.price = nil }
|
67
|
+
assert_raises(RuntimeError) { @shipping.price = 10 }
|
68
|
+
assert_raises(RuntimeError) { @shipping.price = "str" }
|
69
|
+
end
|
70
|
+
end
|