ruby-ecomm-client 1.1.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +15 -0
  2. data/.ruby-version +1 -1
  3. data/Gemfile +1 -0
  4. data/README.md +10 -0
  5. data/fixtures/vcr_cassettes/account_info/default.yml +49 -34
  6. data/fixtures/vcr_cassettes/account_info/unknown/resource_id.yml +42 -34
  7. data/fixtures/vcr_cassettes/account_info/unknown/resource_type.yml +42 -34
  8. data/fixtures/vcr_cassettes/account_info/unknown/source_tree_id.yml +42 -34
  9. data/fixtures/vcr_cassettes/express_checkout/configured.yml +39 -31
  10. data/fixtures/vcr_cassettes/express_checkout/unknown.yml +39 -31
  11. data/fixtures/vcr_cassettes/request_change/express/downgrade/default.yml +46 -36
  12. data/fixtures/vcr_cassettes/request_change/express/downgrade/noop.yml +55 -34
  13. data/fixtures/vcr_cassettes/request_change/express/downgrade/unknown/resource_id.yml +46 -34
  14. data/fixtures/vcr_cassettes/request_change/express/downgrade/unknown/resource_type.yml +47 -34
  15. data/fixtures/vcr_cassettes/request_change/express/downgrade/unknown/target_tree_id.yml +46 -34
  16. data/fixtures/vcr_cassettes/request_change/express/relay/default.yml +48 -0
  17. data/fixtures/vcr_cassettes/request_change/express/upgrade/default.yml +55 -36
  18. data/fixtures/vcr_cassettes/request_change/express/upgrade/noop.yml +46 -34
  19. data/fixtures/vcr_cassettes/request_change/express/upgrade/unknown/resource_id.yml +46 -34
  20. data/fixtures/vcr_cassettes/request_change/express/upgrade/unknown/resource_type.yml +47 -34
  21. data/fixtures/vcr_cassettes/request_change/express/upgrade/unknown/target_tree_id.yml +46 -34
  22. data/fixtures/vcr_cassettes/request_change/manager/downgrade/default.yml +43 -34
  23. data/fixtures/vcr_cassettes/request_change/manager/downgrade/noop.yml +43 -34
  24. data/fixtures/vcr_cassettes/request_change/manager/downgrade/unknown/resource_id.yml +43 -34
  25. data/fixtures/vcr_cassettes/request_change/manager/downgrade/unknown/resource_type.yml +43 -34
  26. data/fixtures/vcr_cassettes/request_change/manager/downgrade/unknown/target_tree_id.yml +43 -34
  27. data/fixtures/vcr_cassettes/request_change/manager/relay/default.yml +100 -0
  28. data/fixtures/vcr_cassettes/request_change/manager/upgrade/default.yml +43 -34
  29. data/fixtures/vcr_cassettes/request_change/manager/upgrade/noop.yml +43 -34
  30. data/fixtures/vcr_cassettes/request_change/manager/upgrade/unknown/resource_id.yml +43 -34
  31. data/fixtures/vcr_cassettes/request_change/manager/upgrade/unknown/resource_type.yml +43 -34
  32. data/fixtures/vcr_cassettes/request_change/manager/upgrade/unknown/target_tree_id.yml +43 -34
  33. data/fixtures/vcr_cassettes/transitions/default/unknown/source_tree_id.yml +42 -34
  34. data/fixtures/vcr_cassettes/transitions/many.yml +49 -34
  35. data/fixtures/vcr_cassettes/transitions/one.yml +49 -34
  36. data/lib/ruby-ecomm-client.rb +13 -1
  37. data/lib/ruby-ecomm-client/client.rb +19 -148
  38. data/lib/ruby-ecomm-client/config.rb +25 -0
  39. data/lib/ruby-ecomm-client/service_base.rb +55 -0
  40. data/lib/ruby-ecomm-client/service_manager.rb +75 -0
  41. data/lib/ruby-ecomm-client/service_profile.rb +30 -0
  42. data/lib/ruby-ecomm-client/service_purchase.rb +79 -0
  43. data/lib/ruby-ecomm-client/util.rb +16 -0
  44. data/lib/ruby-ecomm-client/version.rb +1 -1
  45. data/ruby-ecomm-client.gemspec +2 -1
  46. data/script/bootstrap +68 -0
  47. data/script/cibuild +4 -5
  48. data/spec/ruby-ecomm-client/client_spec.rb +32 -339
  49. data/spec/ruby-ecomm-client/config_spec.rb +56 -0
  50. data/spec/ruby-ecomm-client/service_base_spec.rb +119 -0
  51. data/spec/ruby-ecomm-client/service_manager_spec.rb +285 -0
  52. data/spec/ruby-ecomm-client/service_profile_spec.rb +33 -0
  53. data/spec/ruby-ecomm-client/service_purchase_spec.rb +160 -0
  54. data/spec/ruby-ecomm-client/util_spec.rb +66 -0
  55. data/spec/spec_helper.rb +10 -0
  56. metadata +160 -152
  57. data/lib/ruby-ecomm-client/converter.rb +0 -45
  58. data/spec/ruby-ecomm-client/converter_spec.rb +0 -96
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ class UtilTarget
4
+ include ::Utils
5
+ end
6
+
7
+ describe RubyEcommClient::Config do
8
+ context '#configure' do
9
+ it 'defaults SSL Cert config' do
10
+ RubyEcommClient.config.requesting_app.should eq('outright')
11
+ RubyEcommClient.config.ssl_cert_file.should eq("config/keys/#{UtilTarget.environment}/client.crt")
12
+ RubyEcommClient.config.ssl_cert_key_file.should eq("config/keys/#{UtilTarget.environment}/client.key")
13
+ end
14
+
15
+ it 'should be invalid by default' do
16
+ expect { RubyEcommClient.config.validate }.not_to raise_error
17
+ end
18
+
19
+ it 'should be valid once requesting_app is specified' do
20
+ config = RubyEcommClient::Config.new
21
+ config.requesting_app = nil
22
+ expect { config.validate }.to raise_error(ArgumentError)
23
+ end
24
+
25
+ it 'supports multiple calls' do
26
+ RubyEcommClient.configure do |config|
27
+ config.ssl_cert_file = 'config/ssl.crt'
28
+ end
29
+
30
+ RubyEcommClient.configure do |config|
31
+ config.ssl_cert_key_file = 'config/ssl.key'
32
+ end
33
+
34
+ RubyEcommClient.config.ssl_cert_file.should eq('config/ssl.crt')
35
+ RubyEcommClient.config.ssl_cert_key_file.should eq('config/ssl.key')
36
+ end
37
+
38
+ it 'supports cert and key content' do
39
+ RubyEcommClient.configure do |config|
40
+ config.ssl_cert_content = 'CertContent'
41
+ end
42
+
43
+ RubyEcommClient.configure do |config|
44
+ config.ssl_cert_key_content = 'CertKeyContent'
45
+ end
46
+
47
+ RubyEcommClient.config.ssl_cert_content.should eq('CertContent')
48
+ RubyEcommClient.config.ssl_cert_key_content.should eq('CertKeyContent')
49
+
50
+ RubyEcommClient.configure do |config|
51
+ config.ssl_cert_content = nil
52
+ config.ssl_cert_key_content = nil
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyEcommClient::ServiceBase do
4
+ before do
5
+ @config_client = RubyEcommClient::Client.new(1, 'any', 'abc')
6
+ @service = RubyEcommClient::ServiceBase.new(@config_client)
7
+ end
8
+
9
+ context '#initialize' do
10
+ it 'require config_client non-nil' do
11
+ expect { RubyEcommClient::ServiceBase.new(nil) }.to raise_error(ArgumentError)
12
+ end
13
+
14
+ it 'set config_client' do
15
+ @service.send(:config_client).should eq(@config_client)
16
+ end
17
+ end
18
+
19
+ context '#global_config' do
20
+ it 'must relay global_config' do
21
+ @service.send(:config_global).should eq(RubyEcommClient.config)
22
+ end
23
+ end
24
+
25
+ context '#wsdl_path' do
26
+ it 'must be specified' do
27
+ @service.send(:wsdl_path).should_not be_nil
28
+ end
29
+
30
+ it 'must exist' do
31
+ File.exist?(@service.send(:wsdl_path)).should eq(true)
32
+ end
33
+ end
34
+
35
+ context '#create_client' do
36
+ before do
37
+ @client = @service.send(:create_client) do |globals|
38
+ globals.endpoint 'http://example.com'
39
+ globals.namespace 'http://v1.example.com'
40
+ end
41
+ end
42
+
43
+ it 'must set the tag converter' do
44
+ @client.globals[:convert_response_tags_to].should eq(Freddy::ResponseConverter::TAG_CONVERTER)
45
+ end
46
+
47
+ it 'must disabled logging' do
48
+ @client.globals[:log].should eq(false)
49
+ end
50
+
51
+ it 'must set namespace' do
52
+ @client.globals[:namespace].should_not be_nil
53
+ end
54
+ end
55
+
56
+ context '#generate_request_hash' do
57
+ before do
58
+ @hash = @service.send(:generate_request_hash)
59
+ end
60
+
61
+ it 'must not be nil' do
62
+ @hash.should_not be_nil
63
+ end
64
+
65
+ it 'must not be empty' do
66
+ @hash.should_not be_empty
67
+ end
68
+
69
+ it 'must set ResourceID' do
70
+ @hash['ResourceID'].should eq(@config_client.resource_id)
71
+ end
72
+
73
+ it 'must set ResourceType' do
74
+ @hash['ResourceType'].should eq(@config_client.resource_type)
75
+ end
76
+
77
+ it 'must set IDType' do
78
+ @hash['IDType'].should eq(RubyEcommClient::ServiceBase::ID_TYPE)
79
+ end
80
+ end
81
+
82
+ context '#generate_request_change_hash' do
83
+ before do
84
+ @hash = @service.send(:generate_request_change_hash)
85
+ end
86
+
87
+ it 'must not be nil' do
88
+ @hash.should_not be_nil
89
+ end
90
+
91
+ it 'must not be empty' do
92
+ @hash.should_not be_empty
93
+ end
94
+
95
+ it 'must set ResourceID' do
96
+ @hash['ResourceID'].should eq(@config_client.resource_id)
97
+ end
98
+
99
+ it 'must set ResourceType' do
100
+ @hash['ResourceType'].should eq(@config_client.resource_type)
101
+ end
102
+
103
+ it 'must set IDType' do
104
+ @hash['IDType'].should eq(RubyEcommClient::ServiceBase::ID_TYPE)
105
+ end
106
+
107
+ it 'must set RenewalPFID' do
108
+ @hash['RenewalPFID'].should eq(0)
109
+ end
110
+
111
+ it 'must set RenewalPeriods' do
112
+ @hash['RenewalPeriods'].should eq(0)
113
+ end
114
+
115
+ it 'must set ItemRequestXml' do
116
+ @hash['ItemRequestXml'].should eq('<itemRequest/>')
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,285 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyEcommClient::ServiceManager do
4
+ before do
5
+ use_test = [:qa, :production].include?(RubyEcommClient::Client.environment)
6
+
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
+ @resource_type = 'outright'
13
+ @resource_id = use_test ? 'd5e2ead3-c1c4-11e3-9ea5-005056953ce3' : 'b6be6fd0-c1a5-11e3-8e42-0050569575d8'
14
+
15
+ @config_client = RubyEcommClient::Client.new(@shopper_id, @resource_type, @resource_id)
16
+ @service = RubyEcommClient::ServiceManager.new(@config_client)
17
+ end
18
+
19
+ context '#account_info' do
20
+ before do
21
+ VCR.use_cassette('account_info/default') do
22
+ @account_info = @service.account_info
23
+ end
24
+ end
25
+
26
+ it 'raise RubyEcommError for unknown resource_type' do
27
+ VCR.use_cassette('account_info/unknown/resource_type') do
28
+ @service.send(:config_client).resource_type = 'flugel'
29
+ expect { @service.account_info }.to raise_error(RubyEcommError){|e| e.result_code.should eq(-100) }
30
+ end
31
+ end
32
+
33
+ it 'raise RubyEcommError for unknown resource_id' do
34
+ VCR.use_cassette('account_info/unknown/resource_id') do
35
+ @service.send(:config_client).resource_id = 'unknown'
36
+ expect { @service.account_info }.to raise_error(RubyEcommError){|e| e.result_code.should eq(-304) }
37
+ end
38
+ end
39
+
40
+ it 'raise RubyEcommError for unknown source_tree_id' do
41
+ VCR.use_cassette('account_info/unknown/source_tree_id') do
42
+ expect { @service.account_info(90909) }.to raise_error(RubyEcommError){|e| e.result_code.should eq(-999) }
43
+ end
44
+ end
45
+
46
+ it 'return a Hash' do
47
+ @account_info.class.should eq(Hash)
48
+ end
49
+
50
+ it 'include product_id' do
51
+ @account_info[:product_id].class.should eq(Fixnum)
52
+ end
53
+
54
+ it 'include tree_id' do
55
+ @account_info[:tree_id].class.should eq(Fixnum)
56
+ @account_info[:tree_id].should eq(@current_tree_id.to_i)
57
+ end
58
+
59
+ it 'include is_free' do
60
+ @account_info[:is_free].class.should eq(FalseClass)
61
+ end
62
+
63
+ it 'include tree Hash' do
64
+ @account_info[:tree].class.should eq(Hash)
65
+ end
66
+ end
67
+
68
+ context '#transitions' do
69
+ it 'raise RubyEcommError for unknown source_tree_id' do
70
+ VCR.use_cassette('transitions/default/unknown/source_tree_id') do
71
+ expect { @service.transitions(87563) }.to raise_error(RubyEcommError){|e| e.result_code.should eq(-999) }
72
+ end
73
+ end
74
+ end
75
+
76
+ context '#transitions for one' do
77
+ before do
78
+ VCR.use_cassette('transitions/one') do
79
+ @transitions = @service.transitions(@low_tree_id)
80
+ end
81
+ end
82
+
83
+ it 'return an Array' do
84
+ @transitions.class.should eq(Array)
85
+ end
86
+
87
+ it 'return multiple' do
88
+ @transitions.size.should eq(2)
89
+ end
90
+
91
+ it 'return containing Hashes' do
92
+ @transitions.first.class.should eq(Hash)
93
+ end
94
+
95
+ it 'return containing Hashes with product_id' do
96
+ @transitions.first[:product_id].class.should eq(Fixnum)
97
+ end
98
+
99
+ it 'return containing Hashes with tree_id' do
100
+ @transitions.first[:tree_id].class.should eq(Fixnum)
101
+ end
102
+
103
+ it 'return containing Hashes with node_name' do
104
+ @transitions.first[:node_name].class.should eq(String)
105
+ end
106
+ end
107
+
108
+ context '#transitions for many' do
109
+ before do
110
+ VCR.use_cassette('transitions/many') do
111
+ @transitions = @service.transitions(@current_tree_id)
112
+ end
113
+ end
114
+
115
+ it 'return an Array' do
116
+ @transitions.class.should eq(Array)
117
+ end
118
+
119
+ it 'return multiple' do
120
+ @transitions.size.should eq(2)
121
+ end
122
+
123
+ it 'return containing Hashes' do
124
+ @transitions.first.class.should eq(Hash)
125
+ end
126
+
127
+ it 'return containing Hashes with product_id' do
128
+ @transitions.first[:product_id].class.should eq(Fixnum)
129
+ end
130
+
131
+ it 'return containing Hashes with tree_id' do
132
+ @transitions.first[:tree_id].class.should eq(Fixnum)
133
+ end
134
+
135
+ it 'return containing Hashes with node_name' do
136
+ @transitions.first[:node_name].class.should eq(String)
137
+ end
138
+ end
139
+
140
+ context '#find_transition' do
141
+ before do
142
+ @transitions = [
143
+ { :product_id => 1 },
144
+ { :product_id => 1337 }
145
+ ]
146
+ @target_pfid = 1337
147
+ end
148
+
149
+ it 'requires transitions non-nil' do
150
+ expect { @service.find_transition(nil, @target_pfid) }.to raise_error(ArgumentError)
151
+ end
152
+
153
+ it 'requires transitions non-blank' do
154
+ expect { @service.find_transition([], @target_pfid) }.to raise_error(ArgumentError)
155
+ end
156
+
157
+ it 'requires target_pfid non-nil' do
158
+ expect { @service.find_transition(@transitions, nil) }.to raise_error(ArgumentError)
159
+ end
160
+
161
+ it 'requires target_pfid non-blank' do
162
+ expect { @service.find_transition(@transitions, '') }.to raise_error(ArgumentError)
163
+ end
164
+
165
+ it 'should handle non-Array transitions' do
166
+ @service.find_transition(@transitions.last, @target_pfid)[:product_id].should eq(@target_pfid)
167
+ end
168
+
169
+ it 'should handle String target_pfid' do
170
+ @service.find_transition(@transitions, @target_pfid.to_s)[:product_id].should eq(@target_pfid)
171
+ end
172
+
173
+ it 'returns the first transition matching target_pfid' do
174
+ @service.find_transition(@transitions, @target_pfid)[:product_id].should eq(@target_pfid)
175
+ end
176
+
177
+ it 'returns nil if no match' do
178
+ @service.find_transition(@transitions, 22).should be_nil
179
+ end
180
+ end
181
+
182
+ context '#request_change_via_manager' do
183
+ before do
184
+ @service.stub(:express_checkout?).and_return(false)
185
+ end
186
+
187
+ context 'upgrade' do
188
+ before do
189
+ VCR.use_cassette('request_change/manager/upgrade/default') do
190
+ @result = @service.request_change_via_manager(@upgrade_tree_id)
191
+ end
192
+ end
193
+
194
+ it 'require target_tree_id non-nil' do
195
+ expect { @service.request_change_via_manager(nil) }.to raise_error(ArgumentError)
196
+ end
197
+
198
+ it 'require target_tree_id non-blank' do
199
+ expect { @service.request_change_via_manager('') }.to raise_error(ArgumentError)
200
+ end
201
+
202
+ it 'raise RubyEcommError for unknown resource_type' do
203
+ VCR.use_cassette('request_change/manager/upgrade/unknown/resource_type') do
204
+ @service.send(:config_client).resource_type = 'flugel'
205
+ expect { @service.request_change_via_manager(@upgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-100) }
206
+ end
207
+ end
208
+
209
+ it 'raise RubyEcommError for unknown resource_id' do
210
+ VCR.use_cassette('request_change/manager/upgrade/unknown/resource_id') do
211
+ @service.send(:config_client).resource_id = 'unknown'
212
+ expect { @service.request_change_via_manager(@upgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-304) }
213
+ end
214
+ end
215
+
216
+ it 'raise RubyEcommError for unknown target_tree_id' do
217
+ VCR.use_cassette('request_change/manager/upgrade/unknown/target_tree_id') do
218
+ expect { @service.request_change_via_manager(73223) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-999) }
219
+ end
220
+ end
221
+
222
+ it "return no-op request_result for transition to same" do
223
+ VCR.use_cassette('request_change/manager/upgrade/noop') do
224
+ result = @service.request_change_via_manager(@current_tree_id)
225
+ result[:request_result].should eq(1)
226
+ result[:used_express_checkout].should eq(false)
227
+ end
228
+ end
229
+
230
+ it "return success request_result for valid transition" do
231
+ @result[:request_result].should eq(2)
232
+ @result[:used_express_checkout].should eq(false)
233
+ end
234
+ end
235
+
236
+ context 'downgrade' do
237
+ before do
238
+ VCR.use_cassette('request_change/manager/downgrade/default') do
239
+ @result = @service.request_change_via_manager(@downgrade_tree_id)
240
+ end
241
+ end
242
+
243
+ it 'require target_tree_id non-nil' do
244
+ expect { @service.request_change_via_manager(nil) }.to raise_error(ArgumentError)
245
+ end
246
+
247
+ it 'require target_tree_id non-blank' do
248
+ expect { @service.request_change_via_manager('') }.to raise_error(ArgumentError)
249
+ end
250
+
251
+ it 'raise RubyEcommError for unknown resource_type' do
252
+ VCR.use_cassette('request_change/manager/downgrade/unknown/resource_type') do
253
+ @service.send(:config_client).resource_type = 'flugel'
254
+ expect { @service.request_change_via_manager(@downgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-100) }
255
+ end
256
+ end
257
+
258
+ it 'raise RubyEcommError for unknown resource_id' do
259
+ VCR.use_cassette('request_change/manager/downgrade/unknown/resource_id') do
260
+ @service.send(:config_client).resource_id = 'unknown'
261
+ expect { @service.request_change_via_manager(@downgrade_tree_id) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-304) }
262
+ end
263
+ end
264
+
265
+ it 'raise RubyEcommError for unknown target_tree_id' do
266
+ VCR.use_cassette('request_change/manager/downgrade/unknown/target_tree_id') do
267
+ expect { @service.request_change_via_manager(73541) }.to raise_error(RubyEcommError) { |e| e.result_code.should eq(-999) }
268
+ end
269
+ end
270
+
271
+ it "return no-op request_result for transition to same" do
272
+ VCR.use_cassette('request_change/manager/downgrade/noop') do
273
+ result = @service.request_change_via_manager(@current_tree_id)
274
+ result[:request_result].should eq(2)
275
+ result[:used_express_checkout].should eq(false)
276
+ end
277
+ end
278
+
279
+ it "return success request_result for valid transition" do
280
+ @result[:request_result].should eq(1)
281
+ @result[:used_express_checkout].should eq(false)
282
+ end
283
+ end
284
+ end
285
+ end