quiz_api_client 4.13.0 → 4.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quiz_api_client/services/bank_entries_service.rb +1 -1
- data/lib/quiz_api_client/services/courses_service.rb +7 -0
- data/lib/quiz_api_client/services/quiz_entries_service.rb +1 -1
- data/lib/quiz_api_client/version.rb +1 -1
- data/spec/services/bank_entries_service_spec.rb +42 -13
- data/spec/services/courses_service_spec.rb +35 -0
- data/spec/services/quiz_entries_service_spec.rb +42 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a3731bc74410110bbb5ebcd49a1810b4609e77a39d0f415a66b2add1c588c83
|
4
|
+
data.tar.gz: c00017a51dd925c73ec1f6a957ba830b2762a1da20ba949ff42090d244188f86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c0b3d1876135ab671d33a9156d6c56ad7f51103691de92f6a093d91e5f1a1d01c160f5017585572afd88b2bd245df34e043ff8f1e3516b75e87a3e96344bdca
|
7
|
+
data.tar.gz: d41fde3e160e5b9d57b242810ae29657183516e88586f1afb4a0c86f7171ee447603282b43058f3feb7aff8897c06c74cdf2adec23b0dfcdbb54c423a09e12e4
|
@@ -3,7 +3,7 @@ module QuizApiClient::Services
|
|
3
3
|
def list(params:, token: nil, all: false)
|
4
4
|
raise 'Bank Id Required' unless params && params[:id]
|
5
5
|
|
6
|
-
pagination_params = { page: params.delete(:page), per_page: params.delete(:per_page) }
|
6
|
+
pagination_params = { page: params.delete(:page), per_page: params.delete(:per_page) }.compact
|
7
7
|
get_from_quiz_api(params: params, token: token, pagination_params: pagination_params, all: all)
|
8
8
|
end
|
9
9
|
|
@@ -26,6 +26,13 @@ module QuizApiClient::Services
|
|
26
26
|
)
|
27
27
|
end
|
28
28
|
|
29
|
+
def associate_courses(params:, token: nil)
|
30
|
+
client(token: token).patch(
|
31
|
+
"/api/courses/#{params[:canvas_id]}/associate_courses",
|
32
|
+
course_canvas_ids: params[:course_canvas_ids]
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
29
36
|
private
|
30
37
|
|
31
38
|
def post_to_quiz_api(params:, token:)
|
@@ -23,7 +23,7 @@ module QuizApiClient::Services
|
|
23
23
|
def list(params:, token: nil, all: false)
|
24
24
|
raise 'Quiz Id Required' unless params && params[:id]
|
25
25
|
|
26
|
-
pagination_params = { page: params.delete(:page), per_page: params.delete(:per_page) }
|
26
|
+
pagination_params = { page: params.delete(:page), per_page: params.delete(:per_page) }.compact
|
27
27
|
get_from_quiz_api(params: params, token: token, pagination_params: pagination_params, all: all)
|
28
28
|
end
|
29
29
|
|
@@ -3,24 +3,53 @@ describe QuizApiClient::Services::BankEntriesService do
|
|
3
3
|
let(:config) { QuizApiClient::Config.new { |c| c.host = host } }
|
4
4
|
let(:subject) { described_class.new(config) }
|
5
5
|
|
6
|
+
def link_header(host, path, page, last_page)
|
7
|
+
link_header = "<https://#{host}#{path}?page=#{last_page}>; rel=\"last\""
|
8
|
+
link_header += ", <https://#{host}#{path}?page=#{page + 1}>; rel=\"next\"" if page < last_page
|
9
|
+
link_header += ", <https://#{host}#{path}?page=#{page - 1}>; rel=\"prev\"" if page > 1
|
10
|
+
link_header += ", <https://#{host}#{path}?page=1>; rel=\"first\"" if page > 1
|
11
|
+
{ link: link_header }
|
12
|
+
end
|
13
|
+
|
14
|
+
def stub_quiz_api(url, body, query: {}, headers: {}, status: 200)
|
15
|
+
stub_request(:get, url)
|
16
|
+
.with(query: query)
|
17
|
+
.to_return(
|
18
|
+
body: body.to_json,
|
19
|
+
status: status,
|
20
|
+
headers: headers.merge(
|
21
|
+
'Content-Type' => 'application/json'
|
22
|
+
)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
6
26
|
describe '#list' do
|
7
27
|
let(:params) { { id: 1 } }
|
8
|
-
let(:
|
9
|
-
let(:expected_url) { "https://#{host}
|
10
|
-
let(:status_code) { 200 }
|
28
|
+
let(:path) { "/api/internal_services/banks/#{params[:id]}/bank_entries" }
|
29
|
+
let(:expected_url) { "https://#{host}#{path}" }
|
11
30
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
31
|
+
def page(page_num)
|
32
|
+
[{ 'id' => page_num, 'entry' => { 'id' => page_num } }]
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'single page' do
|
36
|
+
stub_quiz_api(expected_url, page(1), headers: link_header(host, path, 1, 1))
|
37
|
+
result = subject.list(params: params, token: 'token', all: true)
|
38
|
+
expect(result).to eql([{ 'id' => 1, 'entry' => { 'id' => 1 } }])
|
19
39
|
end
|
20
40
|
|
21
|
-
it '
|
22
|
-
|
23
|
-
|
41
|
+
it 'paginated response' do
|
42
|
+
expected_result = [
|
43
|
+
{ 'id' => 1, 'entry' => { 'id' => 1 } },
|
44
|
+
{ 'id' => 2, 'entry' => { 'id' => 2 } },
|
45
|
+
{ 'id' => 3, 'entry' => { 'id' => 3 } }
|
46
|
+
]
|
47
|
+
|
48
|
+
stub_quiz_api(expected_url, page(1), headers: link_header(host, path, 1, 3))
|
49
|
+
stub_quiz_api(expected_url, page(2), query: { page: 2 }, headers: link_header(host, path, 2, 3))
|
50
|
+
stub_quiz_api(expected_url, page(3), query: { page: 3 }, headers: link_header(host, path, 3, 3))
|
51
|
+
result = subject.list(params: params, token: 'token', all: true)
|
52
|
+
expect(result).to eql(expected_result)
|
24
53
|
end
|
25
54
|
end
|
26
55
|
end
|
@@ -174,4 +174,39 @@ describe QuizApiClient::Services::CoursesService do
|
|
174
174
|
).to eq(response)
|
175
175
|
end
|
176
176
|
end
|
177
|
+
|
178
|
+
describe '#associate_courses' do
|
179
|
+
let(:params) { { canvas_id: 1, course_canvas_ids: [2, 3, 4] } }
|
180
|
+
let(:response) do
|
181
|
+
{
|
182
|
+
'course' => {
|
183
|
+
'id' => '4',
|
184
|
+
'title' => 'foo',
|
185
|
+
'canvas_id' => '2',
|
186
|
+
'is_blueprint' => true,
|
187
|
+
'created_at' => '2022-06-22T18:59:27.577Z',
|
188
|
+
'updated_at' => '2022-06-22T18:59:27.577Z'
|
189
|
+
},
|
190
|
+
'courses_synced' => params[:course_canvas_ids]
|
191
|
+
}
|
192
|
+
end
|
193
|
+
|
194
|
+
let(:expected_url) { "https://#{host}/api/courses/1/associate_courses" }
|
195
|
+
|
196
|
+
before do
|
197
|
+
stub_request(:patch, expected_url)
|
198
|
+
.with(body: { course_canvas_ids: params[:course_canvas_ids] }.to_json)
|
199
|
+
.to_return(
|
200
|
+
status: 200,
|
201
|
+
body: response.to_json,
|
202
|
+
headers: { 'Content-Type' => 'application/json' }
|
203
|
+
)
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'patches to the correct endpoint and returns the response' do
|
207
|
+
expect(
|
208
|
+
subject.associate_courses(params: params, token: 'token').parsed_response
|
209
|
+
).to eq(response)
|
210
|
+
end
|
211
|
+
end
|
177
212
|
end
|
@@ -3,24 +3,53 @@ describe QuizApiClient::Services::QuizEntriesService do
|
|
3
3
|
let(:config) { QuizApiClient::Config.new { |c| c.host = host } }
|
4
4
|
let(:subject) { described_class.new(config) }
|
5
5
|
|
6
|
+
def link_header(host, path, page, last_page)
|
7
|
+
link_header = "<https://#{host}#{path}?page=#{last_page}>; rel=\"last\""
|
8
|
+
link_header += ", <https://#{host}#{path}?page=#{page + 1}>; rel=\"next\"" if page < last_page
|
9
|
+
link_header += ", <https://#{host}#{path}?page=#{page - 1}>; rel=\"prev\"" if page > 1
|
10
|
+
link_header += ", <https://#{host}#{path}?page=1>; rel=\"first\"" if page > 1
|
11
|
+
{ link: link_header }
|
12
|
+
end
|
13
|
+
|
14
|
+
def stub_quiz_api(url, body, query: {}, headers: {}, status: 200)
|
15
|
+
stub_request(:get, url)
|
16
|
+
.with(query: query)
|
17
|
+
.to_return(
|
18
|
+
body: body.to_json,
|
19
|
+
status: status,
|
20
|
+
headers: headers.merge(
|
21
|
+
'Content-Type' => 'application/json'
|
22
|
+
)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
6
26
|
describe '#list' do
|
7
27
|
let(:params) { { id: 1 } }
|
8
|
-
let(:
|
9
|
-
let(:expected_url) { "https://#{host}
|
10
|
-
let(:status_code) { 200 }
|
28
|
+
let(:path) { "/api/quizzes/#{params[:id]}/quiz_entries" }
|
29
|
+
let(:expected_url) { "https://#{host}#{path}" }
|
11
30
|
|
12
|
-
|
13
|
-
|
14
|
-
.to_return(
|
15
|
-
status: status_code,
|
16
|
-
body: stubbed_response.to_json,
|
17
|
-
headers: { 'Content-Type' => 'application/json' }
|
18
|
-
)
|
31
|
+
def page(page_num)
|
32
|
+
[{ 'id' => page_num, 'entry' => { 'id' => page_num } }]
|
19
33
|
end
|
20
34
|
|
21
|
-
it '
|
22
|
-
|
23
|
-
|
35
|
+
it 'single page' do
|
36
|
+
stub_quiz_api(expected_url, page(1), headers: link_header(host, path, 1, 1))
|
37
|
+
result = subject.list(params: params, token: 'token', all: true)
|
38
|
+
expect(result).to eql([{ 'id' => 1, 'entry' => { 'id' => 1 } }])
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'paginated response' do
|
42
|
+
expected_result = [
|
43
|
+
{ 'id' => 1, 'entry' => { 'id' => 1 } },
|
44
|
+
{ 'id' => 2, 'entry' => { 'id' => 2 } },
|
45
|
+
{ 'id' => 3, 'entry' => { 'id' => 3 } }
|
46
|
+
]
|
47
|
+
|
48
|
+
stub_quiz_api(expected_url, page(1), headers: link_header(host, path, 1, 3))
|
49
|
+
stub_quiz_api(expected_url, page(2), query: { page: 2 }, headers: link_header(host, path, 2, 3))
|
50
|
+
stub_quiz_api(expected_url, page(3), query: { page: 3 }, headers: link_header(host, path, 3, 3))
|
51
|
+
result = subject.list(params: params, token: 'token', all: true)
|
52
|
+
expect(result).to eql(expected_result)
|
24
53
|
end
|
25
54
|
end
|
26
55
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quiz_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.13.
|
4
|
+
version: 4.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Slaughter
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: exe
|
17
17
|
cert_chain: []
|
18
|
-
date: 2023-
|
18
|
+
date: 2023-08-31 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: httparty
|