quiz_api_client 4.3.0 → 4.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -48
  3. data/Rakefile +0 -29
  4. data/lib/quiz_api_client/services/courses_service.rb +37 -0
  5. data/lib/quiz_api_client/version.rb +1 -1
  6. data/lib/quiz_api_client.rb +5 -0
  7. data/spec/quiz_api_client_spec.rb +7 -0
  8. data/spec/services/courses_service_spec.rb +103 -0
  9. data/spec/spec_helper.rb +1 -25
  10. metadata +11 -86
  11. data/spec/contracts/interaction_types_service_spec.rb +0 -22
  12. data/spec/contracts/item_analyses_service_spec.rb +0 -59
  13. data/spec/contracts/items_service_spec.rb +0 -59
  14. data/spec/contracts/qti_imports_service_spec.rb +0 -34
  15. data/spec/contracts/quiz_clone_job_service_spec.rb +0 -20
  16. data/spec/contracts/quiz_clone_jobs_service_spec.rb +0 -21
  17. data/spec/contracts/quiz_entries_service_spec.rb +0 -125
  18. data/spec/contracts/quiz_service_spec.rb +0 -68
  19. data/spec/contracts/quiz_session_events_service_spec.rb +0 -30
  20. data/spec/contracts/quiz_session_result_service_spec.rb +0 -42
  21. data/spec/contracts/quiz_session_service_spec.rb +0 -56
  22. data/spec/contracts/quiz_sessions_service_spec.rb +0 -28
  23. data/spec/contracts/quiz_sync_job_service_spec.rb +0 -21
  24. data/spec/contracts/quiz_sync_jobs_service_spec.rb +0 -21
  25. data/spec/contracts/quizzes_service_spec.rb +0 -80
  26. data/spec/contracts/session_item_results_service_spec.rb +0 -60
  27. data/spec/contracts/session_items_service_spec.rb +0 -21
  28. data/spec/contracts/shared_banks_spec.rb +0 -366
  29. data/spec/contracts/shared_examples/http_delete_example.rb +0 -56
  30. data/spec/contracts/shared_examples/http_get_example.rb +0 -139
  31. data/spec/contracts/shared_examples/http_patch_example.rb +0 -60
  32. data/spec/contracts/shared_examples/http_post_example.rb +0 -68
  33. data/spec/contracts/shared_examples/http_put_example.rb +0 -60
  34. data/spec/support/pact_config.rb +0 -64
  35. data/spec/support/pact_helper.rb +0 -19
@@ -1,366 +0,0 @@
1
- PERMISSION_READ = 'read'.freeze
2
- PERMISSION_EDIT = 'edit'.freeze
3
- PERMISSION_REMOVED_ACCESS = 'removed_access'.freeze
4
-
5
- # These uuids are defined on the shared_provider_states.rb file in the quiz_api repo
6
- USER_1_UUID_FROM_QUIZ_API = 'd4614a35-a951-46e7-9b5e-48dbadc60158'.freeze
7
- USER_2_UUID_FROM_QUIZ_API = 'a51c9338-b5ee-4417-aaec-2561cb42f92e'.freeze
8
- USER_3_UUID_FROM_QUIZ_API = '71bf7db1-46bc-4769-a015-fa10819a2807'.freeze
9
-
10
- describe QuizApiClient::Services::SharedBanks, :pact do
11
- include PactHelper
12
-
13
- #
14
- ## GET REQUESTS
15
- #
16
-
17
- # Owner of the bank, not shared calling GET shared_banks API
18
- it_behaves_like 'a http get request to quiz_api collection endpoint' do
19
- let(:service_name) { :shared_banks }
20
- let(:request_description) { 'a request to retrieve the list of shared banks' }
21
- let(:quizzes_api_path) { '/api/banks/1/shared_banks' }
22
- let(:provider_state) { 'an user_1 item bank not shared' }
23
- let(:scope) { 'quiz.build' }
24
- let(:user) { USER_1_UUID_FROM_QUIZ_API }
25
- let(:params) { { bank_id: 1 } }
26
- # Returns an empty array
27
- let(:response_body) { [] }
28
- end
29
-
30
- # Owner of the bank, shared with uuid_2, calling GET shared_bank API
31
- it_behaves_like 'a http get request to quiz_api collection endpoint' do
32
- let(:service_name) { :shared_banks }
33
- let(:request_description) { 'a request to get shared banks by bank owner' }
34
- let(:provider_state) { 'an user_1 item bank shared with user_2' }
35
- let(:quizzes_api_path) { '/api/banks/1/shared_banks' }
36
- let(:scope) { 'quiz.build' }
37
- let(:user) { USER_1_UUID_FROM_QUIZ_API }
38
- let(:params) { { bank_id: 1 } }
39
- let(:response_body) do
40
- Pact.each_like(
41
- id: Pact.like('1'),
42
- bank_id: Pact.like('1'),
43
- user_uuid: Pact.like(USER_2_UUID_FROM_QUIZ_API),
44
- permission: PERMISSION_EDIT
45
- )
46
- end
47
- end
48
-
49
- # Not owner of the bank calling GET shared_bank API
50
- it_behaves_like 'a http get request to quiz_api collection endpoint' do
51
- let(:service_name) { :shared_banks }
52
- let(:request_description) { 'a request to get shared banks by shared user' }
53
- let(:provider_state) { 'an user_1 item bank shared with user_2' }
54
- let(:quizzes_api_path) { '/api/banks/1/shared_banks' }
55
- let(:scope) { 'quiz.build' }
56
- let(:user) { USER_2_UUID_FROM_QUIZ_API }
57
- let(:params) { { bank_id: 1 } }
58
- let(:response_body) do
59
- Pact.each_like(
60
- id: Pact.like('1'),
61
- bank_id: Pact.like('1'),
62
- user_uuid: Pact.like(USER_2_UUID_FROM_QUIZ_API),
63
- permission: PERMISSION_EDIT
64
- )
65
- end
66
- end
67
-
68
- # User without permission on bank calling GET shared_bank API
69
- it_behaves_like 'a http get request to quiz_api collection endpoint' do
70
- let(:service_name) { :shared_banks }
71
- let(:request_description) { 'a request to get shared banks by an user without permissions' }
72
- let(:provider_state) { 'an user_1 item bank shared with user_2' }
73
- let(:quizzes_api_path) { '/api/banks/1/shared_banks' }
74
- let(:scope) { 'quiz.build' }
75
- let(:status) { 401 }
76
- let(:user) { USER_3_UUID_FROM_QUIZ_API }
77
- let(:params) { { bank_id: 1 } }
78
- let(:response_body) { nil }
79
- end
80
-
81
- # Authorized user requesting an invalid bank
82
- it_behaves_like 'a http get request to quiz_api collection endpoint' do
83
- let(:service_name) { :shared_banks }
84
- let(:request_description) { 'a request to get shared banks of an invalid bank by an user' }
85
- let(:provider_state) { 'an user_1 item bank shared with user_2' }
86
- let(:quizzes_api_path) { '/api/banks/22222/shared_banks' }
87
- let(:scope) { 'quiz.build' }
88
- let(:status) { 401 }
89
- let(:user) { USER_2_UUID_FROM_QUIZ_API }
90
- let(:params) { { bank_id: '22222' } }
91
- let(:response_body) { nil }
92
- end
93
-
94
- # an authorized user using an deleted item bank ID,
95
- it_behaves_like 'a http get request to quiz_api collection endpoint' do
96
- let(:service_name) { :shared_banks }
97
- let(:request_description) { 'a request to get shared banks of a deleted bank by an authorized user' }
98
- let(:provider_state) { 'an user_1 item bank shared with user_2, then deleted the bank' }
99
- let(:quizzes_api_path) { '/api/banks/1/shared_banks' }
100
- let(:scope) { 'quiz.build' }
101
- let(:status) { 401 }
102
- let(:user) { USER_2_UUID_FROM_QUIZ_API }
103
- let(:params) { { bank_id: '1' } }
104
- let(:response_body) { nil }
105
- end
106
-
107
- # an user that is no longer active (commented out as there's currently no way of deactivating an user in quiz_api)
108
- # it_behaves_like 'a http get request to quiz_api collection endpoint' do
109
- # let(:service_name) { :shared_banks }
110
- # let(:request_description) { 'a request to get shared banks of a deactivated user' }
111
- # let(:provider_state) { 'an user_1 item bank shared with user_2, then deactivated the user_2' }
112
- # let(:quizzes_api_path) { '/api/banks/1/shared_banks' }
113
- # let(:scope) { 'quiz.build' }
114
- # let(:status) { 403 } # Changed as per conversation with @jcrystal
115
- # let(:user) { USER_2_UUID_FROM_QUIZ_API }
116
- # let(:params) { { bank_id: '1' } }
117
- # let(:response_body) { nil }
118
- # end
119
-
120
- #
121
- ## POST REQUESTS
122
- #
123
-
124
- # Owner of the bank shares the bank with user_2
125
- it_behaves_like 'a http post request to quiz_api' do
126
- let(:service_name) { :shared_banks }
127
- let(:request_description) { 'a request to add an user to a shared bank' }
128
- let(:provider_state) { 'an user_1 item bank not shared' }
129
- let(:quizzes_api_path) { '/api/banks/1/shared_banks' }
130
- let(:scope) { 'quiz.build' }
131
- let(:user) { USER_1_UUID_FROM_QUIZ_API }
132
- params = {
133
- id: 1,
134
- bank_id: 1,
135
- user_uuid: USER_2_UUID_FROM_QUIZ_API,
136
- permission: PERMISSION_EDIT
137
- }
138
- let(:params) do
139
- params
140
- end
141
- let(:body) do
142
- params
143
- end
144
- let(:response_body) do
145
- {
146
- id: Pact.like('1'),
147
- bank_id: Pact.like('1'),
148
- user_uuid: Pact.like(USER_2_UUID_FROM_QUIZ_API),
149
- permission: PERMISSION_EDIT
150
- }
151
- end
152
- end
153
-
154
- # attempt to use an invalid permssion
155
- it_behaves_like 'a http post request to quiz_api' do
156
- let(:service_name) { :shared_banks }
157
- let(:request_description) { 'a request to add an user to a shared bank by a user with invalid permissions' }
158
- let(:provider_state) { 'an user_1 item bank not shared' }
159
- let(:quizzes_api_path) { '/api/banks/1/shared_banks' }
160
- let(:scope) { 'quiz.build' }
161
- let(:status) { 422 }
162
- let(:user) { USER_1_UUID_FROM_QUIZ_API }
163
- params = {
164
- id: 1,
165
- bank_id: 1,
166
- user_uuid: USER_2_UUID_FROM_QUIZ_API,
167
- permission: 'THIS_IS_INVALID'
168
- }
169
- let(:params) do
170
- params
171
- end
172
- let(:body) do
173
- params
174
- end
175
- let(:response_body) do
176
- {
177
- error: 'Validation failed: Permission is not included in the list',
178
- errors: Pact.each_like(
179
- error_type: Pact.like(''),
180
- message: Pact.like('')
181
- )
182
- }
183
- end
184
- end
185
-
186
- # User without permissions attempts to update the bank
187
- it_behaves_like 'a http post request to quiz_api' do
188
- let(:service_name) { :shared_banks }
189
- let(:request_description) { 'a request to add an user to a shared bank by a user without edit permissions' }
190
- let(:provider_state) { 'an user_1 item bank not shared' }
191
- let(:quizzes_api_path) { '/api/banks/1/shared_banks' }
192
- let(:scope) { 'quiz.build' }
193
- let(:status) { 401 }
194
- let(:user) { USER_2_UUID_FROM_QUIZ_API }
195
- params = {
196
- id: 1,
197
- bank_id: 1,
198
- user_uuid: USER_2_UUID_FROM_QUIZ_API,
199
- permission: PERMISSION_EDIT
200
- }
201
- let(:params) do
202
- params
203
- end
204
- let(:body) do
205
- params
206
- end
207
- let(:response_body) { nil }
208
- end
209
-
210
- # user_2 with edit permissions shares the bank
211
- it_behaves_like 'a http post request to quiz_api' do
212
- let(:service_name) { :shared_banks }
213
- let(:request_description) { 'a request to add an user to a shared bank by a user with edit permissions' }
214
- let(:provider_state) { 'an user_1 item bank shared with user_2' }
215
- let(:quizzes_api_path) { '/api/banks/1/shared_banks' }
216
- let(:scope) { 'quiz.build' }
217
- let(:user) { USER_2_UUID_FROM_QUIZ_API }
218
- params = {
219
- id: 1,
220
- bank_id: 1,
221
- user_uuid: USER_3_UUID_FROM_QUIZ_API,
222
- permission: PERMISSION_EDIT
223
- }
224
- let(:params) do
225
- params
226
- end
227
- let(:body) do
228
- params
229
- end
230
- let(:response_body) do
231
- {
232
- id: Pact.like('1'),
233
- bank_id: Pact.like('1'),
234
- user_uuid: Pact.like(USER_2_UUID_FROM_QUIZ_API),
235
- permission: PERMISSION_EDIT
236
- }
237
- end
238
- end
239
-
240
- # user_2 with edit permissions on one bank attempts to add themself to another bank
241
- it_behaves_like 'a http post request to quiz_api' do
242
- let(:service_name) { :shared_banks }
243
- let(:request_description) { 'a req to add an user to a bank by a user with edit permissions on a different bank' }
244
- let(:provider_state) { 'an user_1 item bank shared with user_2, user_3 with own bank' }
245
- let(:quizzes_api_path) { '/api/banks/2/shared_banks' }
246
- let(:scope) { 'quiz.build' }
247
- let(:status) { 401 }
248
- let(:user) { USER_2_UUID_FROM_QUIZ_API }
249
- params = {
250
- id: 1,
251
- bank_id: 2,
252
- user_uuid: USER_2_UUID_FROM_QUIZ_API,
253
- permission: PERMISSION_EDIT
254
- }
255
- let(:params) do
256
- params
257
- end
258
- let(:body) do
259
- params
260
- end
261
- let(:response_body) { nil }
262
- end
263
-
264
- #
265
- ## PUT REQUESTS
266
- #
267
-
268
- # a user removing permissions
269
- it_behaves_like 'a http put request to quiz_api' do
270
- let(:service_name) { :shared_banks }
271
- let(:request_description) { 'a request to update a shared bank' }
272
- let(:provider_state) { 'an user_1 item bank shared with user_2' }
273
- let(:quizzes_api_path) { '/api/banks/1/shared_banks/1' }
274
- let(:scope) { 'quiz.build' }
275
- let(:user) { USER_1_UUID_FROM_QUIZ_API }
276
- params = {
277
- bank_id: 1,
278
- shared_bank_id: 1,
279
- user_uuid: USER_2_UUID_FROM_QUIZ_API,
280
- permission: PERMISSION_REMOVED_ACCESS
281
- }
282
- let(:params) do
283
- params
284
- end
285
- let(:body) do
286
- tmp_body = params.clone
287
- # shared_bank_id is not really a parameter so remove it
288
- tmp_body.delete(:shared_bank_id)
289
- tmp_body
290
- end
291
- let(:response_body) do
292
- {
293
- id: Pact.like('1'),
294
- bank_id: Pact.like('1'),
295
- user_uuid: Pact.like(USER_2_UUID_FROM_QUIZ_API),
296
- permission: PERMISSION_REMOVED_ACCESS
297
- }
298
- end
299
- end
300
-
301
- # a user uses an invalid permission
302
- it_behaves_like 'a http put request to quiz_api' do
303
- let(:service_name) { :shared_banks }
304
- let(:request_description) { 'a request to update a shared bank with invalid permission' }
305
- let(:provider_state) { 'an user_1 item bank shared with user_2' }
306
- let(:quizzes_api_path) { '/api/banks/1/shared_banks/1' }
307
- let(:scope) { 'quiz.build' }
308
- let(:status) { 422 }
309
- let(:user) { USER_1_UUID_FROM_QUIZ_API }
310
- params = {
311
- bank_id: 1,
312
- shared_bank_id: 1,
313
- user_uuid: USER_2_UUID_FROM_QUIZ_API,
314
- permission: 'THIS_IS_INVALID'
315
- }
316
- let(:params) do
317
- params
318
- end
319
- let(:body) do
320
- tmp_body = params.clone
321
- # shared_bank_id is not really a parameter so remove it
322
- tmp_body.delete(:shared_bank_id)
323
- tmp_body
324
- end
325
- let(:response_body) do
326
- {
327
- errors: {}
328
- }
329
- end
330
- end
331
-
332
- # a user with edit permissions on antoher bank try to update permissions
333
- it_behaves_like 'a http put request to quiz_api' do
334
- let(:service_name) { :shared_banks }
335
- let(:request_description) { 'a request to update a shared bank by a user with permissions on a different bank' }
336
- let(:provider_state) { 'an user_1 item bank shared with user_2, user_3 with own bank' }
337
- let(:quizzes_api_path) { '/api/banks/2/shared_banks/2' }
338
- let(:scope) { 'quiz.build' }
339
- let(:status) { 401 }
340
- let(:user) { USER_2_UUID_FROM_QUIZ_API }
341
- params = {
342
- bank_id: 2,
343
- shared_bank_id: 2,
344
- user_uuid: USER_2_UUID_FROM_QUIZ_API,
345
- permission: PERMISSION_EDIT
346
- }
347
- let(:params) do
348
- params
349
- end
350
- let(:body) do
351
- tmp_body = params.clone
352
- # shared_bank_id is not really a parameter so remove it
353
- tmp_body.delete(:shared_bank_id)
354
- tmp_body
355
- end
356
- let(:response_body) do
357
- {
358
- error: 'Invalid Auth Action: auth action failed user_can_edit_bank?',
359
- errors: Pact.each_like(
360
- error_type: Pact.like(''),
361
- message: Pact.like('')
362
- )
363
- }
364
- end
365
- end
366
- end
@@ -1,56 +0,0 @@
1
- shared_examples 'a http delete request to quiz_api' do
2
- let(:quizzes_api_path) { raise 'Override in spec' }
3
- let(:consumer_key) { 'consumer key' }
4
- let(:consumer_request_id) { 'consumer request id' }
5
- let(:host) { 'localhost:1234' }
6
- let(:shared_secret) { 'secret' }
7
- let(:scope) { raise 'Override in spec' }
8
- let(:user) { nil }
9
- let(:resource_id) { nil }
10
- let(:response_body) { nil }
11
- let(:service_name) { raise 'Override in spec' }
12
- let(:status) { 204 }
13
- let(:provider_state) { raise 'Override in spec' }
14
- let(:params) { raise 'Override in spec' }
15
- let(:request_description) { raise 'Override in spec (must be unique!)' }
16
-
17
- let(:client) do
18
- QuizApiClient::Client.new(
19
- consumer_key: consumer_key,
20
- consumer_request_id: consumer_request_id,
21
- host: host,
22
- shared_secret: shared_secret,
23
- protocol: 'http'
24
- )
25
- end
26
-
27
- context 'deleting a resource' do
28
- let(:token) do
29
- client.jwt_service.grant_permission(
30
- exp: token_expiration_one_year,
31
- scope: scope,
32
- uuid: user,
33
- resource_id: resource_id
34
- )
35
- end
36
-
37
- before do
38
- response = { status: status }
39
- response[:body] = response_body if response_body
40
- quiz_api
41
- .given(provider_state)
42
- .upon_receiving(request_description)
43
- .with(
44
- method: :delete,
45
- path: quizzes_api_path,
46
- headers: headers(token)
47
- )
48
- .will_respond_with(response)
49
- end
50
-
51
- it 'verifies the request is valid' do
52
- result = client.send(service_name).destroy(token: token, params: params)
53
- expect(result).to be_truthy
54
- end
55
- end
56
- end
@@ -1,139 +0,0 @@
1
- shared_context 'http get' do
2
- let(:quizzes_api_path) { raise 'Override in spec' }
3
- let(:consumer_key) { 'consumer key' }
4
- let(:consumer_request_id) { 'consumer request id' }
5
- let(:host) { 'localhost:1234' }
6
- let(:shared_secret) { 'secret' }
7
- let(:scope) { raise 'Override in spec' }
8
- let(:resource_id) { nil }
9
- let(:response_headers) { { 'Content-Type' => 'application/json; charset=utf-8' } }
10
- let(:response_body) { raise 'Override in spec' }
11
- let(:service_name) { raise 'Override in spec' }
12
- let(:status) { 200 }
13
- let(:provider_state) { raise 'Override in spec' }
14
- let(:user) { nil }
15
- let(:params) { raise 'Override in spec' }
16
- let(:query_params) { {} }
17
- let(:request_description) { raise 'Override in spec (must be unique!)' }
18
-
19
- let(:client) do
20
- QuizApiClient::Client.new(
21
- consumer_key: consumer_key,
22
- consumer_request_id: consumer_request_id,
23
- host: host,
24
- shared_secret: shared_secret,
25
- protocol: 'http'
26
- )
27
- end
28
- end
29
-
30
- shared_examples 'a http get request to quiz_api' do
31
- include_context 'http get'
32
-
33
- context 'retrieving a single resource' do
34
- let(:token) do
35
- client.jwt_service.grant_permission(
36
- exp: token_expiration_one_year,
37
- scope: scope,
38
- uuid: user,
39
- resource_id: resource_id
40
- )
41
- end
42
-
43
- before do
44
- quiz_api
45
- .given(provider_state)
46
- .upon_receiving(request_description)
47
- .with(
48
- method: :get,
49
- path: quizzes_api_path,
50
- headers: headers(token),
51
- query: query_params
52
- )
53
- .will_respond_with(
54
- status: status,
55
- headers: response_headers,
56
- body: response_body
57
- )
58
- end
59
-
60
- it 'verifies the request is valid' do
61
- result = client.send(service_name).show(token: token, params: params)
62
- expect(result).to be_truthy
63
- end
64
- end
65
- end
66
-
67
- shared_examples 'a http get request to quiz_api collection endpoint' do
68
- include_context 'http get'
69
-
70
- context 'retrieving a list of resources' do
71
- let(:token) do
72
- client.jwt_service.grant_permission(
73
- exp: token_expiration_one_year,
74
- scope: scope,
75
- uuid: user,
76
- resource_id: resource_id
77
- )
78
- end
79
-
80
- before do
81
- quiz_api
82
- .given(provider_state)
83
- .upon_receiving(request_description)
84
- .with(
85
- method: :get,
86
- path: quizzes_api_path,
87
- headers: headers(token),
88
- query: query_params
89
- )
90
- .will_respond_with(
91
- status: status,
92
- headers: response_headers,
93
- body: response_body
94
- )
95
- end
96
-
97
- it 'verifies the request is valid' do
98
- result = client.send(service_name).list(token: token, params: params)
99
- expect(result).to be_truthy
100
- end
101
- end
102
- end
103
-
104
- shared_examples 'a http get only request to quiz_api' do
105
- include_context 'http get'
106
-
107
- context 'retrieving a single resource' do
108
- let(:token) do
109
- client.jwt_service.grant_permission(
110
- exp: token_expiration_one_year,
111
- scope: scope,
112
- uuid: user,
113
- resource_id: resource_id
114
- )
115
- end
116
-
117
- before do
118
- quiz_api
119
- .given(provider_state)
120
- .upon_receiving(request_description)
121
- .with(
122
- method: :get,
123
- path: quizzes_api_path,
124
- headers: headers(token),
125
- query: query_params
126
- )
127
- .will_respond_with(
128
- status: status,
129
- headers: response_headers,
130
- body: response_body
131
- )
132
- end
133
-
134
- it 'verifies the request is valid' do
135
- result = client.send(service_name).get(token: token, params: params)
136
- expect(result).to be_truthy
137
- end
138
- end
139
- end
@@ -1,60 +0,0 @@
1
- shared_examples 'a http patch request to quiz_api' do
2
- let(:quizzes_api_path) { raise 'Override in spec' }
3
- let(:consumer_key) { 'consumer key' }
4
- let(:consumer_request_id) { 'consumer request id' }
5
- let(:host) { 'localhost:1234' }
6
- let(:shared_secret) { 'secret' }
7
- let(:scope) { raise 'Override in spec' }
8
- let(:user) { nil }
9
- let(:resource_id) { nil }
10
- let(:response_body) { raise 'Override in spec' }
11
- let(:service_name) { raise 'Override in spec' }
12
- let(:status) { 200 }
13
- let(:provider_state) { raise 'Override in spec' }
14
- let(:params) { raise 'Override in spec' }
15
- let(:body) { raise 'Override in spec' }
16
- let(:request_description) { raise 'Override in spec (must be unique!)' }
17
-
18
- let(:client) do
19
- QuizApiClient::Client.new(
20
- consumer_key: consumer_key,
21
- consumer_request_id: consumer_request_id,
22
- host: host,
23
- shared_secret: shared_secret,
24
- protocol: 'http'
25
- )
26
- end
27
-
28
- context 'updating a resource' do
29
- let(:token) do
30
- client.jwt_service.grant_permission(
31
- exp: token_expiration_one_year,
32
- scope: scope,
33
- uuid: user,
34
- resource_id: resource_id
35
- )
36
- end
37
-
38
- before do
39
- quiz_api
40
- .given(provider_state)
41
- .upon_receiving(request_description)
42
- .with(
43
- method: :patch,
44
- path: quizzes_api_path,
45
- headers: headers(token),
46
- body: body
47
- )
48
- .will_respond_with(
49
- status: status,
50
- headers: { 'Content-Type' => 'application/json; charset=utf-8' },
51
- body: response_body
52
- )
53
- end
54
-
55
- it 'verifies the request is valid' do
56
- result = client.send(service_name).update(token: token, params: params)
57
- expect(result).to be_truthy
58
- end
59
- end
60
- end
@@ -1,68 +0,0 @@
1
- shared_examples 'a http post request to quiz_api' do
2
- let(:quizzes_api_path) { raise 'Override in spec' }
3
- let(:consumer_key) { 'consumer key' }
4
- let(:consumer_request_id) { 'consumer request id' }
5
- let(:host) { 'localhost:1234' }
6
- let(:shared_secret) { 'secret' }
7
- let(:scope) { raise 'Override in spec' }
8
- let(:user) { nil }
9
- let(:resource_id) { nil }
10
- let(:response_body) { raise 'Override in spec' }
11
- let(:service_name) { raise 'Override in spec' }
12
- let(:status) { 201 }
13
- let(:provider_state) { raise 'Override in spec' }
14
- let(:params) { raise 'Override in spec' }
15
- let(:body) { raise 'Override in spec' }
16
- let(:request_description) { raise 'Override in spec (must be unique!)' }
17
- let(:batch) { false }
18
-
19
- let(:client) do
20
- QuizApiClient::Client.new(
21
- consumer_key: consumer_key,
22
- consumer_request_id: consumer_request_id,
23
- host: host,
24
- shared_secret: shared_secret,
25
- protocol: 'http'
26
- )
27
- end
28
-
29
- context 'creating a new resource' do
30
- let(:token) do
31
- client.jwt_service.grant_permission(
32
- exp: token_expiration_one_year,
33
- scope: scope,
34
- uuid: user,
35
- resource_id: resource_id
36
- )
37
- end
38
-
39
- before do
40
- quiz_api
41
- .given(provider_state)
42
- .upon_receiving(request_description)
43
- .with(
44
- method: :post,
45
- path: quizzes_api_path,
46
- headers: headers(token),
47
- body: body
48
- )
49
- .will_respond_with(
50
- status: status,
51
- headers: { 'Content-Type' => 'application/json; charset=utf-8' },
52
- body: response_body
53
- )
54
- end
55
-
56
- it 'verifies the request is valid' do
57
- service = client.send(service_name)
58
-
59
- result = if batch
60
- service.create_batch(token: token, body: params)
61
- else
62
- service.create(token: token, params: params)
63
- end
64
-
65
- expect(result).to be_truthy
66
- end
67
- end
68
- end