quiz_api_client 4.13.1 → 4.13.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ba12e6decb1a28b9587740a754e454a58c5345d28cf72632b267484bc82eab0
4
- data.tar.gz: 7f7773f75f5f586abf61542bb32b013cba0c25e70feb498d709b6682b6f65f2a
3
+ metadata.gz: 5a3731bc74410110bbb5ebcd49a1810b4609e77a39d0f415a66b2add1c588c83
4
+ data.tar.gz: c00017a51dd925c73ec1f6a957ba830b2762a1da20ba949ff42090d244188f86
5
5
  SHA512:
6
- metadata.gz: 3820e1479d10ed16e76f278a741b359334af9c494fd06d3d4db93f597f7209201a4a43b7492d7c90e5d84187e12f69ca56fb0deff1e404dac91bb95a15c5ef82
7
- data.tar.gz: fdc87d815718c2a0585cbe1bcc50b93c9aadcf0b18e384ab0dd000f9e619e83e89a881b70db478732e1f44d949eabcfbb5f4b4b99d9de4e9462caa36b699b6ac
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
 
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module QuizApiClient
2
- VERSION = '4.13.1'.freeze
2
+ VERSION = '4.13.2'.freeze
3
3
  end
@@ -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(:stubbed_response) { { 'id' => 1, 'entry' => { 'id' => 1 } } }
9
- let(:expected_url) { "https://#{host}/api/internal_services/banks/#{params[:id]}/bank_entries?page=&per_page=" }
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
- before do
13
- stub_request(:get, expected_url)
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 } }]
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 'gets from quiz_api/api/banks/{id}/bank_entries and returns the response' do
22
- result = subject.list(params: params, token: 'token')
23
- expect(result.parsed_response).to eql(stubbed_response)
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
@@ -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(:stubbed_response) { { 'id' => 1, 'entry' => { 'id' => 1 } } }
9
- let(:expected_url) { "https://#{host}/api/quizzes/#{params[:id]}/quiz_entries?page=&per_page=" }
10
- let(:status_code) { 200 }
28
+ let(:path) { "/api/quizzes/#{params[:id]}/quiz_entries" }
29
+ let(:expected_url) { "https://#{host}#{path}" }
11
30
 
12
- before do
13
- stub_request(:get, expected_url)
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 'gets from quiz_api/api/quizzes/{id}/quiz_entries and returns the response' do
22
- result = subject.list(params: params, token: 'token')
23
- expect(result.parsed_response).to eql(stubbed_response)
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.1
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-08-23 00:00:00.000000000 Z
18
+ date: 2023-08-31 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: httparty