Skip to content

Commit

Permalink
Raise error on empty paged responses
Browse files Browse the repository at this point in the history
  • Loading branch information
nanotone committed Mar 5, 2020
1 parent 9e4820a commit ac7e205
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/vbms/service/paged_documents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def call(file_number:)
req = next_request(file_number, 0)
first_page = client.send_request(req)

# interpret a first page with no sections (and no doc count) as equivalent to zero pages.
raise ClientError.new("No sections found in first page") if first_page.empty?

# response will always be an array. get pagination from the first section.
(documents << first_page.map { |section| section[:documents] }).flatten!
pagination = first_page.first[:paging]
Expand Down
7 changes: 7 additions & 0 deletions spec/service/paged_documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,12 @@ def next_response
expect(r[:paging][:@total_result_count]).to eq total_docs
end
end

context "when the first page contains no sections" do
it "raises a ClientError" do
allow(client).to receive(:send_request).and_return []
expect { subject.call(file_number: file_number) }.to raise_error(VBMS::ClientError)
end
end
end
end

0 comments on commit ac7e205

Please sign in to comment.