ruby-ecomm-client 1.1.0 → 1.7.0
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.
- checksums.yaml +15 -0
- data/.ruby-version +1 -1
- data/Gemfile +1 -0
- data/README.md +10 -0
- data/fixtures/vcr_cassettes/account_info/default.yml +49 -34
- data/fixtures/vcr_cassettes/account_info/unknown/resource_id.yml +42 -34
- data/fixtures/vcr_cassettes/account_info/unknown/resource_type.yml +42 -34
- data/fixtures/vcr_cassettes/account_info/unknown/source_tree_id.yml +42 -34
- data/fixtures/vcr_cassettes/express_checkout/configured.yml +39 -31
- data/fixtures/vcr_cassettes/express_checkout/unknown.yml +39 -31
- data/fixtures/vcr_cassettes/request_change/express/downgrade/default.yml +46 -36
- data/fixtures/vcr_cassettes/request_change/express/downgrade/noop.yml +55 -34
- data/fixtures/vcr_cassettes/request_change/express/downgrade/unknown/resource_id.yml +46 -34
- data/fixtures/vcr_cassettes/request_change/express/downgrade/unknown/resource_type.yml +47 -34
- data/fixtures/vcr_cassettes/request_change/express/downgrade/unknown/target_tree_id.yml +46 -34
- data/fixtures/vcr_cassettes/request_change/express/relay/default.yml +48 -0
- data/fixtures/vcr_cassettes/request_change/express/upgrade/default.yml +55 -36
- data/fixtures/vcr_cassettes/request_change/express/upgrade/noop.yml +46 -34
- data/fixtures/vcr_cassettes/request_change/express/upgrade/unknown/resource_id.yml +46 -34
- data/fixtures/vcr_cassettes/request_change/express/upgrade/unknown/resource_type.yml +47 -34
- data/fixtures/vcr_cassettes/request_change/express/upgrade/unknown/target_tree_id.yml +46 -34
- data/fixtures/vcr_cassettes/request_change/manager/downgrade/default.yml +43 -34
- data/fixtures/vcr_cassettes/request_change/manager/downgrade/noop.yml +43 -34
- data/fixtures/vcr_cassettes/request_change/manager/downgrade/unknown/resource_id.yml +43 -34
- data/fixtures/vcr_cassettes/request_change/manager/downgrade/unknown/resource_type.yml +43 -34
- data/fixtures/vcr_cassettes/request_change/manager/downgrade/unknown/target_tree_id.yml +43 -34
- data/fixtures/vcr_cassettes/request_change/manager/relay/default.yml +100 -0
- data/fixtures/vcr_cassettes/request_change/manager/upgrade/default.yml +43 -34
- data/fixtures/vcr_cassettes/request_change/manager/upgrade/noop.yml +43 -34
- data/fixtures/vcr_cassettes/request_change/manager/upgrade/unknown/resource_id.yml +43 -34
- data/fixtures/vcr_cassettes/request_change/manager/upgrade/unknown/resource_type.yml +43 -34
- data/fixtures/vcr_cassettes/request_change/manager/upgrade/unknown/target_tree_id.yml +43 -34
- data/fixtures/vcr_cassettes/transitions/default/unknown/source_tree_id.yml +42 -34
- data/fixtures/vcr_cassettes/transitions/many.yml +49 -34
- data/fixtures/vcr_cassettes/transitions/one.yml +49 -34
- data/lib/ruby-ecomm-client.rb +13 -1
- data/lib/ruby-ecomm-client/client.rb +19 -148
- data/lib/ruby-ecomm-client/config.rb +25 -0
- data/lib/ruby-ecomm-client/service_base.rb +55 -0
- data/lib/ruby-ecomm-client/service_manager.rb +75 -0
- data/lib/ruby-ecomm-client/service_profile.rb +30 -0
- data/lib/ruby-ecomm-client/service_purchase.rb +79 -0
- data/lib/ruby-ecomm-client/util.rb +16 -0
- data/lib/ruby-ecomm-client/version.rb +1 -1
- data/ruby-ecomm-client.gemspec +2 -1
- data/script/bootstrap +68 -0
- data/script/cibuild +4 -5
- data/spec/ruby-ecomm-client/client_spec.rb +32 -339
- data/spec/ruby-ecomm-client/config_spec.rb +56 -0
- data/spec/ruby-ecomm-client/service_base_spec.rb +119 -0
- data/spec/ruby-ecomm-client/service_manager_spec.rb +285 -0
- data/spec/ruby-ecomm-client/service_profile_spec.rb +33 -0
- data/spec/ruby-ecomm-client/service_purchase_spec.rb +160 -0
- data/spec/ruby-ecomm-client/util_spec.rb +66 -0
- data/spec/spec_helper.rb +10 -0
- metadata +160 -152
- data/lib/ruby-ecomm-client/converter.rb +0 -45
- data/spec/ruby-ecomm-client/converter_spec.rb +0 -96
@@ -0,0 +1,75 @@
|
|
1
|
+
module RubyEcommClient
|
2
|
+
class ServiceManager < ServiceBase
|
3
|
+
ENDPOINTS_MANAGER = {
|
4
|
+
:development => 'http://bonsai.dev.glbt1.gdg/Bonsai/BonsaiManager/Service.asmx',
|
5
|
+
:production => 'http://bonsai.prod.phx3.gdg/Bonsai/BonsaiManager/Service.asmx',
|
6
|
+
:qa => 'http://bonsai.test.glbt1.gdg/Bonsai/BonsaiManager/Service.asmx',
|
7
|
+
:test => 'http://bonsai.dev.glbt1.gdg/Bonsai/BonsaiManager/Service.asmx'
|
8
|
+
}
|
9
|
+
|
10
|
+
WSDL_MANAGER = 'manager.wsdl'
|
11
|
+
|
12
|
+
def account_info(source_tree_id = 0)
|
13
|
+
result = client_manager.call(:get_account_xml, :message => generate_request_account_hash(source_tree_id))
|
14
|
+
response = convert_response(result.body[:get_account_xml_response])
|
15
|
+
if response[:result_code] == 0
|
16
|
+
response[:account_xml][:bonsai][:bonsai]
|
17
|
+
else
|
18
|
+
raise RubyEcommError.new(response[:result_code])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def transitions(source_tree_id = 0)
|
23
|
+
transitions = account_info(source_tree_id)[:tree][:transition]
|
24
|
+
transitions.is_a?(Array) ? transitions : [transitions]
|
25
|
+
end
|
26
|
+
|
27
|
+
def find_transition(transitions, target_pfid)
|
28
|
+
raise ArgumentError.new('transitions must be specified') if blank?(transitions)
|
29
|
+
raise ArgumentError.new('target_pfid must be specified') if blank?(target_pfid)
|
30
|
+
|
31
|
+
transitions = transitions.is_a?(Array) ? transitions : [transitions]
|
32
|
+
transitions.find do |transition|
|
33
|
+
transition[:product_id].to_s == target_pfid.to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def request_change_via_manager(target_tree_id)
|
38
|
+
raise ArgumentError.new('target_tree_id must be specified') if blank?(target_tree_id)
|
39
|
+
|
40
|
+
request_hash = generate_request_change_hash
|
41
|
+
request_hash['AccountChangeXml'] = %W(
|
42
|
+
<ClientChange
|
43
|
+
TreeID='#{target_tree_id}'
|
44
|
+
ShopperID='#{config_client.shopper_id}'/>
|
45
|
+
).join(' ')
|
46
|
+
|
47
|
+
result = client_manager.call(:change_account_request, :message => request_hash)
|
48
|
+
response = convert_response(result.body[:change_account_request_response])
|
49
|
+
if response[:result_code] == 0
|
50
|
+
{
|
51
|
+
:used_express_checkout => false,
|
52
|
+
:request_result => response[:change_account_request_result]
|
53
|
+
}
|
54
|
+
else
|
55
|
+
raise RubyEcommError.new(response[:result_code], response[:change_account_request_result])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def client_manager
|
62
|
+
@client_manager ||= create_client do |globals|
|
63
|
+
globals.wsdl "#{wsdl_path}#{WSDL_MANAGER}"
|
64
|
+
globals.endpoint ENDPOINTS_MANAGER[environment]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def generate_request_account_hash(source_tree_id = 0)
|
69
|
+
generate_request_hash.merge({
|
70
|
+
'TreeID' => source_tree_id,
|
71
|
+
'PrivateLabelID' => 1
|
72
|
+
})
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RubyEcommClient
|
2
|
+
class ServiceProfile < ServiceBase
|
3
|
+
ENDPOINTS_PROFILE = {
|
4
|
+
:development => 'http://gdcomm.dev.glbt1.gdg/WSgdInstantPurchasePublic/Service.asmx',
|
5
|
+
:production => 'https://gdcomm.prod.phx3.gdg/WSgdInstantPurchasePublic/Service.asmx',
|
6
|
+
:qa => 'http://gdcomm.test.glbt1.gdg/WSgdInstantPurchasePublic/Service.asmx',
|
7
|
+
:test => 'http://gdcomm.dev.glbt1.gdg/WSgdInstantPurchasePublic/Service.asmx'
|
8
|
+
}
|
9
|
+
|
10
|
+
WSDL_PROFILE = 'profile.wsdl'
|
11
|
+
|
12
|
+
def express_checkout?
|
13
|
+
result = client_profile.call(:shopper_has_instant_purchase_payment, :message => {
|
14
|
+
'sShopperID' => config_client.shopper_id
|
15
|
+
})
|
16
|
+
response = convert_value(result.body[:shopper_has_instant_purchase_payment_response])
|
17
|
+
response[:b_has_instant_purchase_payment]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def client_profile
|
23
|
+
@client_profile ||= create_client do |globals|
|
24
|
+
globals.wsdl "#{wsdl_path}#{WSDL_PROFILE}"
|
25
|
+
globals.endpoint ENDPOINTS_PROFILE[environment]
|
26
|
+
globals.namespace 'http://tempuri.org/'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module RubyEcommClient
|
2
|
+
class ServicePurchase < ServiceBase
|
3
|
+
ENDPOINTS_PURCHASE = {
|
4
|
+
:development => 'https://bonsaipurchase.dev.glbt1.gdg/BonsaiPurchase/Service.asmx',
|
5
|
+
:production => 'https://bonsaipurchase.prod.phx3.gdg/BonsaiPurchase/Service.asmx',
|
6
|
+
:qa => 'https://bonsaipurchase.test.glbt1.gdg/BonsaiPurchase/Service.asmx',
|
7
|
+
:test => 'https://bonsaipurchase.dev.glbt1.gdg/BonsaiPurchase/Service.asmx'
|
8
|
+
}
|
9
|
+
|
10
|
+
HOST_NAME = `hostname`.chomp
|
11
|
+
|
12
|
+
WSDL_PURCHASE = 'purchase.wsdl'
|
13
|
+
|
14
|
+
def request_change(target_tree_id, client_ip = '127.0.0.1')
|
15
|
+
raise ArgumentError.new('target_tree_id must be specified') if blank?(target_tree_id)
|
16
|
+
|
17
|
+
if config_client.express_checkout?
|
18
|
+
request_change_via_express(target_tree_id, client_ip)
|
19
|
+
else
|
20
|
+
config_client.request_change_via_manager(target_tree_id)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def request_change_via_express(target_tree_id, client_ip = '127.0.0.1')
|
25
|
+
raise ArgumentError.new('target_tree_id must be specified') if blank?(target_tree_id)
|
26
|
+
config_global.validate
|
27
|
+
|
28
|
+
request_hash = generate_request_change_hash
|
29
|
+
request_hash['AccountPurchaseChangeXml'] = %W(
|
30
|
+
<ClientChange
|
31
|
+
TreeID='#{target_tree_id}'
|
32
|
+
ShopperID='#{config_client.shopper_id}'
|
33
|
+
TransactionCurrency='USD'
|
34
|
+
RequestingApp='#{config_global.requesting_app}'
|
35
|
+
RequestingAppHost='#{HOST_NAME}'
|
36
|
+
ClientAddr='#{client_ip}'
|
37
|
+
EnteredBy='customer'
|
38
|
+
OrderSource='Online'
|
39
|
+
RedirectToBasket='false'
|
40
|
+
EstimateOnly='false'
|
41
|
+
SendConfirmEmail='false'/>
|
42
|
+
).join(' ')
|
43
|
+
|
44
|
+
result = client_purchase.call(:purchase_change_account_request, :message => request_hash)
|
45
|
+
response = convert_response(result.body[:purchase_change_account_request_response])
|
46
|
+
if response[:result_code] == 0
|
47
|
+
{
|
48
|
+
:used_express_checkout => true,
|
49
|
+
:request_result => response[:purchase_change_account_request_result],
|
50
|
+
:error => response[:error],
|
51
|
+
:order_xml => response[:order_xml]
|
52
|
+
}
|
53
|
+
else
|
54
|
+
raise RubyEcommError.new(response[:result_code], response[:change_account_request_result])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def client_purchase
|
61
|
+
@client_purchase ||= create_client do |globals|
|
62
|
+
globals.wsdl "#{wsdl_path}#{WSDL_PURCHASE}"
|
63
|
+
globals.endpoint ENDPOINTS_PURCHASE[environment]
|
64
|
+
|
65
|
+
globals.ssl_verify_mode :none
|
66
|
+
# Must force explicit value to avoid ECONNRESET on P3 servers
|
67
|
+
globals.ssl_version :TLSv1
|
68
|
+
if !blank?(config_global.ssl_cert_file) && File.exists?(config_global.ssl_cert_file)
|
69
|
+
globals.ssl_cert_file config_global.ssl_cert_file
|
70
|
+
end
|
71
|
+
if !blank?(config_global.ssl_cert_key_file) && File.exists?(config_global.ssl_cert_key_file)
|
72
|
+
globals.ssl_cert_key_file config_global.ssl_cert_key_file
|
73
|
+
end
|
74
|
+
globals.ssl_cert_content config_global.ssl_cert_content unless blank?(config_global.ssl_cert_content)
|
75
|
+
globals.ssl_cert_key_content config_global.ssl_cert_key_content unless blank?(config_global.ssl_cert_key_content)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Utils
|
2
|
+
def self.included(base)
|
3
|
+
base.send(:include, Methods)
|
4
|
+
base.extend Methods
|
5
|
+
end
|
6
|
+
|
7
|
+
module Methods
|
8
|
+
def blank?(value)
|
9
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?) || value.to_s.strip == ''
|
10
|
+
end
|
11
|
+
|
12
|
+
def environment
|
13
|
+
((defined?(Rails) ? Rails.env : ENV['RAILS_ENV']) || 'development').to_sym
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/ruby-ecomm-client.gemspec
CHANGED
@@ -21,10 +21,11 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_development_dependency "ci_reporter"
|
22
22
|
gem.add_development_dependency 'fakeweb'
|
23
23
|
gem.add_development_dependency "gemfury"
|
24
|
-
gem.add_development_dependency "
|
24
|
+
gem.add_development_dependency "simplecov"
|
25
25
|
gem.add_development_dependency "rspec"
|
26
26
|
gem.add_development_dependency 'vcr'
|
27
27
|
|
28
|
+
gem.add_runtime_dependency "freddy"
|
28
29
|
gem.add_runtime_dependency "nokogiri", "1.5.10"
|
29
30
|
gem.add_runtime_dependency "savon"
|
30
31
|
end
|
data/script/bootstrap
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
set -e
|
3
|
+
|
4
|
+
main()
|
5
|
+
{
|
6
|
+
has_ruby_version_manager
|
7
|
+
install_correct_version_of_ruby
|
8
|
+
install_bundler
|
9
|
+
|
10
|
+
install_bundle
|
11
|
+
}
|
12
|
+
|
13
|
+
log()
|
14
|
+
{
|
15
|
+
local blue="\033[0;34m"
|
16
|
+
local reset="\033[0m"
|
17
|
+
printf "$blue[bootstrap] %s$reset\n" "$1"
|
18
|
+
}
|
19
|
+
|
20
|
+
has_bundle_installed()
|
21
|
+
{
|
22
|
+
bundle check > /dev/null 2>&1
|
23
|
+
}
|
24
|
+
|
25
|
+
install_bundle()
|
26
|
+
{
|
27
|
+
if ! has_bundle_installed; then
|
28
|
+
log "Installing bundle"
|
29
|
+
bundle install --path='vendor' --binstubs='.bin' --clean
|
30
|
+
fi
|
31
|
+
}
|
32
|
+
|
33
|
+
has_ruby_version_manager()
|
34
|
+
{
|
35
|
+
command -v rbenv > /dev/null 2>&1 || exit 2;
|
36
|
+
}
|
37
|
+
|
38
|
+
has_correct_version_of_ruby()
|
39
|
+
{
|
40
|
+
rbenv versions | grep $(cat .ruby-version) &>/dev/null
|
41
|
+
}
|
42
|
+
|
43
|
+
install_correct_version_of_ruby()
|
44
|
+
{
|
45
|
+
if ! has_correct_version_of_ruby; then
|
46
|
+
version="$(cat .ruby-version)"
|
47
|
+
log "Installing ruby $version"
|
48
|
+
rbenv install $version
|
49
|
+
rbenv rehash
|
50
|
+
fi
|
51
|
+
}
|
52
|
+
|
53
|
+
has_bundler_installed()
|
54
|
+
{
|
55
|
+
# exits non-zero if bundle is not a command in the current Ruby version.
|
56
|
+
rbenv which bundle &>/dev/null
|
57
|
+
}
|
58
|
+
|
59
|
+
install_bundler()
|
60
|
+
{
|
61
|
+
if ! has_bundler_installed; then
|
62
|
+
log "Installing bundler"
|
63
|
+
gem install bundler --no-ri --no-rdoc
|
64
|
+
rbenv rehash
|
65
|
+
fi
|
66
|
+
}
|
67
|
+
|
68
|
+
main
|
data/script/cibuild
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
|
3
|
-
|
4
|
-
[
|
3
|
+
echo ""
|
4
|
+
echo "[$(date)] Bootstrapping"
|
5
|
+
script/bootstrap
|
5
6
|
|
6
7
|
set -e
|
7
8
|
|
8
|
-
bundle
|
9
|
-
|
10
|
-
bundle exec rake
|
9
|
+
bundle exec rake spec
|
@@ -4,13 +4,13 @@ describe RubyEcommClient::Client do
|
|
4
4
|
before do
|
5
5
|
use_test = [:qa, :production].include?(RubyEcommClient::Client.environment)
|
6
6
|
|
7
|
-
@shopper_id = use_test ? '
|
8
|
-
@low_tree_id = '
|
9
|
-
@downgrade_tree_id = '
|
10
|
-
@current_tree_id = '
|
11
|
-
@upgrade_tree_id = '
|
7
|
+
@shopper_id = use_test ? '261639' : '923518'
|
8
|
+
@low_tree_id = '2402'
|
9
|
+
@downgrade_tree_id = '2402'
|
10
|
+
@current_tree_id = '2410'
|
11
|
+
@upgrade_tree_id = '2418'
|
12
12
|
@resource_type = 'outright'
|
13
|
-
@resource_id = use_test ? '
|
13
|
+
@resource_id = use_test ? 'd5e2ead3-c1c4-11e3-9ea5-005056953ce3' : 'b6be6fd0-c1a5-11e3-8e42-0050569575d8'
|
14
14
|
|
15
15
|
@client = RubyEcommClient::Client.new(@shopper_id, @resource_type, @resource_id)
|
16
16
|
end
|
@@ -53,366 +53,59 @@ describe RubyEcommClient::Client do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
context '#environment' do
|
57
|
-
it 'not be nil' do
|
58
|
-
RubyEcommClient::Client.environment.should_not be_nil
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'not be blank' do
|
62
|
-
RubyEcommClient::Client.environment.should_not eq('')
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'honor ENV' do
|
66
|
-
old_env = ENV['RAILS_ENV']
|
67
|
-
ENV['RAILS_ENV'] = 'production'
|
68
|
-
RubyEcommClient::Client.environment.should eq(:production)
|
69
|
-
ENV['RAILS_ENV'] = old_env
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
56
|
context '#express_checkout?' do
|
74
|
-
it '
|
75
|
-
|
76
|
-
@client.shopper_id = '101010'
|
77
|
-
@client.express_checkout?.should eq(false)
|
78
|
-
end
|
79
|
-
end
|
57
|
+
it 'must relay' do
|
58
|
+
RubyEcommClient::ServiceProfile.any_instance.should_receive(:express_checkout?).once
|
80
59
|
|
81
|
-
|
82
|
-
VCR.use_cassette('express_checkout/configured') do
|
83
|
-
@client.express_checkout?.should eq(true)
|
84
|
-
end
|
60
|
+
@client.express_checkout?
|
85
61
|
end
|
86
62
|
end
|
87
63
|
|
88
64
|
context '#account_info' do
|
89
|
-
|
90
|
-
|
91
|
-
@account_info = @client.account_info
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'raise RubyEcommError for unknown resource_type' do
|
96
|
-
VCR.use_cassette('account_info/unknown/resource_type') do
|
97
|
-
@client.resource_type = 'flugel'
|
98
|
-
expect { @client.account_info }.to raise_error(RubyEcommError){|e| e.result_code.should eq(-100) }
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'raise RubyEcommError for unknown resource_id' do
|
103
|
-
VCR.use_cassette('account_info/unknown/resource_id') do
|
104
|
-
@client.resource_id = 'unknown'
|
105
|
-
expect { @client.account_info }.to raise_error(RubyEcommError){|e| e.result_code.should eq(-304) }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'raise RubyEcommError for unknown source_tree_id' do
|
110
|
-
VCR.use_cassette('account_info/unknown/source_tree_id') do
|
111
|
-
expect { @client.account_info(90909) }.to raise_error(RubyEcommError){|e| e.result_code.should eq(-999) }
|
112
|
-
end
|
113
|
-
end
|
65
|
+
it 'must relay' do
|
66
|
+
RubyEcommClient::ServiceManager.any_instance.should_receive(:account_info).with(1).once
|
114
67
|
|
115
|
-
|
116
|
-
@account_info.class.should eq(Hash)
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'include product_id' do
|
120
|
-
@account_info[:product_id].class.should eq(Fixnum)
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'include tree_id' do
|
124
|
-
@account_info[:tree_id].class.should eq(Fixnum)
|
125
|
-
@account_info[:tree_id].should eq(@current_tree_id.to_i)
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'include is_free' do
|
129
|
-
@account_info[:is_free].class.should eq(FalseClass)
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'include tree Hash' do
|
133
|
-
@account_info[:tree].class.should eq(Hash)
|
68
|
+
@client.account_info(1)
|
134
69
|
end
|
135
70
|
end
|
136
71
|
|
137
72
|
context '#transitions' do
|
138
|
-
it '
|
139
|
-
|
140
|
-
expect { @client.transitions(87563) }.to raise_error(RubyEcommError){|e| e.result_code.should eq(-999) }
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
73
|
+
it 'must relay' do
|
74
|
+
RubyEcommClient::ServiceManager.any_instance.should_receive(:transitions).with(1).once
|
144
75
|
|
145
|
-
|
146
|
-
before do
|
147
|
-
VCR.use_cassette('transitions/one') do
|
148
|
-
@transitions = @client.transitions(@low_tree_id)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'return an Array' do
|
153
|
-
@transitions.class.should eq(Array)
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'return multiple' do
|
157
|
-
@transitions.size.should eq(1)
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'return containing Hashes' do
|
161
|
-
@transitions.first.class.should eq(Hash)
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'return containing Hashes with product_id' do
|
165
|
-
@transitions.first[:product_id].class.should eq(Fixnum)
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'return containing Hashes with tree_id' do
|
169
|
-
@transitions.first[:tree_id].class.should eq(Fixnum)
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'return containing Hashes with node_name' do
|
173
|
-
@transitions.first[:node_name].class.should eq(String)
|
76
|
+
@client.transitions(1)
|
174
77
|
end
|
175
78
|
end
|
176
79
|
|
177
|
-
context '#
|
178
|
-
|
179
|
-
|
180
|
-
@transitions = @client.transitions(@current_tree_id)
|
181
|
-
end
|
182
|
-
end
|
80
|
+
context '#find_transition' do
|
81
|
+
it 'must relay' do
|
82
|
+
RubyEcommClient::ServiceManager.any_instance.should_receive(:find_transition).with([], 1).once
|
183
83
|
|
184
|
-
|
185
|
-
@transitions.class.should eq(Array)
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'return multiple' do
|
189
|
-
@transitions.size.should eq(6)
|
84
|
+
@client.find_transition([], 1)
|
190
85
|
end
|
86
|
+
end
|
191
87
|
|
192
|
-
|
193
|
-
|
194
|
-
|
88
|
+
context '#request_change_via_manager' do
|
89
|
+
it 'must relay' do
|
90
|
+
RubyEcommClient::ServiceManager.any_instance.should_receive(:request_change_via_manager).with(1).once
|
195
91
|
|
196
|
-
|
197
|
-
@transitions.first[:product_id].class.should eq(Fixnum)
|
92
|
+
@client.request_change_via_manager(1)
|
198
93
|
end
|
94
|
+
end
|
199
95
|
|
200
|
-
|
201
|
-
|
202
|
-
|
96
|
+
context '#request_change_via_express' do
|
97
|
+
it 'must relay' do
|
98
|
+
RubyEcommClient::ServicePurchase.any_instance.should_receive(:request_change_via_express).with(1, '10.0.1.1').once
|
203
99
|
|
204
|
-
|
205
|
-
@transitions.first[:node_name].class.should eq(String)
|
100
|
+
@client.request_change_via_express(1, '10.0.1.1')
|
206
101
|
end
|
207
102
|
end
|
208
103
|
|
209
104
|
context '#request_change' do
|
210
|
-
|
211
|
-
|
212
|
-
@client.stub(:express_checkout?).and_return(true)
|
213
|
-
end
|
214
|
-
|
215
|
-
context 'upgrade' do
|
216
|
-
before do
|
217
|
-
VCR.use_cassette('request_change/express/upgrade/default') do
|
218
|
-
@result = @client.request_change(@upgrade_tree_id)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
it 'require target_tree_id non-nil' do
|
223
|
-
expect { @client.request_change(nil) }.to raise_error(ArgumentError)
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'require target_tree_id non-blank' do
|
227
|
-
expect { @client.request_change('') }.to raise_error(ArgumentError)
|
228
|
-
end
|
229
|
-
|
230
|
-
it 'raise RubyEcommError for unknown resource_type' do
|
231
|
-
VCR.use_cassette('request_change/express/upgrade/unknown/resource_type') do
|
232
|
-
@client.resource_type = 'flugel'
|
233
|
-
expect { @client.request_change(@upgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-100) }
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
it 'raise RubyEcommError for unknown resource_id' do
|
238
|
-
VCR.use_cassette('request_change/express/upgrade/unknown/resource_id') do
|
239
|
-
@client.resource_id = 'unknown'
|
240
|
-
expect { @client.request_change(@upgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-304) }
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
it 'raise RubyEcommError for unknown target_tree_id' do
|
245
|
-
VCR.use_cassette('request_change/express/upgrade/unknown/target_tree_id') do
|
246
|
-
expect { @client.request_change(73223) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-999) }
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
it "return no-op request_result for transition to same" do
|
251
|
-
VCR.use_cassette('request_change/express/upgrade/noop') do
|
252
|
-
result = @client.request_change(@current_tree_id)
|
253
|
-
result[:request_result].should eq(1)
|
254
|
-
result[:used_express_checkout].should eq(true)
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
it "return success request_result for valid transition" do
|
259
|
-
@result[:request_result].should eq(0)
|
260
|
-
@result[:used_express_checkout].should eq(true)
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
context 'downgrade' do
|
265
|
-
before do
|
266
|
-
VCR.use_cassette('request_change/express/downgrade/default') do
|
267
|
-
@result = @client.request_change(@downgrade_tree_id)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
it 'require target_tree_id non-nil' do
|
272
|
-
expect { @client.request_change(nil) }.to raise_error(ArgumentError)
|
273
|
-
end
|
274
|
-
|
275
|
-
it 'require target_tree_id non-blank' do
|
276
|
-
expect { @client.request_change('') }.to raise_error(ArgumentError)
|
277
|
-
end
|
278
|
-
|
279
|
-
it 'raise RubyEcommError for unknown resource_type' do
|
280
|
-
VCR.use_cassette('request_change/express/downgrade/unknown/resource_type') do
|
281
|
-
@client.resource_type = 'flugel'
|
282
|
-
expect { @client.request_change(@downgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-100) }
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
it 'raise RubyEcommError for unknown resource_id' do
|
287
|
-
VCR.use_cassette('request_change/express/downgrade/unknown/resource_id') do
|
288
|
-
@client.resource_id = 'unknown'
|
289
|
-
expect { @client.request_change(@downgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-304) }
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
it 'raise RubyEcommError for unknown target_tree_id' do
|
294
|
-
VCR.use_cassette('request_change/express/downgrade/unknown/target_tree_id') do
|
295
|
-
expect { @client.request_change(73541) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-999) }
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
it "return no-op request_result for transition to same" do
|
300
|
-
VCR.use_cassette('request_change/express/downgrade/noop') do
|
301
|
-
result = @client.request_change(@current_tree_id)
|
302
|
-
result[:request_result].should eq(1)
|
303
|
-
result[:used_express_checkout].should eq(true)
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
it "return success request_result for valid transition" do
|
308
|
-
@result[:request_result].should eq(0)
|
309
|
-
@result[:used_express_checkout].should eq(true)
|
310
|
-
end
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
context 'via manager' do
|
315
|
-
before do
|
316
|
-
@client.stub(:express_checkout?).and_return(false)
|
317
|
-
end
|
318
|
-
|
319
|
-
context 'upgrade' do
|
320
|
-
before do
|
321
|
-
VCR.use_cassette('request_change/manager/upgrade/default') do
|
322
|
-
@result = @client.request_change(@upgrade_tree_id)
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
it 'require target_tree_id non-nil' do
|
327
|
-
expect { @client.request_change(nil) }.to raise_error(ArgumentError)
|
328
|
-
end
|
329
|
-
|
330
|
-
it 'require target_tree_id non-blank' do
|
331
|
-
expect { @client.request_change('') }.to raise_error(ArgumentError)
|
332
|
-
end
|
333
|
-
|
334
|
-
it 'raise RubyEcommError for unknown resource_type' do
|
335
|
-
VCR.use_cassette('request_change/manager/upgrade/unknown/resource_type') do
|
336
|
-
@client.resource_type = 'flugel'
|
337
|
-
expect { @client.request_change(@upgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-100) }
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
it 'raise RubyEcommError for unknown resource_id' do
|
342
|
-
VCR.use_cassette('request_change/manager/upgrade/unknown/resource_id') do
|
343
|
-
@client.resource_id = 'unknown'
|
344
|
-
expect { @client.request_change(@upgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-304) }
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
it 'raise RubyEcommError for unknown target_tree_id' do
|
349
|
-
VCR.use_cassette('request_change/manager/upgrade/unknown/target_tree_id') do
|
350
|
-
expect { @client.request_change(73223) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-999) }
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
it "return no-op request_result for transition to same" do
|
355
|
-
VCR.use_cassette('request_change/manager/upgrade/noop') do
|
356
|
-
result = @client.request_change(@current_tree_id)
|
357
|
-
result[:request_result].should eq(1)
|
358
|
-
result[:used_express_checkout].should eq(false)
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
it "return success request_result for valid transition" do
|
363
|
-
@result[:request_result].should eq(2)
|
364
|
-
@result[:used_express_checkout].should eq(false)
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
context 'downgrade' do
|
369
|
-
before do
|
370
|
-
VCR.use_cassette('request_change/manager/downgrade/default') do
|
371
|
-
@result = @client.request_change(@downgrade_tree_id)
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
it 'require target_tree_id non-nil' do
|
376
|
-
expect { @client.request_change(nil) }.to raise_error(ArgumentError)
|
377
|
-
end
|
378
|
-
|
379
|
-
it 'require target_tree_id non-blank' do
|
380
|
-
expect { @client.request_change('') }.to raise_error(ArgumentError)
|
381
|
-
end
|
382
|
-
|
383
|
-
it 'raise RubyEcommError for unknown resource_type' do
|
384
|
-
VCR.use_cassette('request_change/manager/downgrade/unknown/resource_type') do
|
385
|
-
@client.resource_type = 'flugel'
|
386
|
-
expect { @client.request_change(@downgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-100) }
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
it 'raise RubyEcommError for unknown resource_id' do
|
391
|
-
VCR.use_cassette('request_change/manager/downgrade/unknown/resource_id') do
|
392
|
-
@client.resource_id = 'unknown'
|
393
|
-
expect { @client.request_change(@downgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-304) }
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
it 'raise RubyEcommError for unknown target_tree_id' do
|
398
|
-
VCR.use_cassette('request_change/manager/downgrade/unknown/target_tree_id') do
|
399
|
-
expect { @client.request_change(73541) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-999) }
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
it "return no-op request_result for transition to same" do
|
404
|
-
VCR.use_cassette('request_change/manager/downgrade/noop') do
|
405
|
-
result = @client.request_change(@current_tree_id)
|
406
|
-
result[:request_result].should eq(1)
|
407
|
-
result[:used_express_checkout].should eq(false)
|
408
|
-
end
|
409
|
-
end
|
105
|
+
it 'must relay' do
|
106
|
+
RubyEcommClient::ServicePurchase.any_instance.should_receive(:request_change).with(1, '10.0.1.1').once
|
410
107
|
|
411
|
-
|
412
|
-
@result[:request_result].should eq(2)
|
413
|
-
@result[:used_express_checkout].should eq(false)
|
414
|
-
end
|
415
|
-
end
|
108
|
+
@client.request_change(1, '10.0.1.1')
|
416
109
|
end
|
417
110
|
end
|
418
111
|
end
|