stormpath-sdk 1.0.0.beta.5 → 1.0.0.beta.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -85,7 +85,7 @@ describe Stormpath::Resource::Directory, :vcr do
85
85
  expect(created_account.username).to eq(account.username)
86
86
  expect(created_account).to eq(account)
87
87
  expect(created_account.status).to eq("ENABLED")
88
- expect(created_account.email_verification_token.href).not_to be
88
+ expect(created_account.email_verification_token).not_to be
89
89
  end
90
90
  end
91
91
 
@@ -108,7 +108,6 @@ describe Stormpath::Resource::Directory, :vcr do
108
108
  end
109
109
 
110
110
  context 'with registration workflow but set it to false on account creation' do
111
-
112
111
  let(:created_account_with_reg_workflow) { test_directory_with_verification.create_account account, false }
113
112
 
114
113
  after do
@@ -120,9 +119,8 @@ describe Stormpath::Resource::Directory, :vcr do
120
119
  expect(created_account_with_reg_workflow.username).to eq(account.username)
121
120
  expect(created_account_with_reg_workflow).to eq(account)
122
121
  expect(created_account_with_reg_workflow.status).to eq("ENABLED")
123
- expect(created_account_with_reg_workflow.email_verification_token.href).not_to be
122
+ expect(created_account_with_reg_workflow.email_verification_token).not_to be
124
123
  end
125
-
126
124
  end
127
125
 
128
126
  end
data/spec/spec_helper.rb CHANGED
@@ -21,7 +21,7 @@ VCR.configure do |c|
21
21
  c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
22
22
  c.hook_into :webmock
23
23
  c.configure_rspec_metadata!
24
- c.ignore_request { |r| HIJACK_HTTP_REQUESTS_WITH_VCR != true }
24
+ c.ignore_request { |r| HIJACK_HTTP_REQUESTS_WITH_VCR == false }
25
25
  end
26
26
 
27
27
  module Stormpath
@@ -55,12 +55,16 @@ module Stormpath
55
55
  end
56
56
 
57
57
  def test_api_key
58
- Stormpath::ApiKey.new test_api_key_id,
59
- test_api_key_secret
58
+ Stormpath::ApiKey.new test_api_key_id, test_api_key_secret
60
59
  end
61
60
 
62
61
  def test_api_client
63
- Stormpath::Client.new api_key: test_api_key
62
+ @test_api_client ||= Stormpath::Client.new api_key: test_api_key
63
+ end
64
+
65
+ def get_cache_data href
66
+ data_store = test_api_client.send :data_store
67
+ data_store.send :cache_for, href
64
68
  end
65
69
 
66
70
  def test_missing_env_vars
@@ -0,0 +1,391 @@
1
+ shared_examples_for 'account_custom_data' do
2
+ context 'account' do
3
+ let(:custom_data_storage) do
4
+ directory.accounts.create username: "jlpicard",
5
+ email: "capt@enterprise.com",
6
+ givenName: "Jean-Luc",
7
+ surname: "Picard",
8
+ password: "uGhd%a8Kl!"
9
+ end
10
+
11
+ let(:custom_data_storage_w_nested_custom_data) do
12
+ directory.accounts.create username: "jlpicard",
13
+ email: "capt@enterprise.com",
14
+ given_name: "Jean-Luc",
15
+ surname: "Picard",
16
+ password: "uGhd%a8Kl!",
17
+ custom_data: {
18
+ rank: "Captain",
19
+ favorite_drink: "Earl Grey Tea",
20
+ favoriteDrink: "Camelized Tea"
21
+ }
22
+ end
23
+
24
+ let(:reloaded_custom_data_storage) do
25
+ test_api_client.accounts.get custom_data_storage.href
26
+ end
27
+
28
+ let(:reloaded_custom_data_storage_2) do
29
+ test_api_client.accounts.get custom_data_storage.href
30
+ end
31
+
32
+ it_behaves_like 'custom_data_storage'
33
+ end
34
+ end
35
+
36
+ shared_examples_for 'group_custom_data' do
37
+ context 'group' do
38
+ let(:custom_data_storage) do
39
+ directory.groups.create name: 'test_group'
40
+ end
41
+
42
+ let(:custom_data_storage_w_nested_custom_data) do
43
+ directory.groups.create name: "Jean",
44
+ description: "Capital Group",
45
+ custom_data: {
46
+ rank: "Captain",
47
+ favorite_drink: "Earl Grey Tea",
48
+ favoriteDrink: "Camelized Tea"
49
+ }
50
+ end
51
+
52
+ let(:reloaded_custom_data_storage) do
53
+ test_api_client.groups.get custom_data_storage.href
54
+ end
55
+
56
+ let(:reloaded_custom_data_storage_2) do
57
+ test_api_client.groups.get custom_data_storage.href
58
+ end
59
+
60
+ it_behaves_like 'custom_data_storage'
61
+ end
62
+ end
63
+
64
+ RESERVED_FIELDS = %w( createdAt modifiedAt meta spMeta spmeta ionMeta ionmeta )
65
+
66
+ shared_examples_for 'custom_data_storage' do
67
+
68
+ it 'read reserved data' do
69
+ expect(custom_data_storage.custom_data["href"]).not_to eq(nil)
70
+ expect(custom_data_storage.custom_data["createdAt"]).not_to eq(nil)
71
+ expect(custom_data_storage.custom_data["modifiedAt"]).not_to eq(nil)
72
+ end
73
+
74
+ RESERVED_FIELDS.each do |reserved_field|
75
+ it "set reserved data #{reserved_field} should raise error" do
76
+ custom_data_storage.custom_data[reserved_field] = 12
77
+ expect{ custom_data_storage.custom_data.save }.to raise_error
78
+ end
79
+ end
80
+
81
+ it 'should save properly when custom data is nested on creation' do
82
+ expect(custom_data_storage_w_nested_custom_data.custom_data["rank"]).to eq("Captain")
83
+ expect(custom_data_storage_w_nested_custom_data.custom_data["favorite_drink"]).to eq("Earl Grey Tea")
84
+ expect(custom_data_storage_w_nested_custom_data.custom_data["favoriteDrink"]).to eq("Camelized Tea")
85
+ end
86
+
87
+ it 'set custom data' do
88
+ custom_data_storage.custom_data[:rank] = "Captain"
89
+ expect(custom_data_storage.custom_data[:rank]).to eq("Captain")
90
+ custom_data_storage.custom_data.save
91
+ expect(reloaded_custom_data_storage.custom_data[:rank]).to eq("Captain")
92
+ end
93
+
94
+ it 'set nested custom data' do
95
+ custom_data_storage.custom_data[:special_rank] = "Captain"
96
+ custom_data_storage.custom_data[:permissions] = {"crew_quarters" => "93-601"}
97
+ expect(custom_data_storage.custom_data[:permissions]).to eq({"crew_quarters" => "93-601"})
98
+ custom_data_storage.custom_data.save
99
+ expect(reloaded_custom_data_storage.custom_data[:special_rank]).to eq("Captain")
100
+ expect(reloaded_custom_data_storage.custom_data[:permissions]).to eq({"crew_quarters" => "93-601"})
101
+ end
102
+
103
+ it 'not raise errors when saving a empty properties array' do
104
+ custom_data_storage.custom_data.save
105
+ end
106
+
107
+ it 'trigger custom data saving on custom_data_storage.save' do
108
+ custom_data_storage.custom_data[:rank] = "Captain"
109
+ custom_data_storage.save
110
+ expect(reloaded_custom_data_storage.custom_data[:rank]).to eq("Captain")
111
+ end
112
+
113
+ it 'trigger custom data saving on custom_data_storage.save with complex custom data' do
114
+ custom_data_storage.custom_data[:permissions] = {"crew_quarters" => "93-601"}
115
+ custom_data_storage.save
116
+ expect(reloaded_custom_data_storage.custom_data[:permissions]).to eq({"crew_quarters" => "93-601"})
117
+ end
118
+
119
+ it 'update custom data through custom_data_storage.save, cache should be cleared' do
120
+ custom_data_storage.custom_data[:permissions] = {"crew_quarters" => "93-601"}
121
+ custom_data_storage.custom_data.save
122
+
123
+ expect(reloaded_custom_data_storage.custom_data[:permissions]).to eq({"crew_quarters" => "93-601"})
124
+
125
+ reloaded_custom_data_storage.custom_data[:permissions] = {"crew_quarters" => "601-93"}
126
+
127
+ reloaded_custom_data_storage.save
128
+ expect(reloaded_custom_data_storage_2.custom_data[:permissions]).to eq({"crew_quarters" => "601-93"})
129
+ end
130
+
131
+ it 'first level keys can be saved as symbols or strings, they will default to the same (saved as strings)' do
132
+ custom_data_storage.custom_data[:permissions] = "Drive the boat"
133
+ expect(custom_data_storage.custom_data[:permissions]).to eq("Drive the boat");
134
+ expect(custom_data_storage.custom_data["permissions"]).to eq(custom_data_storage.custom_data[:permissions])
135
+
136
+ custom_data_storage.custom_data.save
137
+ expect(custom_data_storage.custom_data[:permissions]).to eq("Drive the boat");
138
+ expect(custom_data_storage.custom_data["permissions"]).to eq(custom_data_storage.custom_data[:permissions])
139
+ end
140
+
141
+ it "one shouldn't save deeply nested keys as symbols, as on return from the server they will be strings" do
142
+ custom_data_storage.custom_data[:permissions] = { driving_privelage: "Boat", can_swim: true }
143
+ expect(custom_data_storage.custom_data[:permissions]).to eq({ driving_privelage: "Boat", can_swim: true })
144
+ custom_data_storage.custom_data.save
145
+ expect(custom_data_storage.custom_data[:permissions]).to eq({ "driving_privelage" => "Boat", "can_swim" => true })
146
+ expect(custom_data_storage.custom_data[:permissions]).not_to eq({ driving_privelage: "Boat", can_swim: true })
147
+ end
148
+
149
+ it 'delete all custom data and rebind without reloading' do
150
+ custom_data_storage.custom_data["a_map"] = {the_key: "this is the value"}
151
+ custom_data_storage.custom_data.save
152
+
153
+ expect(custom_data_storage.custom_data["a_map"]).to eq({"the_key" => "this is the value"})
154
+
155
+ custom_data_storage.custom_data.delete("a_map")
156
+ custom_data_storage.custom_data.save
157
+
158
+ expect(custom_data_storage.custom_data["a_map"]).to be_nil
159
+
160
+ custom_data_storage.custom_data["rank"] = "Captain"
161
+ custom_data_storage.custom_data.save
162
+
163
+ expect(custom_data_storage.custom_data["rank"]).to eq("Captain")
164
+
165
+ custom_data_storage.custom_data.delete
166
+
167
+ expect(custom_data_storage.custom_data["a_map"]).to be_nil
168
+ expect(custom_data_storage.custom_data["rank"]).to be_nil
169
+
170
+ custom_data_storage.custom_data['new_stuff'] = "the value"
171
+ custom_data_storage.custom_data.save
172
+
173
+ expect(custom_data_storage.custom_data["new_stuff"]).to eq("the value")
174
+ custom_data_storage.custom_data.delete("new_stuff")
175
+
176
+ custom_data_storage.custom_data.save
177
+
178
+ expect(custom_data_storage.custom_data["new_stuff"]).to be_nil
179
+ end
180
+
181
+ it 'delete all custom data and rebind without reloading through custom_data_storage#save' do
182
+ custom_data_storage.custom_data["a_map"] = {"the_key" => "this is the value"}
183
+ custom_data_storage.save
184
+
185
+ expect(custom_data_storage.custom_data["a_map"]).to eq({"the_key" => "this is the value"})
186
+
187
+ custom_data_storage.custom_data.delete("a_map")
188
+ custom_data_storage.custom_data.save
189
+
190
+ expect(custom_data_storage.custom_data["a_map"]).to be_nil
191
+
192
+ custom_data_storage.custom_data["rank"] = "Captain"
193
+ custom_data_storage.save
194
+
195
+ expect(custom_data_storage.custom_data["rank"]).to eq("Captain")
196
+
197
+ custom_data_storage.custom_data.delete
198
+
199
+ expect(custom_data_storage.custom_data["a_map"]).to be_nil
200
+ expect(custom_data_storage.custom_data["rank"]).to be_nil
201
+
202
+ custom_data_storage.custom_data['new_stuff'] = "the value"
203
+ custom_data_storage.save
204
+
205
+ expect(custom_data_storage.custom_data["new_stuff"]).to eq("the value")
206
+
207
+ custom_data_storage.custom_data.delete("new_stuff")
208
+ custom_data_storage.custom_data.save
209
+
210
+ expect(custom_data_storage.custom_data["new_stuff"]).to be_nil
211
+ end
212
+
213
+ it 'delete all custom data' do
214
+ custom_data_storage.custom_data[:rank] = "Captain"
215
+ custom_data_storage.custom_data.save
216
+ expect(custom_data_storage.custom_data[:rank]).to eq("Captain")
217
+ custom_data_storage.custom_data.delete
218
+ expect(reloaded_custom_data_storage.custom_data[:rank]).to eq(nil)
219
+ end
220
+
221
+ it 'delete all custom data and re-add new custom data' do
222
+ custom_data_storage.custom_data[:rank] = "Captain"
223
+
224
+ custom_data_storage.custom_data.save
225
+
226
+ expect(custom_data_storage.custom_data[:rank]).to eq("Captain")
227
+
228
+ custom_data_storage.custom_data.delete
229
+
230
+ expect(reloaded_custom_data_storage.custom_data[:rank]).to eq(nil)
231
+
232
+ reloaded_custom_data_storage.custom_data[:rank] = "Pilot"
233
+
234
+ reloaded_custom_data_storage.custom_data.save
235
+
236
+ expect(reloaded_custom_data_storage.custom_data[:rank]).to eq("Pilot")
237
+
238
+ expect(reloaded_custom_data_storage_2.custom_data[:rank]).to eq("Pilot")
239
+ end
240
+
241
+ it "shouldn't be the same if the key is lowercased or camelcased" do
242
+
243
+ favorite_drink = "Earl Grey Tea";
244
+ custom_data_storage.custom_data["favorite_drink"] = favorite_drink
245
+
246
+ expect(custom_data_storage.custom_data["favorite_drink"]).to eq(favorite_drink)
247
+ expect(custom_data_storage.custom_data["favoriteDrink"]).to be_nil
248
+
249
+ custom_data_storage.custom_data.save
250
+
251
+ expect(custom_data_storage.custom_data["favorite_drink"]).to eq(favorite_drink)
252
+ expect(custom_data_storage.custom_data["favoriteDrink"]).to be_nil
253
+
254
+ custom_data_storage.custom_data.delete("favorite_drink")
255
+
256
+ expect(custom_data_storage.custom_data["favorite_drink"]).to be_nil
257
+ expect(custom_data_storage.custom_data["favoriteDrink"]).to be_nil
258
+
259
+ custom_data_storage.custom_data.save
260
+
261
+ expect(custom_data_storage.custom_data["favorite_drink"]).to be_nil
262
+ expect(custom_data_storage.custom_data["favoriteDrink"]).to be_nil
263
+ end
264
+
265
+ it 'delete a specific custom data field' do
266
+ custom_data_storage.custom_data[:rank] = "Captain"
267
+ custom_data_storage.custom_data["favorite_drink"] = "Earl Grey Tea"
268
+ custom_data_storage.custom_data.save
269
+
270
+ custom_data_storage.custom_data.delete(:rank)
271
+ custom_data_storage.custom_data.save
272
+
273
+ expect(reloaded_custom_data_storage.custom_data[:rank]).to eq(nil)
274
+
275
+ expect(reloaded_custom_data_storage.custom_data["favorite_drink"]).to eq("Earl Grey Tea")
276
+ end
277
+
278
+
279
+ it '#has_key?' do
280
+ expect(custom_data_storage.custom_data.has_key? "createdAt").to be_true
281
+ expect(custom_data_storage.custom_data.has_key? "created_at").not_to be_true
282
+ end
283
+
284
+ it '#include?' do
285
+ expect(custom_data_storage.custom_data.include? "createdAt").to be_true
286
+ expect(custom_data_storage.custom_data.include? "created_at").not_to be_true
287
+ end
288
+
289
+ it '#has_value?' do
290
+ custom_data_storage.custom_data[:rank] = "Captain"
291
+ custom_data_storage.custom_data.save
292
+ expect(reloaded_custom_data_storage.custom_data.has_value? "Captain").to be_true
293
+ end
294
+
295
+ it '#store' do
296
+ custom_data_storage.custom_data.store(:rank, "Captain")
297
+ custom_data_storage.custom_data.save
298
+ expect(reloaded_custom_data_storage.custom_data[:rank]).to eq("Captain")
299
+ end
300
+
301
+ it '#store with a snakecased key' do
302
+ custom_data_storage.custom_data.store(:super_rank, "Captain")
303
+
304
+ expect(custom_data_storage.custom_data[:super_rank]).to eq("Captain")
305
+ expect(custom_data_storage.custom_data["super_rank"]).to eq("Captain")
306
+
307
+ expect(custom_data_storage.custom_data[:superRank]).to be_nil
308
+ expect(custom_data_storage.custom_data["superRank"]).to be_nil
309
+
310
+ custom_data_storage.custom_data.save
311
+
312
+ expect(custom_data_storage.custom_data[:super_rank]).to eq("Captain")
313
+ expect(custom_data_storage.custom_data["super_rank"]).to eq("Captain")
314
+
315
+ expect(custom_data_storage.custom_data[:superRank]).to be_nil
316
+ expect(custom_data_storage.custom_data["superRank"]).to be_nil
317
+ end
318
+
319
+ it '#store with a lower camelCase key' do
320
+ custom_data_storage.custom_data.store(:superRank, "Captain")
321
+
322
+ expect(custom_data_storage.custom_data[:superRank]).to eq("Captain")
323
+ expect(custom_data_storage.custom_data["superRank"]).to eq("Captain")
324
+
325
+ expect(custom_data_storage.custom_data[:super_rank]).to be_nil
326
+ expect(custom_data_storage.custom_data["super_rank"]).to be_nil
327
+
328
+ custom_data_storage.custom_data.save
329
+
330
+ expect(custom_data_storage.custom_data[:superRank]).to eq("Captain")
331
+ expect(custom_data_storage.custom_data["superRank"]).to eq("Captain")
332
+
333
+ expect(custom_data_storage.custom_data[:super_rank]).to be_nil
334
+ expect(custom_data_storage.custom_data["super_rank"]).to be_nil
335
+ end
336
+
337
+ it '#keys' do
338
+ expect(custom_data_storage.custom_data.keys).to be_kind_of(Array)
339
+ expect(custom_data_storage.custom_data.keys).to have_at_least(3).items
340
+ expect(custom_data_storage.custom_data.keys).to eq(custom_data_storage.custom_data.properties.keys)
341
+ end
342
+
343
+ it '#values' do
344
+ custom_data_storage.custom_data[:permissions] = {"crew_quarters" => "93-601"}
345
+ custom_data_storage.custom_data.save
346
+ expect(reloaded_custom_data_storage.custom_data.values).to include({"crew_quarters" => "93-601"})
347
+ expect(reloaded_custom_data_storage.custom_data.values).to eq(reloaded_custom_data_storage.custom_data.properties.values)
348
+ end
349
+
350
+ it 'inner property holders clearing properly' do
351
+ expect(deleted_properties).to have(0).items
352
+
353
+ custom_data_storage.custom_data[:permissions] = 'NOOP'
354
+
355
+ custom_data_storage.custom_data.save
356
+
357
+ expect(custom_data_storage.custom_data[:permissions]).to eq("NOOP")
358
+ custom_data_storage.custom_data.delete(:permissions)
359
+ expect(custom_data_storage.custom_data[:permissions]).to be_nil
360
+
361
+ expect(deleted_properties).to have(1).items
362
+
363
+ custom_data_storage.custom_data.save
364
+
365
+ expect(custom_data_storage.custom_data[:permissions]).to be_nil
366
+ expect(deleted_properties).to have(0).items
367
+
368
+ custom_data_storage.custom_data[:permissions] = 'NOOP'
369
+ expect(custom_data_storage.custom_data[:permissions]).to eq("NOOP")
370
+
371
+ custom_data_storage.custom_data.delete(:permissions)
372
+ expect(custom_data_storage.custom_data[:permissions]).to be_nil
373
+
374
+ expect(deleted_properties).to have(1).items
375
+
376
+ if custom_data_storage.is_a? Stormpath::Resource::Account
377
+ custom_data_storage.given_name = "Capt"
378
+ else
379
+ custom_data_storage.name = "Capt"
380
+ end
381
+
382
+ custom_data_storage.save
383
+
384
+ expect(custom_data_storage.custom_data[:permissions]).to be_nil
385
+ expect(deleted_properties).to have(0).items
386
+ end
387
+
388
+ def deleted_properties
389
+ custom_data_storage.custom_data.instance_variable_get("@deleted_properties")
390
+ end
391
+ end
@@ -1,7 +1,7 @@
1
1
  module Stormpath
2
2
  module Test
3
3
  class ResourceFactory
4
- URL_PREFIX = 'https://api.stormpath.com/v1'
4
+ URL_PREFIX = Stormpath::DataStore::DEFAULT_BASE_URL
5
5
 
6
6
  def initialize
7
7
  @id_count = 0