badgeapi 0.3.10 → 1.0.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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rubocop.yml +147 -0
  4. data/README.md +44 -12
  5. data/Rakefile +24 -11
  6. data/badgeapi.gemspec +23 -22
  7. data/lib/badgeapi/badge.rb +24 -27
  8. data/lib/badgeapi/badgeapi_object.rb +160 -147
  9. data/lib/badgeapi/collection.rb +6 -9
  10. data/lib/badgeapi/errors/api_error.rb +3 -4
  11. data/lib/badgeapi/errors/badgeapi_error.rb +15 -15
  12. data/lib/badgeapi/errors/invalid_request_error.rb +3 -4
  13. data/lib/badgeapi/recipient.rb +13 -16
  14. data/lib/badgeapi/version.rb +1 -1
  15. data/lib/badgeapi.rb +13 -15
  16. data/test/badge/badge_test.rb +71 -150
  17. data/test/badgeapi_test.rb +4 -0
  18. data/test/collection/collection_test.rb +43 -77
  19. data/test/fixtures/badge_all.yml +113 -0
  20. data/test/fixtures/{bad_api_key.yml → badge_all_bad_user.yml} +14 -13
  21. data/test/fixtures/{all_badges_bad_user.yml → badge_all_badges_bad_user.yml} +16 -57
  22. data/test/fixtures/badge_all_expanded.yml +184 -0
  23. data/test/fixtures/badge_all_from_collection.yml +52 -0
  24. data/test/fixtures/badge_all_issued.yml +99 -0
  25. data/test/fixtures/{all_badges_limited.yml → badge_all_limited.yml} +10 -8
  26. data/test/fixtures/{create_badge.yml → badge_create.yml} +20 -16
  27. data/test/fixtures/{create_new_badge_failure.yml → badge_create_new.yml} +28 -22
  28. data/test/fixtures/badge_destroy.yml +147 -0
  29. data/test/fixtures/badge_destroy_error.yml +147 -0
  30. data/test/fixtures/badge_error.yml +54 -6
  31. data/test/fixtures/{issue_badge_to_bad_user.yml → badge_issue_to_bad_user.yml} +8 -6
  32. data/test/fixtures/badge_issue_to_user.yml +107 -0
  33. data/test/fixtures/{issue_badge_to_user_with_library_card.yml → badge_issue_to_user_with_library_card.yml} +21 -17
  34. data/test/fixtures/{one_badge.yml → badge_one.yml} +10 -8
  35. data/test/fixtures/{one_badge_expanded.yml → badge_one_expanded.yml} +11 -9
  36. data/test/fixtures/badge_requirements.yml +150 -105
  37. data/test/fixtures/badge_revoke_from_user.yml +107 -0
  38. data/test/fixtures/{update_badge_via_update.yml → badge_update_via_update.yml} +31 -25
  39. data/test/fixtures/{update_badge_via_update_slug_history.yml → badge_update_via_update_slug_history.yml} +41 -33
  40. data/test/fixtures/{all_collection.yml → collection_all.yml} +11 -9
  41. data/test/fixtures/collection_all_expanded.yml +123 -0
  42. data/test/fixtures/{all_collection_limit.yml → collection_all_limit.yml} +10 -8
  43. data/test/fixtures/{create_collection.yml → collection_create.yml} +20 -16
  44. data/test/fixtures/{create_new_collection_failure.yml → collection_create_new_failure.yml} +36 -28
  45. data/test/fixtures/{destroy_collection.yml → collection_destroy.yml} +36 -28
  46. data/test/fixtures/{destroy_collection_error.yml → collection_destroy_error.yml} +36 -28
  47. data/test/fixtures/collection_error.yml +108 -12
  48. data/test/fixtures/{one_collection.yml → collection_one.yml} +10 -8
  49. data/test/fixtures/collection_one_expanded.yml +106 -0
  50. data/test/fixtures/{update_collection.yml → collection_update.yml} +40 -32
  51. data/test/fixtures/{update_collection_via_update.yml → collection_update_via_update.yml} +30 -24
  52. data/test/fixtures/{bad_Recipietn_request.yml → recipient_bad_user_data.yml} +26 -22
  53. data/test/fixtures/recipient_with_badges.yml +20 -108
  54. data/test/fixtures/recipient_with_badges_unicard.yml +151 -8
  55. data/test/recipient/recipient_test.rb +11 -29
  56. metadata +69 -73
  57. data/test/fixtures/all_badges.yml +0 -121
  58. data/test/fixtures/all_badges_expanded.yml +0 -196
  59. data/test/fixtures/all_badges_from_collection.yml +0 -52
  60. data/test/fixtures/all_badges_issued.yml +0 -430
  61. data/test/fixtures/all_collection_expanded.yml +0 -131
  62. data/test/fixtures/bad_Recipient.yml +0 -183
  63. data/test/fixtures/destroy_badge.yml +0 -277
  64. data/test/fixtures/destroy_badge_error.yml +0 -231
  65. data/test/fixtures/issue_already_owned_badge.yml +0 -49
  66. data/test/fixtures/issue_badge_to_user.yml +0 -199
  67. data/test/fixtures/one_collection_expanded.yml +0 -104
  68. data/test/fixtures/revoke_badge_from_user.yml +0 -199
  69. data/test/fixtures/revoke_badge_not_issued.yml +0 -49
@@ -3,6 +3,10 @@ require './test/test_helper'
3
3
 
4
4
  class BadgeapiBadgeTest < MiniTest::Test
5
5
 
6
+ Badgeapi.api_base = 'https://gamification-api.dev/v1'
7
+ Badgeapi.ssl_ca_cert='/Users/tomskarbek/.tunnelss/ca/cert.pem'
8
+ Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
9
+
6
10
  def self.test_order
7
11
  :alpha
8
12
  end
@@ -20,163 +24,122 @@ class BadgeapiBadgeTest < MiniTest::Test
20
24
  end
21
25
 
22
26
  def test_it_returns_back_a_single_badge
23
- VCR.use_cassette('one_badge', :record => :all) do
24
- Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
25
-
27
+ VCR.use_cassette('badge_one') do
26
28
  badge = Badgeapi::Badge.find(1)
27
29
  assert_equal Badgeapi::Badge, badge.class
28
30
 
29
- assert_equal "book-worm", badge.id
30
- assert_equal "Book Worm", badge.name
31
- assert_equal "You have loaned out over 25 books. Nice going!", badge.description
32
- assert_equal "Loan out 25 books", badge.requirements
33
- assert_equal "You must like books...", badge.hint
34
- #assert_equal "http://openbadges.org/wp-content/themes/openbadges2/media/images/content-background.png", badge.image
35
- assert_equal "library", badge.collection_id
36
- assert_equal "bronze", badge.level
37
- assert_equal 25, badge.points
31
+ assert_kind_of String, badge.id
32
+ assert_kind_of String, badge.name
33
+ assert_kind_of String, badge.description
34
+ assert_kind_of String, badge.requirements
35
+ assert_kind_of String, badge.hint
36
+ assert_kind_of String, badge.image
37
+ assert_kind_of String, badge.collection_id
38
+ assert_kind_of String, badge.level
39
+ assert_kind_of Integer, badge.points
38
40
  assert_equal false, badge.auto_issue
39
- assert_equal "badge", badge.object
40
- assert_equal "live", badge.status
41
+ assert_kind_of String, badge.object
42
+ assert_kind_of String, badge.status
41
43
  end
42
44
  end
43
45
 
44
46
  def test_it_returns_back_a_single_badge_expanded
45
- VCR.use_cassette('one_badge_expanded', :record => :all) do
46
- Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
47
-
47
+ VCR.use_cassette('badge_one_expanded') do
48
48
  badge = Badgeapi::Badge.find(1, expand: "collection")
49
49
  assert_equal Badgeapi::Badge, badge.class
50
50
 
51
- assert_equal "book-worm", badge.id
52
- assert_equal "Book Worm", badge.name
53
- assert_equal "You have loaned out over 25 books. Nice going!", badge.description
54
- assert_equal "Loan out 25 books", badge.requirements
55
- assert_equal "You must like books...", badge.hint
56
- #assert_equal "http://openbadges.org/wp-content/themes/openbadges2/media/images/content-background.png", badge.image
57
- assert_equal "library", badge.collection_id
51
+ assert_kind_of String, badge.id
52
+ assert_kind_of String, badge.name
53
+ assert_kind_of String, badge.description
54
+ assert_kind_of String, badge.requirements
55
+ assert_kind_of String, badge.hint
56
+ assert_kind_of String, badge.image
57
+ assert_kind_of String, badge.collection_id
58
58
 
59
59
  assert_equal Badgeapi::Collection, badge.collection.class
60
- assert_equal "Library", badge.collection.name
60
+ assert_kind_of String, badge.collection.name
61
61
  end
62
62
  end
63
63
 
64
64
  def test_it_returns_back_all_badges_issued_to_user
65
- VCR.use_cassette('all_badges_issued', :record => :all) do
66
- Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
65
+ VCR.use_cassette('badge_all_issued') do
67
66
  result = Badgeapi::Badge.all(user: "t.skarbek-wazynski@lancaster.ac.uk")
68
67
 
69
- # Make sure we got all the badges
70
- assert_equal 1, result.length
71
-
72
- # Make sure that the JSON was parsed
73
68
  assert result.kind_of?(Array)
74
69
  assert result.first.kind_of?(Badgeapi::Badge)
75
70
 
76
71
  result = Badgeapi::Badge.all(user: "0043181") #uni card number for t.skarbek-wazynski
77
72
 
78
- # Make sure we got all the badges
79
- assert_equal 1, result.length
80
-
81
- # Make sure that the JSON was parsed
82
73
  assert result.kind_of?(Array)
83
74
  assert result.first.kind_of?(Badgeapi::Badge)
84
75
  end
85
76
  end
86
77
 
87
78
  def test_it_raises_error_for_bad_user
88
- VCR.use_cassette('all_badges_bad_user', :record => :all) do
89
- Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
79
+ VCR.use_cassette('badge_all_bad_user') do
90
80
  assert_raises(Badgeapi::InvalidRequestError) { Badgeapi::Badge.all(user: "t.skarbek-wazynski") }
91
81
  end
92
82
  end
93
83
 
94
84
  def test_it_raises_error_for_non_existing_user
95
- VCR.use_cassette('all_badges_bad_user', :record => :all) do
96
- Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
85
+ VCR.use_cassette('badge_all_badges_bad_user') do
97
86
  assert_raises(Badgeapi::InvalidRequestError) { Badgeapi::Badge.all(user: "t.skarbek-wazynsky@lancaster.ac.uk") }
98
87
  assert_raises(Badgeapi::InvalidRequestError) { Badgeapi::Badge.all(user: "081897144451") }
99
88
  end
100
89
  end
101
90
 
102
91
  def test_it_returns_back_all_badges
103
- VCR.use_cassette('all_badges', :record => :all) do
104
- Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
92
+ VCR.use_cassette('badge_all') do
105
93
  result = Badgeapi::Badge.all
106
94
 
107
- # Make sure we got all the badges
108
- assert_equal 6, result.length
109
-
110
- # Make sure that the JSON was parsed
111
95
  assert result.kind_of?(Array)
112
96
  assert result.first.kind_of?(Badgeapi::Badge)
113
97
  end
114
98
  end
115
99
 
116
100
  def test_it_returns_back_all_badges_exapanded
117
- VCR.use_cassette('all_badges_expanded', :record => :all) do
118
- Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
101
+ VCR.use_cassette('badge_all_expanded') do
119
102
  result = Badgeapi::Badge.all(expand: "collection")
120
103
 
121
- # Make sure we got all the badges
122
- assert_equal 6, result.length
123
-
124
- # Make sure that the JSON was parsed
125
104
  assert result.kind_of?(Array)
126
105
  assert result.first.kind_of?(Badgeapi::Badge)
127
106
  assert result.first.collection.kind_of?(Badgeapi::Collection)
128
-
129
- #assert_not_nil result['collection']
130
107
  end
131
108
  end
132
109
 
133
110
  def test_it_errors_all_badges_exapanded
134
- VCR.use_cassette('all_badges_expanded', :record => :all) do
135
- Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
136
-
111
+ VCR.use_cassette('badge_all_expanded') do
137
112
  assert_raises(Badgeapi::InvalidRequestError) { Badgeapi::Badge.all(expand: "monkey") }
138
113
  end
139
114
  end
140
115
 
141
116
  def test_it_returns_back_all_badges_from_collection
142
- VCR.use_cassette('all_badges_from_collection') do
143
- Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
117
+ VCR.use_cassette('badge_all_from_collection') do
144
118
  result = Badgeapi::Badge.all(collection_id: 2)
145
119
 
146
- # Make sure we got all the badges
147
- assert_equal 2, result.length
148
-
149
- # Make sure that the JSON was parsed
150
120
  assert result.kind_of?(Array)
151
121
  assert result.first.kind_of?(Badgeapi::Badge)
152
122
  end
153
123
  end
154
124
 
155
125
  def test_all_limit
156
- VCR.use_cassette('all_badges_limited', :record => :all) do
157
- Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
126
+ VCR.use_cassette('badge_all_limited') do
158
127
  result = Badgeapi::Badge.all(limit: 1)
159
128
 
160
- # Make sure we got all the badges
161
129
  assert_equal 1, result.length
162
-
163
- # Make sure that the JSON was parsed
164
130
  assert result.kind_of?(Array)
165
131
  assert result.first.kind_of?(Badgeapi::Badge)
166
132
  end
167
133
  end
168
134
 
169
135
  def test_badges_raise_errors
170
- VCR.use_cassette('badge_error', :record => :all) do
171
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
172
- assert_raises(Badgeapi::InvalidRequestError) { Badgeapi::Badge.find(27) }
136
+ VCR.use_cassette('badge_error') do
137
+ assert_raises(Badgeapi::InvalidRequestError) { Badgeapi::Badge.find("safasuf2") }
173
138
  end
174
139
  end
175
140
 
176
141
  def test_create_a_new_badge
177
- VCR.use_cassette('create_badge', :record => :all) do
178
- Badgeapi.api_key = 'c9cde524238644fa93393159e5e9ad87'
179
-
142
+ VCR.use_cassette('badge_create') do
180
143
  badge = Badgeapi::Badge.create(
181
144
  name: "Create Badge Test",
182
145
  description: "This is a new badge",
@@ -192,8 +155,6 @@ class BadgeapiBadgeTest < MiniTest::Test
192
155
  assert_equal "This is a new badge", badge.description
193
156
  assert_equal "You need to love the Badge API", badge.requirements
194
157
  assert_equal "Love us..", badge.hint
195
- #assert_equal "http://example.org/badge.png", badge.image
196
- assert_equal "library", badge.collection_id
197
158
  assert_equal true, badge.auto_issue
198
159
 
199
160
  Badgeapi::Badge.destroy(badge.id)
@@ -201,9 +162,7 @@ class BadgeapiBadgeTest < MiniTest::Test
201
162
  end
202
163
 
203
164
  def test_create_new_badge_failure
204
- VCR.use_cassette('create_new_badge_failure', :record => :all) do
205
- Badgeapi.api_key = 'c9cde524238644fa93393159e5e9ad87'
206
-
165
+ VCR.use_cassette('badge_create_new') do
207
166
  badge = Badgeapi::Badge.create(
208
167
  name: "Create Badge Test Destroy",
209
168
  description: "This is a new badge",
@@ -229,9 +188,7 @@ class BadgeapiBadgeTest < MiniTest::Test
229
188
  end
230
189
 
231
190
  def test_badge_destroy
232
- VCR.use_cassette('destroy_badge', :record => :all) do
233
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
234
-
191
+ VCR.use_cassette('badge_destroy') do
235
192
  badge = Badgeapi::Badge.create(
236
193
  name: "Create Badge for Destroy",
237
194
  description: "This is a new badge",
@@ -251,9 +208,7 @@ class BadgeapiBadgeTest < MiniTest::Test
251
208
  end
252
209
 
253
210
  def test_badge_destroy_error
254
- VCR.use_cassette('destroy_badge_error', :record => :all) do
255
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
256
-
211
+ VCR.use_cassette('badge_destroy_error') do
257
212
  badge = Badgeapi::Badge.create(
258
213
  name: "Create Badge for Destroy",
259
214
  description: "This is a new badge",
@@ -263,16 +218,14 @@ class BadgeapiBadgeTest < MiniTest::Test
263
218
  level: "bronze"
264
219
  )
265
220
 
266
- destroyed_badge = Badgeapi::Badge.destroy(badge.id)
221
+ Badgeapi::Badge.destroy(badge.id)
267
222
 
268
223
  assert_raises(Badgeapi::InvalidRequestError) { Badgeapi::Badge.destroy(badge.id) }
269
224
  end
270
225
  end
271
226
 
272
227
  def test_update_badge_via_update
273
- VCR.use_cassette('update_badge_via_update', :record => :all) do
274
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
275
-
228
+ VCR.use_cassette('badge_update_via_update') do
276
229
  badge = Badgeapi::Badge.create(
277
230
  name: "Create Badge for update",
278
231
  description: "This is a new badge",
@@ -287,7 +240,6 @@ class BadgeapiBadgeTest < MiniTest::Test
287
240
  description: "Updated Description",
288
241
  requirements: "Updated Requirements",
289
242
  hint: "Updated Hint",
290
- collection_id: "trim-trail",
291
243
  status: "live",
292
244
  )
293
245
 
@@ -295,7 +247,6 @@ class BadgeapiBadgeTest < MiniTest::Test
295
247
  assert_equal "Updated Description", updated_badge.description
296
248
  assert_equal "Updated Requirements", updated_badge.requirements
297
249
  assert_equal "Updated Hint", updated_badge.hint
298
- assert_equal "trim-trail", updated_badge.collection_id
299
250
  assert_equal "live", updated_badge.status
300
251
 
301
252
  Badgeapi::Badge.destroy(badge.id)
@@ -303,9 +254,7 @@ class BadgeapiBadgeTest < MiniTest::Test
303
254
  end
304
255
 
305
256
  def test_update_badge_via_update_with_slug_update_and_history
306
- VCR.use_cassette('update_badge_via_update_slug_history', :record => :all) do
307
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
308
-
257
+ VCR.use_cassette('badge_update_via_update_slug_history') do
309
258
  badge = Badgeapi::Badge.create(
310
259
  name: "Create Badge for update",
311
260
  description: "This is a new badge",
@@ -323,7 +272,6 @@ class BadgeapiBadgeTest < MiniTest::Test
323
272
  description: "Updated Description",
324
273
  requirements: "Updated Requirements",
325
274
  hint: "Updated Hint",
326
- collection_id: "trim-trail"
327
275
  )
328
276
 
329
277
  assert_equal "updated-badge", updated_badge.id
@@ -331,7 +279,6 @@ class BadgeapiBadgeTest < MiniTest::Test
331
279
  assert_equal "Updated Description", updated_badge.description
332
280
  assert_equal "Updated Requirements", updated_badge.requirements
333
281
  assert_equal "Updated Hint", updated_badge.hint
334
- assert_equal "trim-trail", updated_badge.collection_id
335
282
 
336
283
  using_old_slug = Badgeapi::Badge.find(badge.id)
337
284
 
@@ -342,15 +289,12 @@ class BadgeapiBadgeTest < MiniTest::Test
342
289
  end
343
290
 
344
291
  def test_should_issue_badge_with_email
345
- VCR.use_cassette('issue_badge_to_user', :record => :all) do
346
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
347
-
292
+ VCR.use_cassette('badge_issue_to_user') do
348
293
  recipient = Badgeapi::Badge.issue(
349
294
  "mega-book-worm",
350
295
  recipient: "t.skarbek-wazynski@lancaster.ac.uk"
351
296
  )
352
297
 
353
- assert_equal 2, recipient.badges.length
354
298
  assert recipient.kind_of?(Badgeapi::Recipient)
355
299
  assert recipient.badges.first.kind_of?(Badgeapi::Badge)
356
300
 
@@ -358,44 +302,32 @@ class BadgeapiBadgeTest < MiniTest::Test
358
302
  "mega-book-worm",
359
303
  recipient: "t.skarbek-wazynski@lancaster.ac.uk"
360
304
  )
361
-
362
- assert_equal 1, recipient.badges.length
363
305
  end
364
306
  end
365
307
 
366
308
  def test_should_revoke_badge_with_email
367
- VCR.use_cassette('revoke_badge_from_user', :record => :all) do
368
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
369
-
309
+ VCR.use_cassette('badge_revoke_from_user') do
370
310
  recipient = Badgeapi::Badge.issue(
371
311
  "mega-book-worm",
372
312
  recipient: "t.skarbek-wazynski@lancaster.ac.uk"
373
313
  )
374
314
 
375
- assert_equal 2, recipient.badges.length
376
-
377
315
  recipient = Badgeapi::Badge.revoke(
378
316
  "mega-book-worm",
379
317
  recipient: "t.skarbek-wazynski@lancaster.ac.uk"
380
318
  )
381
319
 
382
- assert_equal 1, recipient.badges.length
383
320
  assert recipient.kind_of?(Badgeapi::Recipient)
384
- assert recipient.badges.first.kind_of?(Badgeapi::Badge)
385
321
  end
386
322
  end
387
323
 
388
324
  def test_should_issue_badge_with_library_card
389
- VCR.use_cassette('issue_badge_to_user_with_library_card', :record => :all) do
390
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
391
-
325
+ VCR.use_cassette('badge_issue_to_user_with_library_card') do
392
326
  recipient = Badgeapi::Badge.issue(
393
327
  3,
394
328
  recipient: "0043181"
395
329
  )
396
330
 
397
-
398
- assert_equal 2, recipient.badges.length
399
331
  assert recipient.kind_of?(Badgeapi::Recipient)
400
332
  assert recipient.badges.first.kind_of?(Badgeapi::Badge)
401
333
 
@@ -403,15 +335,11 @@ class BadgeapiBadgeTest < MiniTest::Test
403
335
  3,
404
336
  recipient: "0043181"
405
337
  )
406
-
407
- assert_equal 1, recipient.badges.length
408
338
  end
409
339
  end
410
340
 
411
341
  def test_should_error_when_user_param_is_bad
412
- VCR.use_cassette('issue_badge_to_bad_user', :record => :all) do
413
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
414
-
342
+ VCR.use_cassette('badge_issue_to_bad_user') do
415
343
  assert_raises(Badgeapi::InvalidRequestError) {
416
344
  Badgeapi::Badge.issue(
417
345
  2,
@@ -421,49 +349,42 @@ class BadgeapiBadgeTest < MiniTest::Test
421
349
  end
422
350
  end
423
351
 
424
- def test_should_error_when_issuing_bad_already_issued
425
- VCR.use_cassette('issue_already_owned_badge', :record => :all) do
426
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
427
-
428
- assert_raises(Badgeapi::InvalidRequestError) {
429
- Badgeapi::Badge.issue(
430
- 1,
431
- recipient: "t.skarbek-wazynski@lancaster.ac.uk"
432
- )
433
- }
434
- end
435
- end
436
-
437
- def test_should_error_when_revoking_badge_not_owned
438
- VCR.use_cassette('revoke_badge_not_issued', :record => :all) do
439
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
440
-
441
- assert_raises(Badgeapi::InvalidRequestError) {
442
- Badgeapi::Badge.revoke(
443
- 3,
444
- recipient: "t.skarbek-wazynski@lancaster.ac.uk"
445
- )
446
- }
447
- end
448
- end
449
-
450
352
  def test_badge_requirements
451
- VCR.use_cassette('badge_requirements', :record => :all) do
452
- Badgeapi.api_key= 'c9cde524238644fa93393159e5e9ad87'
353
+ VCR.use_cassette('badge_requirements') do
354
+ badge = Badgeapi::Badge.create(
355
+ name: "Create Badge",
356
+ description: "This is a new badge",
357
+ requirements: "You need to love the Badge API",
358
+ hint: "Love us..",
359
+ collection_id: 1,
360
+ level: "silver"
361
+ )
362
+
363
+ required_badge = Badgeapi::Badge.create(
364
+ name: "Required Badge",
365
+ description: "This is a new badge",
366
+ requirements: "You need to love the Badge API",
367
+ hint: "Love us..",
368
+ collection_id: 1,
369
+ level: "bronze"
370
+ )
453
371
 
454
- badge = Badgeapi::Badge.find("marathon-man")
455
372
 
456
373
  required_count = badge.required_badges.count
457
374
 
458
- badge = Badgeapi::Badge.add_badge_requirement("marathon-man", "you-trim-trailed")
375
+ badge = Badgeapi::Badge.add_badge_requirement(badge.id, required_badge.id)
459
376
 
460
377
  assert_equal required_count + 1, badge.required_badges.count
461
378
  assert_equal Badgeapi::Badge, badge.required_badges.first.class
462
379
 
463
- badge = Badgeapi::Badge.remove_badge_requirement("marathon-man", "you-trim-trailed")
380
+ badge = Badgeapi::Badge.remove_badge_requirement(badge.id, required_badge.id)
464
381
 
465
382
  assert_equal required_count, badge.required_badges.count
383
+
384
+ Badgeapi::Badge.destroy(badge.id)
385
+ Badgeapi::Badge.destroy(required_badge.id)
386
+
466
387
  end
467
388
  end
468
389
 
469
- end
390
+ end
@@ -3,6 +3,10 @@ require './test/test_helper'
3
3
 
4
4
  class BadgeapiTest < MiniTest::Test
5
5
 
6
+ Badgeapi.api_base = 'https://gamification-api.dev/v1'
7
+ Badgeapi.ssl_ca_cert='/Users/tomskarbek/.tunnelss/ca/cert.pem'
8
+ Badgeapi.api_key = "c9cde524238644fa93393159e5e9ad87"
9
+
6
10
  def test_api_url
7
11
  assert_equal Badgeapi.api_url, 'https://gamification-api.dev/v1'
8
12
  end