fuelsdk 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -71,29 +71,32 @@ describe FuelSDK::Soap do
71
71
 
72
72
  describe '#normalize_filter' do
73
73
  it 'returns complex filter part when filter contains LogicalOperator key' do
74
- expect(subject.normalize_filter({'LogicalOperator' => 'AND'}))
74
+ expect(subject.normalize_filter({'LogicalOperator' => 'AND', 'LeftOperand' => {}, 'RightOperand' => {}}))
75
75
  .to eq(
76
76
  {
77
77
  'Filter' => {
78
78
  'LogicalOperator' => 'AND',
79
- :attributes! => {
80
- 'LeftOperand' => { 'xsi:type' => 'tns:SimpleFilterPart' },
81
- 'RightOperand' => { 'xsi:type' => 'tns:SimpleFilterPart' }
82
- },
83
- },
84
- :attributes! => { 'Filter' => { 'xsi:type' => 'tns:ComplexFilterPart' }}
79
+ '@xsi:type' => 'tns:ComplexFilterPart',
80
+ 'LeftOperand' => { '@xsi:type' => 'tns:SimpleFilterPart' },
81
+ 'RightOperand' => { '@xsi:type' => 'tns:SimpleFilterPart' }
82
+ }
85
83
  }
86
84
  )
87
85
  end
88
86
 
87
+ it 'raises error when missing left or right operand' do
88
+ expect{subject.normalize_filter({'LogicalOperator' => 'AND'})}
89
+ .to raise_error /Missing SimpleFilterParts/
90
+ end
91
+
89
92
  it 'returns simple filter part by default' do
90
93
  expect(subject.normalize_filter({'SimpleOperator' => 'equals'}))
91
94
  .to eq(
92
95
  {
93
96
  'Filter' => {
94
97
  'SimpleOperator' => 'equals',
95
- },
96
- :attributes! => { 'Filter' => { 'xsi:type' => 'tns:SimpleFilterPart' }}
98
+ '@xsi:type' => 'tns:SimpleFilterPart',
99
+ }
97
100
  }
98
101
  )
99
102
  end
@@ -14,12 +14,12 @@ describe FuelSDK::Soap do
14
14
  expect(subject.create_action_message('Definitions', 'QueryDefinition', [{'ObjectID' => 1}], 'start'))
15
15
  .to eq(
16
16
  {
17
- 'Action' => 'start',
17
+ 'Action' => 'start',
18
18
  'Definitions' => {
19
- 'Definition' => [{'ObjectID' => 1}],
20
- :attributes! => {
21
- 'Definition' => { 'xsi:type' => 'tns:QueryDefinition'}
22
- }
19
+ 'Definition' => [{
20
+ 'ObjectID' => 1,
21
+ '@xsi:type' => 'tns:QueryDefinition'
22
+ }]
23
23
  }
24
24
  }
25
25
  )
@@ -29,12 +29,12 @@ describe FuelSDK::Soap do
29
29
  expect(subject.create_action_message('Definitions', 'QueryDefinition', {'ObjectID' => 1}, 'start'))
30
30
  .to eq(
31
31
  {
32
- 'Action' => 'start',
32
+ 'Action' => 'start',
33
33
  'Definitions' => {
34
- 'Definition' => [{'ObjectID' => 1}],
35
- :attributes! => {
36
- 'Definition' => { 'xsi:type' => 'tns:QueryDefinition'}
37
- }
34
+ 'Definition' => [{
35
+ 'ObjectID' => 1,
36
+ '@xsi:type' => 'tns:QueryDefinition'
37
+ }]
38
38
  }
39
39
  }
40
40
  )
@@ -35,9 +35,9 @@ describe FuelSDK::Soap do
35
35
  client.internal_token = 'innerspace'
36
36
  expect(client.header).to eq(
37
37
  {
38
- 'oAuth' => { 'oAuthToken' => 'innerspace' },
39
- :attributes! => {
40
- 'oAuth' => { 'xmlns' => 'http://exacttarget.com' }
38
+ 'oAuth' => {
39
+ 'oAuthToken' => 'innerspace',
40
+ '@xmlns' => 'http://exacttarget.com'
41
41
  }
42
42
  }
43
43
  )
@@ -69,16 +69,23 @@ describe FuelSDK::Soap do
69
69
  it 'formats soap :create message for single object' do
70
70
  expect(subject.soap_post 'Subscriber', 'EmailAddress' => 'test@fuelsdk.com' ).to eq([:create,
71
71
  {
72
- 'Objects' => [{'EmailAddress' => 'test@fuelsdk.com'}],
73
- :attributes! => {'Objects' => {'xsi:type' => ('tns:Subscriber')}}
72
+ 'Objects' => [{
73
+ 'EmailAddress' => 'test@fuelsdk.com',
74
+ '@xsi:type' => 'tns:Subscriber'
75
+ }]
74
76
  }])
75
77
  end
76
78
 
77
79
  it 'formats soap :create message for multiple objects' do
78
80
  expect(subject.soap_post 'Subscriber', [{'EmailAddress' => 'first@fuelsdk.com'}, {'EmailAddress' => 'second@fuelsdk.com'}] ).to eq([:create,
79
81
  {
80
- 'Objects' => [{'EmailAddress' => 'first@fuelsdk.com'}, {'EmailAddress' => 'second@fuelsdk.com'}],
81
- :attributes! => {'Objects' => {'xsi:type' => ('tns:Subscriber')}}
82
+ 'Objects' => [{
83
+ 'EmailAddress' => 'first@fuelsdk.com',
84
+ '@xsi:type' => 'tns:Subscriber'
85
+ }, {
86
+ 'EmailAddress' => 'second@fuelsdk.com',
87
+ '@xsi:type' => 'tns:Subscriber'
88
+ }]
82
89
  }])
83
90
  end
84
91
 
@@ -88,9 +95,9 @@ describe FuelSDK::Soap do
88
95
  {
89
96
  'Objects' => [{
90
97
  'EmailAddress' => 'test@fuelsdk.com',
91
- 'Attributes' => [{'Name' => 'First Name', 'Value' => 'first'}],
92
- }],
93
- :attributes! => {'Objects' => {'xsi:type' => ('tns:Subscriber')}}
98
+ 'Attributes' => [{'Name' => 'First Name', 'Value' => 'first'}],
99
+ '@xsi:type' => 'tns:Subscriber'
100
+ }]
94
101
  }])
95
102
  end
96
103
 
@@ -100,12 +107,12 @@ describe FuelSDK::Soap do
100
107
  {
101
108
  'Objects' => [{
102
109
  'EmailAddress' => 'test@fuelsdk.com',
103
- 'Attributes' => [
110
+ 'Attributes' => [
104
111
  {'Name' => 'First Name', 'Value' => 'first'},
105
112
  {'Name' => 'Last Name', 'Value' => 'subscriber'},
106
113
  ],
107
- }],
108
- :attributes! => {'Objects' => {'xsi:type' => ('tns:Subscriber')}}
114
+ '@xsi:type' => 'tns:Subscriber'
115
+ }]
109
116
  }])
110
117
  end
111
118
 
@@ -115,18 +122,19 @@ describe FuelSDK::Soap do
115
122
  {
116
123
  'Objects' => [
117
124
  {'EmailAddress' => 'first@fuelsdk.com',
118
- 'Attributes' => [
125
+ 'Attributes' => [
119
126
  {'Name' => 'First Name', 'Value' => 'first'},
120
127
  {'Name' => 'Last Name', 'Value' => 'subscriber'},
121
- ]
128
+ ],
129
+ '@xsi:type' => 'tns:Subscriber'
122
130
  },
123
131
  {'EmailAddress' => 'second@fuelsdk.com',
124
132
  'Attributes' => [
125
133
  {'Name' => 'First Name', 'Value' => 'second'},
126
134
  {'Name' => 'Last Name', 'Value' => 'subscriber'},
127
- ]
128
- }],
129
- :attributes! => {'Objects' => {'xsi:type' => ('tns:Subscriber')}}
135
+ ],
136
+ '@xsi:type' => 'tns:Subscriber'
137
+ }]
130
138
  }])
131
139
  end
132
140
  end
@@ -1,16 +1,32 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  lib = File.expand_path('../lib', __FILE__)
2
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
6
 
4
7
  require 'fuelsdk'
8
+ require 'pry'
9
+ require 'webmock/rspec'
10
+ require "savon/mock/spec_helper"
5
11
 
6
12
  RSpec.configure do |config|
7
13
  config.mock_with :rspec
14
+ config.include Savon::SpecHelper
8
15
 
9
16
  # Use color in STDOUT
10
17
  config.color_enabled = true
11
18
 
12
19
  # Use the specified formatter
13
20
  config.formatter = :documentation
21
+
22
+ config.before(:all) do
23
+ savon.mock!
24
+ end
25
+
26
+ config.after(:all) do
27
+ savon.unmock!
28
+ end
29
+
14
30
  end
15
31
 
16
32
  shared_examples_for 'Response Object' do
@@ -0,0 +1,322 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Subscriber' do
4
+
5
+ let(:base) { 'spec/fixtures/webmock/subscriber' }
6
+
7
+ let(:auth) do
8
+ {
9
+ 'client' => {
10
+ 'id' => 'kevy_id',
11
+ 'secret' => 'kevy_secret'
12
+ }
13
+ }
14
+ end
15
+
16
+ let!(:stub_wsdl_request) do
17
+ stub_request(:get, "https://webservice.exacttarget.com/etframework.wsdl").
18
+ to_return(File.new("spec/fixtures/webmock/client/wsdl.txt"))
19
+ end
20
+
21
+ let!(:stub_determine_endpoint) do
22
+ stub_request(:get, "https://www.exacttargetapis.com/platform/v1/endpoints/soap").
23
+ with(:query => { 'access_token' => 'access' }).
24
+ to_return(File.new("spec/fixtures/webmock/client/endpoint.txt"))
25
+ end
26
+
27
+ let!(:stub_refresh_tokens) do
28
+ stub_request(:post, "https://auth.exacttargetapis.com/v1/requestToken").
29
+ with(:query => { 'legacy' => 1 },
30
+ :body => {
31
+ 'clientId' => 'kevy_id',
32
+ 'clientSecret' => 'kevy_secret',
33
+ 'accessType' => 'offline',
34
+ }).
35
+ to_return(File.new("spec/fixtures/webmock/client/tokens.txt"))
36
+ end
37
+
38
+ let(:client) { FuelSDK::Client.new(auth) }
39
+
40
+ let(:stub_describes) do
41
+ savon.expects(:describe).
42
+ with(:message => {
43
+ 'DescribeRequests' => {
44
+ 'ObjectDefinitionRequest' => {
45
+ 'ObjectType' => 'Subscriber'
46
+ }
47
+ }
48
+ }).
49
+ returns(File.read("#{base}/description.xml"))
50
+ end
51
+
52
+ it 'describes' do
53
+ stub_describes
54
+
55
+ rsp = client.describe('Subscriber')
56
+ expect(rsp.retrievable).to include(
57
+ 'EmailAddress'
58
+ )
59
+ expect(rsp.editable).to include(
60
+ 'Gender'
61
+ )
62
+ expect(rsp.editable).not_to include(
63
+ 'ModifiedDate'
64
+ )
65
+ end
66
+ it 'reads specified properties' do
67
+ savon.expects(:retrieve).
68
+ with(:message => {
69
+ 'RetrieveRequest' => {
70
+ 'ObjectType' => 'Subscriber',
71
+ 'Properties' => [
72
+ "ID",
73
+ "EmailAddress",
74
+ ]
75
+ }
76
+ }).
77
+ returns(File.read("#{base}/subscribers.xml"))
78
+
79
+ rsp = client.soap_get('Subscriber', ['ID', 'EmailAddress'])
80
+
81
+ expect(rsp.success).to be_true
82
+ expect(rsp.results.count).to eq 2
83
+
84
+ expect(rsp.results.first[:id]).to eq '16234076'
85
+ expect(rsp.results.first[:attributes]).to include(
86
+ {:name=>"Available Weekends", :value=>"False"}
87
+ )
88
+
89
+ expect(rsp.results.last[:id]).to eq '16234077'
90
+ expect(rsp.results.last[:attributes]).to include(
91
+ {:name=>"Available Weekends", :value=>"True"}
92
+ )
93
+ end
94
+ it 'reads all properties' do
95
+ stub_describes
96
+ savon.expects(:retrieve).
97
+ with(:message => {
98
+ 'RetrieveRequest' => {
99
+ 'ObjectType' => 'Subscriber',
100
+ 'Properties' => [
101
+ "ID",
102
+ "PartnerKey",
103
+ "CreatedDate",
104
+ "Client.ID",
105
+ "Client.PartnerClientKey",
106
+ "EmailAddress",
107
+ "SubscriberKey",
108
+ "UnsubscribedDate",
109
+ "Status",
110
+ "EmailTypePreference",
111
+ ]
112
+ }
113
+ }).
114
+ returns(File.read("#{base}/subscribers_with_all_properties.xml"))
115
+
116
+ rsp = client.soap_get('Subscriber')
117
+
118
+ expect(rsp.success).to be_true
119
+ expect(rsp.results.count).to eq 2
120
+
121
+ expect(rsp.results.first[:id]).to eq '16234076'
122
+ expect(rsp.results.first[:status]).to eq 'Active'
123
+ expect(rsp.results.first[:attributes]).to include(
124
+ {:name=>"Available Weekends", :value=>"False"}
125
+ )
126
+
127
+ expect(rsp.results.last[:id]).to eq '16234077'
128
+ expect(rsp.results.last[:status]).to eq 'Unsubscribed'
129
+ expect(rsp.results.last[:attributes]).to include(
130
+ {:name=>"Available Weekends", :value=>"True"}
131
+ )
132
+ end
133
+ it 'reads with a simple filter' do
134
+ stub_describes
135
+ savon.expects(:retrieve).
136
+ with(:message => {
137
+ 'RetrieveRequest' => {
138
+ 'ObjectType' => 'Subscriber',
139
+ 'Properties' => [
140
+ "ID",
141
+ "PartnerKey",
142
+ "CreatedDate",
143
+ "Client.ID",
144
+ "Client.PartnerClientKey",
145
+ "EmailAddress",
146
+ "SubscriberKey",
147
+ "UnsubscribedDate",
148
+ "Status",
149
+ "EmailTypePreference",
150
+ ],
151
+ 'Filter' => {
152
+ 'Property' => 'ID',
153
+ 'SimpleOperator' => 'equals',
154
+ 'Value' => '16234076',
155
+ '@xsi:type' => 'tns:SimpleFilterPart'
156
+ }
157
+ }
158
+ }).
159
+ returns(File.read("#{base}/subscriber.xml"))
160
+
161
+ rsp = client.soap_get('Subscriber', nil,
162
+ 'Property' => 'ID',
163
+ 'SimpleOperator' => 'equals',
164
+ 'Value' => '16234076'
165
+ )
166
+
167
+ expect(rsp.success).to be_true
168
+ expect(rsp.results.count).to eq 1
169
+
170
+ expect(rsp.results.first[:id]).to eq '16234076'
171
+ expect(rsp.results.first[:status]).to eq 'Active'
172
+ expect(rsp.results.first[:attributes]).to include(
173
+ {:name=>"Available Weekends", :value=>"False"}
174
+ )
175
+ end
176
+ it 'reads with a complex filter' do
177
+ stub_describes
178
+ savon.expects(:retrieve).
179
+ with(:message => {
180
+ 'RetrieveRequest' => {
181
+ 'ObjectType' => 'Subscriber',
182
+ 'Properties' => [
183
+ "ID",
184
+ "PartnerKey",
185
+ "CreatedDate",
186
+ "Client.ID",
187
+ "Client.PartnerClientKey",
188
+ "EmailAddress",
189
+ "SubscriberKey",
190
+ "UnsubscribedDate",
191
+ "Status",
192
+ "EmailTypePreference",
193
+ ],
194
+ 'Filter' => {
195
+ 'LeftOperand' => {
196
+ 'Property' => 'ID',
197
+ 'SimpleOperator' => 'equals',
198
+ 'Value' => '16234076',
199
+ '@xsi:type' => 'tns:SimpleFilterPart'
200
+ },
201
+ 'RightOperand' => {
202
+ 'Property' => 'ID',
203
+ 'SimpleOperator' => 'equals',
204
+ 'Value' => '16234077',
205
+ '@xsi:type' => 'tns:SimpleFilterPart'
206
+ },
207
+ 'LogicalOperator' => 'OR',
208
+ '@xsi:type' => 'tns:ComplexFilterPart'
209
+ }
210
+ }
211
+ }).
212
+ returns(File.read("#{base}/subscriber.xml"))
213
+
214
+ rsp = client.soap_get('Subscriber', nil, {
215
+ 'LeftOperand' => {
216
+ 'Property' => 'ID',
217
+ 'SimpleOperator' => 'equals',
218
+ 'Value' => '16234076'
219
+ },
220
+ 'RightOperand' => {
221
+ 'Property' => 'ID',
222
+ 'SimpleOperator' => 'equals',
223
+ 'Value' => '16234077'
224
+ },
225
+ 'LogicalOperator' => 'OR'
226
+ })
227
+
228
+ expect(rsp.success).to be_true
229
+ expect(rsp.results.count).to eq 1
230
+
231
+ expect(rsp.results.first[:id]).to eq '16234076'
232
+ expect(rsp.results.first[:status]).to eq 'Active'
233
+ expect(rsp.results.first[:attributes]).to include(
234
+ {:name=>"Available Weekends", :value=>"False"}
235
+ )
236
+ end
237
+ it 'creates' do
238
+ stub_describes
239
+ savon.expects(:create).
240
+ with(:message => {
241
+ 'Objects' => [{
242
+ 'EmailAddress' => 'fuelsdk@exacttarget.com',
243
+ 'Attributes' => [{
244
+ 'Name' => 'Gender',
245
+ 'Value' => 'M'
246
+ },{
247
+ 'Name' => 'Available Weekends',
248
+ 'Value' => true
249
+ }],
250
+ '@xsi:type' => 'tns:Subscriber'
251
+ }]}).
252
+ returns(File.read("#{base}/created.xml"))
253
+
254
+ rsp = client.soap_post('Subscriber',
255
+ 'EmailAddress' => 'fuelsdk@exacttarget.com',
256
+ 'Gender' => 'M',
257
+ 'Available Weekends' => true
258
+ )
259
+ expect(rsp.success).to be_true
260
+ expect(rsp.results.first[:new_id]).to eq '37576181'
261
+ end
262
+ it 'updates' do
263
+ stub_describes
264
+ savon.expects(:update).
265
+ with(:message => {
266
+ 'Objects' => [{
267
+ 'EmailAddress' => 'fuelsdk@exacttarget.com',
268
+ 'Attributes' => [{
269
+ 'Name' => 'Gender',
270
+ 'Value' => 'M'
271
+ },{
272
+ 'Name' => 'Available Weekends',
273
+ 'Value' => true
274
+ }],
275
+ '@xsi:type' => 'tns:Subscriber'
276
+ }]}).
277
+ returns(File.read("#{base}/updated.xml"))
278
+
279
+ rsp = client.soap_put('Subscriber',
280
+ 'EmailAddress' => 'fuelsdk@exacttarget.com',
281
+ 'Gender' => 'M',
282
+ 'Available Weekends' => true
283
+ )
284
+ expect(rsp.success).to be_true
285
+ expect(rsp.results.first).to include(
286
+ :status_code => "OK",
287
+ :status_message => "Updated Subscriber."
288
+ )
289
+ expect(rsp.results.first[:object][:id]).to eq '16234076'
290
+ expect(rsp.results.first[:object][:attributes]).to include(
291
+ {:name => "Available Weekends", :value => true}
292
+ )
293
+ end
294
+ it 'deletes' do
295
+ stub_describes
296
+ savon.expects(:delete).
297
+ with(:message => {
298
+ 'Objects' => [{
299
+ 'EmailAddress' => 'fuelsdk@exacttarget.com',
300
+ 'Attributes' => [{
301
+ 'Name' => 'Gender',
302
+ 'Value' => 'M'
303
+ },{
304
+ 'Name' => 'Available Weekends',
305
+ 'Value' => true
306
+ }],
307
+ '@xsi:type' => 'tns:Subscriber'
308
+ }]}).
309
+ returns(File.read("#{base}/deleted.xml"))
310
+
311
+ rsp = client.soap_delete('Subscriber',
312
+ 'EmailAddress' => 'fuelsdk@exacttarget.com',
313
+ 'Gender' => 'M',
314
+ 'Available Weekends' => true
315
+ )
316
+ expect(rsp.success).to be_true
317
+ expect(rsp.results.first).to include(
318
+ :status_code => "OK",
319
+ :status_message => "Subscriber deleted"
320
+ )
321
+ end
322
+ end