Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Client
include Introspection

MAX_PER_PAGE = 100
MAX_TOTAL_RESULTS = 1000

def initialize(configuration)
@configuration = configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def translate_page(page)

per_page = page.limit&.positive? ? [page.limit, Client::MAX_PER_PAGE].min : Client::MAX_PER_PAGE
page_num = (page.offset.to_i / per_page) + 1
if page_num * per_page > Client::MAX_TOTAL_RESULTS
raise ForestAdminDatasourceToolkit::Exceptions::ForestException,
"Zendesk Search caps total results at #{Client::MAX_TOTAL_RESULTS}; " \
"page #{page_num} (offset=#{page.offset}, per_page=#{per_page}) exceeds this limit. " \
'Narrow the filter to fetch records past this point.'
end
[page_num, per_page]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ def zendesk_record(attrs)
expect(client).to have_received(:search)
.with('ticket', hash_including(per_page: ForestAdminDatasourceZendesk::Client::MAX_PER_PAGE))
end

it 'sends the last allowed page (offset 900 / limit 100) without raising' do
allow(client).to receive(:search).and_return([])

filter = Filter.new(page: Page.new(offset: 900, limit: 100))
collection.list(nil, filter, ['id'])

expect(client).to have_received(:search).with('ticket', hash_including(page: 10, per_page: 100))
end

it 'raises a ForestException with an actionable message past the 1000-result cap' do
filter = Filter.new(page: Page.new(offset: 1000, limit: 100))
expect { collection.list(nil, filter, ['id']) }
.to raise_error(ForestAdminDatasourceToolkit::Exceptions::ForestException,
/caps total results at 1000.*Narrow the filter/m)
end
end

describe 'requester_email enrichment' do
Expand Down
Loading