reward_station 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +9 -0
  5. data/LICENSE +0 -0
  6. data/README.md +5 -0
  7. data/Rakefile +5 -0
  8. data/lib/reward_station.rb +1 -0
  9. data/lib/reward_station/version.rb +3 -0
  10. data/lib/wsdl/reward_services.xml +511 -0
  11. data/lib/xceleration/reward_station.rb +122 -0
  12. data/reward_station.gemspec +21 -0
  13. data/spec/fixtures/savon/reward_station/award_points/award_points.xml +12 -0
  14. data/spec/fixtures/savon/reward_station/award_points/award_points_invalid_token.xml +12 -0
  15. data/spec/fixtures/savon/reward_station/return_point_summary/return_point_summary.xml +22 -0
  16. data/spec/fixtures/savon/reward_station/return_point_summary/return_point_summary_invalid_token.xml +12 -0
  17. data/spec/fixtures/savon/reward_station/return_popular_products/return_popular_products.xml +362 -0
  18. data/spec/fixtures/savon/reward_station/return_popular_products/return_popular_products_invalid_token.xml +10 -0
  19. data/spec/fixtures/savon/reward_station/return_token/return_token.xml +10 -0
  20. data/spec/fixtures/savon/reward_station/return_token/return_token_invalid.xml +10 -0
  21. data/spec/fixtures/savon/reward_station/return_user/return_user.xml +35 -0
  22. data/spec/fixtures/savon/reward_station/return_user/return_user_invalid_token.xml +10 -0
  23. data/spec/fixtures/savon/reward_station/return_user/return_user_invalid_user.xml +10 -0
  24. data/spec/fixtures/savon/reward_station/update_user/create_user.xml +34 -0
  25. data/spec/fixtures/savon/reward_station/update_user/create_user_exists.xml +9 -0
  26. data/spec/savon_helper.rb +129 -0
  27. data/spec/spec_helper.rb +18 -0
  28. data/spec/xceleration/reward_station_spec.rb +348 -0
  29. metadata +95 -0
@@ -0,0 +1,10 @@
1
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <soap:Body>
3
+ <ReturnPopularProductsResponse xmlns="http://rswebservices.rewardstation.com/">
4
+ <ReturnPopularProductsResult>
5
+ <UserID>534347</UserID>
6
+ <ErrorMessage>Invalid Token</ErrorMessage>
7
+ </ReturnPopularProductsResult>
8
+ </ReturnPopularProductsResponse>
9
+ </soap:Body>
10
+ </soap:Envelope>
@@ -0,0 +1,10 @@
1
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <soap:Body>
3
+ <ReturnTokenResponse xmlns="http://rswebservices.rewardstation.com/">
4
+ <ReturnTokenResult>
5
+ <Token>e285e1ed-2356-4676-a554-99d79e6284b0</Token>
6
+ <ErrorMessage/>
7
+ </ReturnTokenResult>
8
+ </ReturnTokenResponse>
9
+ </soap:Body>
10
+ </soap:Envelope>
@@ -0,0 +1,10 @@
1
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <soap:Body>
3
+ <ReturnTokenResponse xmlns="http://rswebservices.rewardstation.com/">
4
+ <ReturnTokenResult>
5
+ <Token/>
6
+ <ErrorMessage>Invalid Account Number and/or Account Code. Please contact Xceleration.</ErrorMessage>
7
+ </ReturnTokenResult>
8
+ </ReturnTokenResponse>
9
+ </soap:Body>
10
+ </soap:Envelope>
@@ -0,0 +1,35 @@
1
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <soap:Body>
3
+ <ReturnUserResponse xmlns="http://rswebservices.rewardstation.com/">
4
+ <ReturnUserResult>
5
+ <UserID>6725</UserID>
6
+ <UserProfile>
7
+ <UserID>6725</UserID>
8
+ <ClientID>100080</ClientID>
9
+ <UserName>john3@company.com</UserName>
10
+ <EncryptedPassword/>
11
+ <FirstName>John</FirstName>
12
+ <LastName>Smith</LastName>
13
+ <AddressOne/>
14
+ <AddressTwo/>
15
+ <City/>
16
+ <StateCode/>
17
+ <Province/>
18
+ <PostalCode/>
19
+ <CountryCode>USA</CountryCode>
20
+ <Phone/>
21
+ <Email>john@company.com</Email>
22
+ <OrganizationID>0</OrganizationID>
23
+ <OrganizationName/>
24
+ <RepTypeID>0</RepTypeID>
25
+ <ClientRegionID>0</ClientRegionID>
26
+ <IsActive>true</IsActive>
27
+ <PointBalance>10</PointBalance>
28
+ <ManagerID>0</ManagerID>
29
+ <ErrorMessage/>
30
+ </UserProfile>
31
+ <ErrorMessage/>
32
+ </ReturnUserResult>
33
+ </ReturnUserResponse>
34
+ </soap:Body>
35
+ </soap:Envelope>
@@ -0,0 +1,10 @@
1
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <soap:Body>
3
+ <ReturnUserResponse xmlns="http://rswebservices.rewardstation.com/">
4
+ <ReturnUserResult>
5
+ <UserID>672</UserID>
6
+ <ErrorMessage>Invalid Token</ErrorMessage>
7
+ </ReturnUserResult>
8
+ </ReturnUserResponse>
9
+ </soap:Body>
10
+ </soap:Envelope>
@@ -0,0 +1,10 @@
1
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <soap:Body>
3
+ <ReturnUserResponse xmlns="http://rswebservices.rewardstation.com/">
4
+ <ReturnUserResult>
5
+ <UserID>672</UserID>
6
+ <ErrorMessage>Invalid User ID</ErrorMessage>
7
+ </ReturnUserResult>
8
+ </ReturnUserResponse>
9
+ </soap:Body>
10
+ </soap:Envelope>
@@ -0,0 +1,34 @@
1
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <soap:Body>
3
+ <UpdateUserResponse xmlns="http://rswebservices.rewardstation.com/">
4
+ <UpdateUserResult>
5
+ <UpdateUser>
6
+ <UserID>6727</UserID>
7
+ <ClientID>100080</ClientID>
8
+ <UserName>john5@company.com</UserName>
9
+ <EncryptedPassword/>
10
+ <FirstName>John</FirstName>
11
+ <LastName>Smith</LastName>
12
+ <AddressOne/>
13
+ <AddressTwo/>
14
+ <City/>
15
+ <StateCode/>
16
+ <Province/>
17
+ <PostalCode/>
18
+ <CountryCode>USA</CountryCode>
19
+ <Phone/>
20
+ <Email>john5@company.com</Email>
21
+ <OrganizationID>150</OrganizationID>
22
+ <OrganizationName/>
23
+ <RepTypeID>0</RepTypeID>
24
+ <ClientRegionID>0</ClientRegionID>
25
+ <IsActive>true</IsActive>
26
+ <PointBalance>0</PointBalance>
27
+ <ManagerID>0</ManagerID>
28
+ <ErrorMessage/>
29
+ </UpdateUser>
30
+ <ErrorMessage/>
31
+ </UpdateUserResult>
32
+ </UpdateUserResponse>
33
+ </soap:Body>
34
+ </soap:Envelope>
@@ -0,0 +1,9 @@
1
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <soap:Body>
3
+ <UpdateUserResponse xmlns="http://rswebservices.rewardstation.com/">
4
+ <UpdateUserResult>
5
+ <ErrorMessage>User Name: john3@company.com already exists. Please enter a different user name.</ErrorMessage>
6
+ </UpdateUserResult>
7
+ </UpdateUserResponse>
8
+ </soap:Body>
9
+ </soap:Envelope>
@@ -0,0 +1,129 @@
1
+ module Savon
2
+ module Spec
3
+
4
+ # = Savon::Spec::Macros
5
+ #
6
+ # Include this module into your RSpec tests to mock/stub Savon SOAP requests.
7
+ module Macros
8
+
9
+ def savon
10
+ Savon::SOAP::Response.any_instance.stub(:soap_fault?).and_return(false)
11
+ Savon::SOAP::Response.any_instance.stub(:http_error?).and_return(false)
12
+
13
+ Savon::Spec::Mock.new
14
+ end
15
+
16
+ end
17
+
18
+ class Fixture
19
+ class << self
20
+
21
+ def path
22
+ @path ||= Rails.root.join("spec", "fixtures").to_s if defined? Rails
23
+
24
+ raise ArgumentError, "Savon::Spec::Fixture.path needs to be specified" unless @path
25
+ @path
26
+ end
27
+
28
+ attr_writer :path
29
+
30
+ def load(*args)
31
+ file = args.map { |arg| arg.to_s.snakecase }.join("/")
32
+ fixtures[file] ||= load_file file
33
+ end
34
+
35
+ alias [] load
36
+
37
+ private
38
+
39
+ def fixtures
40
+ @fixtures ||= {}
41
+ end
42
+
43
+ def load_file(file)
44
+ full_path = File.expand_path File.join(path, "#{file}.xml")
45
+ raise ArgumentError, "Unable to load: #{full_path}" unless File.exist? full_path
46
+
47
+ File.read full_path
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ # = Savon::Spec::Mock
54
+ #
55
+ # Mocks/stubs SOAP requests executed by Savon.
56
+ class Mock
57
+
58
+ def expects(soap_action)
59
+ setup :expects, soap_action
60
+ self
61
+ end
62
+
63
+ def stub(soap_action)
64
+ setup :stub, soap_action
65
+ self
66
+ end
67
+
68
+ # Expects a given SOAP body Hash to be used.
69
+ def with(soap_body)
70
+ Savon::SOAP::XML.any_instance.expects(:body=).with(soap_body) if mock_method == :expects
71
+ self
72
+ end
73
+
74
+ def never
75
+ httpi_mock.never
76
+ self
77
+ end
78
+
79
+ # Sets up HTTPI to return a given +response+.
80
+ def and_return(response = nil)
81
+ http = { :code => 200, :headers => {}, :body => "" }
82
+
83
+ case response
84
+ when Symbol then http[:body] = Fixture[soap_action, response]
85
+ when Hash then http.merge! response
86
+ when String then http[:body] = response
87
+ end
88
+
89
+ httpi_mock.and_return HTTPI::Response.new(http[:code], http[:headers], http[:body])
90
+ self
91
+ end
92
+
93
+ # Sets up Savon to respond like there was a SOAP fault.
94
+ def raises_soap_fault
95
+ Savon::SOAP::Response.any_instance.stub(:soap_fault?).and_return(true)
96
+ self
97
+ end
98
+
99
+ def raises_http_error
100
+ Savon::SOAP::Response.any_instance.stub(:soap_fault?).and_return(false)
101
+ Savon::SOAP::Response.any_instance.stub(:http_error?).and_return(true)
102
+ self
103
+ end
104
+
105
+ private
106
+
107
+ def setup(mock_method, soap_action)
108
+ self.mock_method = mock_method
109
+ self.soap_action = soap_action
110
+ self.httpi_mock = new_httpi_mock
111
+ end
112
+
113
+ attr_accessor :mock_method
114
+
115
+ def soap_action=(soap_action)
116
+ @soap_action = soap_action.kind_of?(Symbol) ? soap_action.to_s.lower_camelcase : soap_action
117
+ end
118
+
119
+ attr_reader :soap_action
120
+
121
+ def new_httpi_mock
122
+ HTTPI.send(mock_method, :post)
123
+ end
124
+
125
+ attr_accessor :httpi_mock
126
+
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,18 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+
4
+ require 'rubygems'
5
+
6
+ require 'savon'
7
+
8
+ require 'reward_station'
9
+
10
+ require "savon_helper"
11
+
12
+ RSpec.configure do |config|
13
+ config.mock_with :rspec
14
+
15
+ config.include Savon::Spec::Macros
16
+ end
17
+
18
+
@@ -0,0 +1,348 @@
1
+ require 'spec_helper'
2
+
3
+ describe Xceleration::RewardStation do
4
+
5
+ before(:all) {
6
+ Savon::Spec::Fixture.path = File.join(File.dirname(__FILE__), "..", "fixtures", "savon", "reward_station").to_s
7
+ }
8
+
9
+ before(:each) { @service = Xceleration::RewardStation.new }
10
+
11
+ describe "return_token" do
12
+
13
+ describe "on valid response" do
14
+ before do
15
+ savon.stub(:return_token).and_return(:return_token)
16
+ end
17
+ it "should return valid token" do
18
+ @service.return_token('100080', 'fM6Rv4moz#').should eq("e285e1ed-2356-4676-a554-99d79e6284b0")
19
+ end
20
+
21
+ it "should not raise InvalidAccount exception" do
22
+ lambda{ @service.return_token('100080', 'fM6Rv4moz#') }.should_not raise_error(Xceleration::InvalidAccount)
23
+ end
24
+ end
25
+
26
+ describe "on invalid account response" do
27
+ before do
28
+ savon.stub(:return_token).and_return(:return_token_invalid)
29
+ end
30
+
31
+ it "should raise InvalidAccount exception" do
32
+ lambda{ @service.return_token('100080', 'fM6Rv4moz#') }.should raise_error(Xceleration::InvalidAccount)
33
+ end
34
+ end
35
+
36
+ describe "on soap error" do
37
+ before do
38
+ savon.stub(:return_token).and_return.raises_soap_fault
39
+ # mock_client.stub!(:request).and_raise(Savon::SOAP::Fault.new(HTTPI::Response.new(404, {}, {})))
40
+ end
41
+
42
+ it "should raise ConnectionError exception" do
43
+ lambda{ @service.return_token('100080', 'fM6Rv4moz#') }.should raise_error(Xceleration::ConnectionError)
44
+ end
45
+ end
46
+
47
+ describe "on http error" do
48
+ before do
49
+ savon.stub(:return_token).and_return(:code => 404).raises_http_error
50
+ end
51
+
52
+ it "should raise HttpError exception" do
53
+ lambda{ @service.return_token('100080', 'fM6Rv4moz#') }.should raise_error(Xceleration::ConnectionError)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "award_points" do
59
+ describe "on valid response" do
60
+ before do
61
+ savon.stub(:award_points).and_return(:award_points)
62
+ end
63
+
64
+ it "should return valid confirm code" do
65
+ @service.award_points("e285e1ed-2356-4676-a554-99d79e6284b0", 130, 10, "Action 'Some' taken").should eq("9376")
66
+ end
67
+
68
+ it "should not raise InvalidToken exception" do
69
+ lambda{ @service.award_points("e285e1ed-2356-4676-a554-99d79e6284b0", 130, 10, "Action 'Some' taken") }.should_not raise_error(Xceleration::InvalidToken)
70
+ end
71
+ end
72
+
73
+ describe "on invalid token response" do
74
+ before do
75
+ savon.stub(:award_points).and_return(:award_points_invalid_token)
76
+ end
77
+
78
+ it "should raise InvalidToken exception" do
79
+ lambda{ @service.award_points("", 130, 10, "Action 'Some' taken") }.should raise_error(Xceleration::InvalidToken)
80
+ end
81
+ end
82
+
83
+ describe "on soap error" do
84
+ before do
85
+ savon.stub(:award_points).and_return.raises_soap_fault
86
+ # mock_client.stub!(:request).and_raise(Savon::SOAP::Fault.new(HTTPI::Response.new(404, {}, {})))
87
+ end
88
+
89
+ it "should raise ConnectionError exception" do
90
+ lambda{ @service.award_points("e285e1ed-2356-4676-a554-99d79e6284b0", 130, 10, "Action 'Some' taken") }.should raise_error(Xceleration::ConnectionError)
91
+ end
92
+ end
93
+
94
+ describe "on http error" do
95
+ before do
96
+ savon.stub(:award_points).and_return(:code => 404).raises_http_error
97
+ end
98
+
99
+ it "should raise HttpError exception" do
100
+ lambda{ @service.award_points("e285e1ed-2356-4676-a554-99d79e6284b0", 130, 10, "Action 'Some' taken") }.should raise_error(Xceleration::ConnectionError)
101
+ end
102
+ end
103
+ end
104
+
105
+ describe "return_user" do
106
+ describe "on valid response" do
107
+ before do
108
+ savon.stub(:return_user).and_return(:return_user)
109
+ end
110
+
111
+ it "should return valid user data" do
112
+ @service.return_user("e285e1ed-2356-4676-a554-99d79e6284b0", 130).should eq(:user_id => '6725',
113
+ :client_id => '100080',
114
+ :user_name => 'john3@company.com',
115
+ :encrypted_password => nil,
116
+ :first_name => 'John',
117
+ :last_name => 'Smith',
118
+ :address_one => nil,
119
+ :address_two => nil,
120
+ :city => nil,
121
+ :state_code => nil,
122
+ :province => nil,
123
+ :postal_code => nil,
124
+ :country_code => 'USA',
125
+ :phone => nil,
126
+ :email => 'john@company.com',
127
+ :organization_id => '0',
128
+ :organization_name => nil,
129
+ :rep_type_id => '0',
130
+ :client_region_id => '0',
131
+ :is_active => true,
132
+ :point_balance => '10',
133
+ :manager_id => '0',
134
+ :error_message => nil)
135
+ end
136
+
137
+ it "should not raise InvalidToken exception" do
138
+ lambda{ @service.return_user("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should_not raise_error(Xceleration::InvalidToken)
139
+ end
140
+ end
141
+
142
+ describe "on invalid token response" do
143
+ before do
144
+ savon.stub(:return_user).and_return(:return_user_invalid_token)
145
+ end
146
+
147
+ it "should raise InvalidToken exception" do
148
+ lambda{ @service.return_user("", 130) }.should raise_error(Xceleration::InvalidToken)
149
+ end
150
+ end
151
+
152
+ describe "on invalid user response" do
153
+ before do
154
+ savon.stub(:return_user).and_return(:return_user_invalid_user)
155
+ end
156
+
157
+ it "should raise InvalidUser exception" do
158
+ lambda{ @service.return_user("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should raise_error(Xceleration::InvalidUser)
159
+ end
160
+ end
161
+
162
+ describe "on soap error" do
163
+ before do
164
+ savon.stub(:return_user).and_return.raises_soap_fault
165
+ end
166
+
167
+ it "should raise ConnectionError exception" do
168
+ lambda{ @service.return_user("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should raise_error(Xceleration::ConnectionError)
169
+ end
170
+ end
171
+
172
+ describe "on http error" do
173
+ before do
174
+ savon.stub(:return_user).and_return(:code => 404).raises_http_error
175
+ end
176
+
177
+ it "should raise HttpError exception" do
178
+ lambda{ @service.return_user("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should raise_error(Xceleration::ConnectionError)
179
+ end
180
+ end
181
+ end
182
+
183
+ describe "return_point_summary" do
184
+ describe "on valid request" do
185
+ before do
186
+ savon.stub(:return_point_summary).and_return(:return_point_summary)
187
+ end
188
+
189
+ it "should return valid summary" do
190
+ @service.return_point_summary("e285e1ed-2356-4676-a554-99d79e6284b0", 130, '100080').should eq(:user_id => '577',
191
+ :is_active => true,
192
+ :points_earned => '465',
193
+ :points_redeemed => '0',
194
+ :points_credited => '0',
195
+ :points_balance => '465')
196
+ end
197
+
198
+ it "should not raise InvalidToken exception" do
199
+ lambda{ @service.return_point_summary("e285e1ed-2356-4676-a554-99d79e6284b0", 130, '100080') }.should_not raise_error(Xceleration::InvalidToken)
200
+ end
201
+ end
202
+
203
+ describe "on invalid token request" do
204
+ before do
205
+ savon.stub(:return_point_summary).and_return(:return_point_summary_invalid_token)
206
+ end
207
+
208
+ it "should raise InvalidToken exception" do
209
+ lambda{ @service.return_point_summary("", 130, '100080') }.should raise_error(Xceleration::InvalidToken)
210
+ end
211
+ end
212
+
213
+ describe "on soap error" do
214
+ before do
215
+ savon.stub(:return_point_summary).and_return.raises_soap_fault
216
+ end
217
+
218
+ it "should raise ConnectionError exception" do
219
+ lambda{ @service.return_point_summary("e285e1ed-2356-4676-a554-99d79e6284b0", 130, '100080') }.should raise_error(Xceleration::ConnectionError)
220
+ end
221
+ end
222
+
223
+ describe "on http error" do
224
+ before do
225
+ savon.stub(:return_point_summary).and_return(:code => 404).raises_http_error
226
+ end
227
+
228
+ it "should raise HttpError exception" do
229
+ lambda{ @service.return_point_summary("e285e1ed-2356-4676-a554-99d79e6284b0", 130, '100080') }.should raise_error(Xceleration::ConnectionError)
230
+ end
231
+ end
232
+ end
233
+
234
+ describe "update_user" do
235
+ describe "on create user valid request" do
236
+ before do
237
+ savon.stub(:update_user).and_return(:create_user)
238
+ end
239
+
240
+ it "should return valid response" do
241
+ @service.create_user("e285e1ed-2356-4676-a554-99d79e6284b0",
242
+ '100080',
243
+ '150', {
244
+ :email => 'john5@company.com',
245
+ :first_name => 'John',
246
+ :last_name => 'Smith',
247
+ :user_name => 'john5@company.com',
248
+ :balance => 0
249
+ }).should eq(:user_id => '6727',
250
+ :client_id => '100080',
251
+ :user_name => 'john5@company.com',
252
+ :email => 'john5@company.com',
253
+ :encrypted_password => nil,
254
+ :first_name => 'John',
255
+ :last_name => 'Smith',
256
+ :address_one => nil,
257
+ :address_two => nil,
258
+ :city => nil,
259
+ :state_code => nil,
260
+ :province => nil,
261
+ :postal_code => nil,
262
+ :country_code => 'USA',
263
+ :phone => nil,
264
+ :organization_id => '150',
265
+ :organization_name => nil,
266
+ :rep_type_id => '0',
267
+ :client_region_id => '0',
268
+
269
+ :is_active => true,
270
+ :point_balance => '0',
271
+ :manager_id => '0',
272
+ :error_message => nil)
273
+ end
274
+
275
+ it "should not raise InvalidToken exception" do
276
+ lambda{ @service.create_user("e285e1ed-2356-4676-a554-99d79e6284b0",
277
+ '100080',
278
+ '150', {
279
+ :email => 'john5@company.com',
280
+ :first_name => 'John',
281
+ :last_name => 'Smith',
282
+ :user_name => 'john5@company.com',
283
+ :balance => 0
284
+ })
285
+ }.should_not raise_error(Xceleration::InvalidToken)
286
+ end
287
+ end
288
+
289
+ describe "on create user invalid request" do
290
+ before do
291
+ savon.stub(:update_user).and_return(:create_user_exists)
292
+ end
293
+
294
+ it "should raise UserAlreadyExists exception" do
295
+ lambda{ @service.update_user("e285e1ed-2356-4676-a554-99d79e6284b0",
296
+ 130,
297
+ '100080',
298
+ '150', {
299
+ :email => 'john5@company.com',
300
+ :first_name => 'John',
301
+ :last_name => 'Smith',
302
+ :user_name => 'john5@company.com',
303
+ :balance => 0
304
+ })
305
+ }.should raise_error(Xceleration::UserAlreadyExists)
306
+ end
307
+ end
308
+
309
+ end
310
+
311
+ describe "return_popular_products" do
312
+ describe "on valid request" do
313
+ before do
314
+ savon.stub(:return_popular_products).and_return(:return_popular_products)
315
+ end
316
+
317
+ it "should return valid response" do
318
+ products = @service.return_popular_products("e285e1ed-2356-4676-a554-99d79e6284b0", 130)
319
+ products.should be_a(Array)
320
+ products.size.should eq(35)
321
+ products.first.should eq(:product_id => 'MC770LLA',
322
+ :name => 'iPad 2 with Wifi - 32GB',
323
+ :description => 'The NEW Apple iPad 2 - Thinner, lighter, and full of great ideas. Once you pick up iPad 2, it’ll be hard to put down. That’s the idea behind the all-new design. It’s 33 percent thinner and up to 15 percent lighter, so it feels even more comfortable in your hands. And, it makes surfing the web, checking email, watching movies, and reading books so natural, you might forget there’s incredible technology under your fingers.<br><br><b>Dual-core A5 chip</b>.<br> Two powerful cores in one A5 chip mean iPad can do twice the work at once. You’ll notice the difference when you’re surfing the web, watching movies, making FaceTime video calls, gaming, and going from app to app to app. Multitasking is smoother, apps load faster, and everything just works better.<br><br><b>Superfast graphics</b>. <br>With up to nine times the graphics performance, gameplay on iPad is even smoother and more realistic. And faster graphics help apps perform better — especially those with video. You’ll see it when you’re scrolling through your photo library, editing video with iMovie, and viewing animations in Keynote.<br><br><b>Battery life keeps on going. So you can, too.</b><br> Even with the new thinner and lighter design, iPad has the same amazing 10-hour battery life. That’s enough juice for one flight across the ocean, or one movie-watching all-nighter, or a week’s commute across town. The power-efficient A5 chip and iOS keep battery life from fading away, so you can get carried away.<br><br><b>Two cameras.</b><br> You’ll see two cameras on iPad — one on the front and one on the back. They may be tiny, but they’re a big deal. They’re designed for FaceTime video calling, and they work together so you can talk to your favorite people and see them smile and laugh back at you. The front camera puts you and your friend face-to-face. Switch to the back camera during your video call to share where you are, who you’re with, or what’s going on around you. When you’re not using FaceTime, let the back camera roll if you see something movie-worthy. It’s HD, so whatever you shoot is a mini-masterpiece. And you can take wacky snapshots in Photo Booth. It’s the most fun a face can have.<br><br><b>Due to the demand for this item, please allow up to 8-10 weeks for delivery</b>.',
324
+ :points => '10927',
325
+ :category => 'Office & Computer',
326
+ :manufacturer => 'Apple',
327
+ :small_image_url => 'https://www.rewardstation.com/catalogimages/MC769LLA.gif',
328
+ :large_image_url => 'https://www.rewardstation.com/catalogimages/MC769LLA.jpg')
329
+ end
330
+
331
+ it "should not raise InvalidToken exception" do
332
+ lambda{ @service.return_popular_products("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should_not raise_error(Xceleration::InvalidToken)
333
+ end
334
+ end
335
+
336
+ describe "on create user invalid token request" do
337
+ before do
338
+ savon.stub(:return_popular_products).and_return(:return_popular_products_invalid_token)
339
+ end
340
+
341
+ it "should raise InvalidToken exception" do
342
+ lambda{ @service.return_popular_products("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should raise_error(Xceleration::InvalidToken)
343
+ end
344
+ end
345
+
346
+ end
347
+
348
+ end