quiz_api_client 4.2.1 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -48
- data/Rakefile +0 -29
- data/lib/quiz_api_client/services/courses_service.rb +37 -0
- data/lib/quiz_api_client/services/quiz_clone_jobs_service.rb +11 -0
- data/lib/quiz_api_client/services/quiz_sync_job_service.rb +17 -0
- data/lib/quiz_api_client/services/quiz_sync_jobs_service.rb +16 -0
- data/lib/quiz_api_client/version.rb +1 -1
- data/lib/quiz_api_client.rb +15 -0
- data/spec/quiz_api_client_spec.rb +7 -0
- data/spec/services/courses_service_spec.rb +98 -0
- data/spec/services/quiz_clone_jobs_service_spec.rb +36 -0
- data/spec/services/quiz_sync_job_service_spec.rb +41 -0
- data/spec/services/quiz_sync_jobs_service_spec.rb +77 -0
- data/spec/spec_helper.rb +1 -25
- metadata +11 -76
- data/spec/contracts/interaction_types_service_spec.rb +0 -22
- data/spec/contracts/item_analyses_service_spec.rb +0 -59
- data/spec/contracts/items_service_spec.rb +0 -59
- data/spec/contracts/qti_imports_service_spec.rb +0 -34
- data/spec/contracts/quiz_clone_job_service_spec.rb +0 -20
- data/spec/contracts/quiz_clone_jobs_service_spec.rb +0 -21
- data/spec/contracts/quiz_entries_service_spec.rb +0 -125
- data/spec/contracts/quiz_service_spec.rb +0 -68
- data/spec/contracts/quiz_session_events_service_spec.rb +0 -30
- data/spec/contracts/quiz_session_result_service_spec.rb +0 -42
- data/spec/contracts/quiz_session_service_spec.rb +0 -56
- data/spec/contracts/quiz_sessions_service_spec.rb +0 -28
- data/spec/contracts/quizzes_service_spec.rb +0 -80
- data/spec/contracts/session_item_results_service_spec.rb +0 -60
- data/spec/contracts/session_items_service_spec.rb +0 -21
- data/spec/contracts/shared_banks_spec.rb +0 -366
- data/spec/contracts/shared_examples/http_delete_example.rb +0 -56
- data/spec/contracts/shared_examples/http_get_example.rb +0 -139
- data/spec/contracts/shared_examples/http_patch_example.rb +0 -60
- data/spec/contracts/shared_examples/http_post_example.rb +0 -60
- data/spec/contracts/shared_examples/http_put_example.rb +0 -60
- data/spec/support/pact_config.rb +0 -64
- data/spec/support/pact_helper.rb +0 -19
@@ -1,56 +0,0 @@
|
|
1
|
-
describe QuizApiClient::Services::QuizSessionService, :pact do
|
2
|
-
include PactHelper
|
3
|
-
|
4
|
-
it_behaves_like 'a http get request to quiz_api', testrail_id: %w[3402554] do
|
5
|
-
let(:request_description) { 'a request to retrieve the graded quiz session' }
|
6
|
-
let(:quizzes_api_path) { '/api/quiz_sessions/1' }
|
7
|
-
let(:provider_state) { 'a graded quiz session' }
|
8
|
-
let(:scope) { 'quiz_session.show' }
|
9
|
-
let(:params) { { id: '1' } }
|
10
|
-
let(:resource_id) { '1' }
|
11
|
-
let(:response_body) do
|
12
|
-
{
|
13
|
-
id: Pact.like('1'),
|
14
|
-
account_uuid: Pact.like('cbedd9b0-d1ab-43a9-a3b2-89c3134a722a'),
|
15
|
-
end_at: nil,
|
16
|
-
start_at: Pact.like(''),
|
17
|
-
status: 'graded',
|
18
|
-
metadata: nil,
|
19
|
-
accepted_student_access_code: Pact.like(false),
|
20
|
-
attempt: Pact.like(1),
|
21
|
-
disable_timer: nil,
|
22
|
-
extra_time_in_seconds: nil,
|
23
|
-
timer_multiplier: nil,
|
24
|
-
elapsed_time: Pact.like(3600),
|
25
|
-
allow_backtracking: nil,
|
26
|
-
one_at_a_time_type: nil
|
27
|
-
}
|
28
|
-
end
|
29
|
-
let(:service_name) { :quiz_session_service }
|
30
|
-
end
|
31
|
-
|
32
|
-
it_behaves_like 'a http patch request to quiz_api', testrail_id: %w[3402555] do
|
33
|
-
let(:request_description) { 'a request to update a quiz session' }
|
34
|
-
let(:quizzes_api_path) { '/api/quiz_sessions/1' }
|
35
|
-
let(:provider_state) { 'a quiz session' }
|
36
|
-
let(:scope) { 'quiz_session.update' }
|
37
|
-
let(:attempt) { 2 }
|
38
|
-
let(:params) do
|
39
|
-
{
|
40
|
-
id: '1',
|
41
|
-
attempt: { attempt: 2 }
|
42
|
-
}
|
43
|
-
end
|
44
|
-
let(:resource_id) { '1' }
|
45
|
-
let(:body) { { quiz_session: params } }
|
46
|
-
let(:response_body) do
|
47
|
-
{
|
48
|
-
id: Pact.like('1'),
|
49
|
-
status: 'graded',
|
50
|
-
start_at: Pact.like(''),
|
51
|
-
end_at: Pact.like('')
|
52
|
-
}
|
53
|
-
end
|
54
|
-
let(:service_name) { :quiz_session_service }
|
55
|
-
end
|
56
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
describe QuizApiClient::Services::QuizSessionsService, :pact do
|
2
|
-
include PactHelper
|
3
|
-
|
4
|
-
it_behaves_like 'a http post request to quiz_api', testrail_id: %w[3402556] do
|
5
|
-
let(:request_description) { 'a request to create a quiz session' }
|
6
|
-
let(:provider_state) { 'a quiz' }
|
7
|
-
let(:quiz_id) { 1 }
|
8
|
-
let(:quizzes_api_path) { "/api/quizzes/#{quiz_id}/quiz_sessions" }
|
9
|
-
let(:scope) { 'quiz_session.create' }
|
10
|
-
let(:resource_id) { quiz_id }
|
11
|
-
let(:params) do
|
12
|
-
{
|
13
|
-
quiz_id: quiz_id,
|
14
|
-
attempt: 1
|
15
|
-
}
|
16
|
-
end
|
17
|
-
let(:body) { { quiz_session: params } }
|
18
|
-
let(:response_body) do
|
19
|
-
{
|
20
|
-
id: Pact.like('1'),
|
21
|
-
status: 'pending',
|
22
|
-
start_at: Pact.like(''),
|
23
|
-
end_at: Pact.like('')
|
24
|
-
}
|
25
|
-
end
|
26
|
-
let(:service_name) { :quiz_sessions_service }
|
27
|
-
end
|
28
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
describe QuizApiClient::Services::QuizzesService, :pact do
|
2
|
-
include PactHelper
|
3
|
-
|
4
|
-
it_behaves_like 'a http get request to quiz_api collection endpoint', testrail_id: %w[3402557] do
|
5
|
-
let(:request_description) { 'a request specifying a quiz id' }
|
6
|
-
let(:quizzes_api_path) { '/api/quizzes' }
|
7
|
-
let(:provider_state) { 'a quiz' }
|
8
|
-
let(:scope) { 'quiz.list' }
|
9
|
-
let(:params) { { 'id' => '1' } }
|
10
|
-
let(:query_params) { { 'id' => '1' } }
|
11
|
-
let(:response_body) do
|
12
|
-
[
|
13
|
-
{
|
14
|
-
# TODO: figure out why Pact specs' responses for GET requests from
|
15
|
-
# quiz_api have integers for *ID fields given quiz_api actually returns strings
|
16
|
-
id: Pact.like(1),
|
17
|
-
title: Pact.like('quiz title'),
|
18
|
-
context_id: Pact.like(1),
|
19
|
-
outcome_declaration: nil,
|
20
|
-
session_time_limit_in_seconds: Pact.like(1),
|
21
|
-
quiz_type: nil,
|
22
|
-
minimum_passing_score: nil,
|
23
|
-
lti_resource_id: nil,
|
24
|
-
created_at: Pact.like('2017-06-15T22:14:51.215Z'),
|
25
|
-
updated_at: Pact.like('2017-06-15T22:14:51.215Z'),
|
26
|
-
instructions: Pact.like('quiz instructions'),
|
27
|
-
shuffle_questions: Pact.like(false),
|
28
|
-
shuffle_answers: Pact.like(false),
|
29
|
-
status: 'uninitialized',
|
30
|
-
owner: Pact.like('teacher'),
|
31
|
-
has_time_limit: Pact.like(false),
|
32
|
-
outcome_alignment_set_guid: Pact.like('cbedd9b0-d1ab-43a9-a3b2-89c3134a722a'),
|
33
|
-
one_at_a_time_type: 'question',
|
34
|
-
allow_backtracking: Pact.like(true)
|
35
|
-
}
|
36
|
-
]
|
37
|
-
end
|
38
|
-
let(:service_name) { :quizzes_service }
|
39
|
-
end
|
40
|
-
|
41
|
-
it_behaves_like 'a http post request to quiz_api', testrails_id: %w[3402558] do
|
42
|
-
let(:request_description) { 'a request to create a quiz' }
|
43
|
-
let(:quizzes_api_path) { '/api/quizzes' }
|
44
|
-
let(:provider_state) { 'a context' }
|
45
|
-
let(:scope) { 'quiz.create' }
|
46
|
-
let(:title) { 'Pop Quiz' }
|
47
|
-
let(:instructions) { 'Select the best answer.' }
|
48
|
-
let(:context_id) { '1' }
|
49
|
-
let(:params) do
|
50
|
-
{
|
51
|
-
'title' => title,
|
52
|
-
'instructions' => instructions,
|
53
|
-
'context_id' => context_id
|
54
|
-
}
|
55
|
-
end
|
56
|
-
let(:body) { { quiz: params } }
|
57
|
-
let(:response_body) do
|
58
|
-
{
|
59
|
-
id: Pact.like('1'),
|
60
|
-
title: title,
|
61
|
-
instructions: instructions,
|
62
|
-
context_id: context_id,
|
63
|
-
owner: Pact.like('teacher1'),
|
64
|
-
has_time_limit: Pact.like(false),
|
65
|
-
allow_backtracking: Pact.like(true),
|
66
|
-
one_at_a_time_type: 'none',
|
67
|
-
session_time_limit_in_seconds: 0,
|
68
|
-
outcome_alignment_set_guid: nil,
|
69
|
-
require_student_access_code: Pact.like(false),
|
70
|
-
filter_ip_address: Pact.like(false),
|
71
|
-
shuffle_questions: Pact.like(false),
|
72
|
-
shuffle_answers: Pact.like(false),
|
73
|
-
status: 'uninitialized',
|
74
|
-
student_access_code: nil,
|
75
|
-
filters: Pact.like({})
|
76
|
-
}
|
77
|
-
end
|
78
|
-
let(:service_name) { :quizzes_service }
|
79
|
-
end
|
80
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
describe QuizApiClient::Services::SessionItemResultsService, :pact do
|
2
|
-
include PactHelper
|
3
|
-
it_behaves_like 'a http get request to quiz_api collection endpoint', testrail_id: %w[3402559] do
|
4
|
-
let(:request_description) { 'a request to retrieve a session item result' }
|
5
|
-
let(:quizzes_api_path) { '/api/quiz_sessions/1/results/1/session_item_results' }
|
6
|
-
let(:provider_state) { 'a set of session_item_results' }
|
7
|
-
let(:resource_id) { '1' }
|
8
|
-
let(:scope) { 'quiz_session.results' }
|
9
|
-
let(:params) { { quiz_session_id: '1', quiz_session_result_id: '1' } }
|
10
|
-
let(:response_body) do
|
11
|
-
[
|
12
|
-
{
|
13
|
-
position: Pact.like(1),
|
14
|
-
attempt: Pact.like(1),
|
15
|
-
item_id: Pact.like('1'),
|
16
|
-
graded_at: Pact.like('2017-06-15T22:14:51.215Z'),
|
17
|
-
grading_method: 'autograde',
|
18
|
-
points_possible: Pact.like(1.0),
|
19
|
-
score: Pact.like(1.0),
|
20
|
-
scored_data: {},
|
21
|
-
feedback: {}
|
22
|
-
}
|
23
|
-
]
|
24
|
-
end
|
25
|
-
let(:service_name) { :session_item_results_service }
|
26
|
-
end
|
27
|
-
|
28
|
-
it_behaves_like 'a http get request to quiz_api collection endpoint' do
|
29
|
-
let(:request_description) { 'a request to retrieve a session item result for all interaction_types' }
|
30
|
-
let(:quizzes_api_path) { '/api/quiz_sessions/1/results/1/session_item_results' }
|
31
|
-
let(:provider_state) { 'a set of session_item_results of autograded interaction_types' }
|
32
|
-
let(:resource_id) { '1' }
|
33
|
-
let(:scope) { 'quiz_session.results' }
|
34
|
-
let(:params) { { quiz_session_id: '1', quiz_session_result_id: '1' } }
|
35
|
-
let(:response_body) do
|
36
|
-
Pact.each_like(
|
37
|
-
grading_method: 'autograde',
|
38
|
-
score: Pact.like(1.0)
|
39
|
-
)
|
40
|
-
end
|
41
|
-
let(:service_name) { :session_item_results_service }
|
42
|
-
end
|
43
|
-
|
44
|
-
it_behaves_like 'a http get request to quiz_api collection endpoint' do
|
45
|
-
let(:request_description) { 'a request to retrieve a session item result for manually graded interaction_types' }
|
46
|
-
let(:quizzes_api_path) { '/api/quiz_sessions/1/results/1/session_item_results' }
|
47
|
-
let(:provider_state) { 'a set of session_item_results of manually graded interaction_types' }
|
48
|
-
let(:resource_id) { '1' }
|
49
|
-
let(:scope) { 'quiz_session.results' }
|
50
|
-
let(:params) { { quiz_session_id: '1', quiz_session_result_id: '1' } }
|
51
|
-
let(:response_body) do
|
52
|
-
Pact.each_like(
|
53
|
-
graded_at: Pact.like('2017-06-15T22:14:51.215Z'),
|
54
|
-
grading_method: 'manual_grading',
|
55
|
-
score: Pact.like(1.0)
|
56
|
-
)
|
57
|
-
end
|
58
|
-
let(:service_name) { :session_item_results_service }
|
59
|
-
end
|
60
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
describe QuizApiClient::Services::SessionItemsService, :pact do
|
2
|
-
include PactHelper
|
3
|
-
it_behaves_like 'a http get request to quiz_api collection endpoint', testrail_id: %w[3402560] do
|
4
|
-
let(:request_description) { 'a request to retrieve a session item' }
|
5
|
-
let(:quizzes_api_path) { '/api/quiz_sessions/1/session_items' }
|
6
|
-
let(:provider_state) { 'a set of session_items' }
|
7
|
-
let(:scope) { 'quiz_session.results' }
|
8
|
-
let(:resource_id) { '1' }
|
9
|
-
let(:params) { { quiz_session_id: '1' } }
|
10
|
-
let(:response_body) do
|
11
|
-
[
|
12
|
-
{
|
13
|
-
position: Pact.like(1),
|
14
|
-
item: {},
|
15
|
-
points_possible: Pact.like(1.0)
|
16
|
-
}
|
17
|
-
]
|
18
|
-
end
|
19
|
-
let(:service_name) { :session_items_service }
|
20
|
-
end
|
21
|
-
end
|
@@ -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
|