From 6e1d4c205cc59d8d62016ea86962dcb64a1394aa Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Thu, 4 Jul 2019 16:02:29 +0200 Subject: [PATCH] Add tests for page_id for search service --- .../external_protocols_controller_spec.rb | 22 ++++++++++++++++--- .../search_protocols_service_spec.rb | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/spec/controllers/external_protocols_controller_spec.rb b/spec/controllers/external_protocols_controller_spec.rb index 0f0de9fbb..ce47cc857 100644 --- a/spec/controllers/external_protocols_controller_spec.rb +++ b/spec/controllers/external_protocols_controller_spec.rb @@ -15,8 +15,8 @@ describe ExternalProtocolsController, type: :controller do team_id: team.id, key: 'search_string', protocol_source: 'protocolsio/v3', - page_id: 1, - page_size: 10, + page_id: 2, + page_size: 50, order_field: 'activity', order_dir: 'desc' } @@ -24,10 +24,21 @@ describe ExternalProtocolsController, type: :controller do let(:action) { get :index, params: params } + let(:valid_search_response) do + { + protocols: [], + pagination: { + current_page: 2, + total_pages: 6, + page_size: 10 + } + } + end + before do service = double('success_service') allow(service).to(receive(:succeed?)).and_return(true) - allow(service).to(receive(:protocols_list)).and_return({}) + allow(service).to(receive(:protocols_list)).and_return(valid_search_response) allow_any_instance_of(ProtocolImporters::SearchProtocolsService).to(receive(:call)).and_return(service) end @@ -42,6 +53,11 @@ describe ExternalProtocolsController, type: :controller do action expect(JSON.parse(response.body)).to have_key('html') end + + it 'contains page_id in the response' do + action + expect(JSON.parse(response.body)['page_id']).to eq 2 + end end describe 'GET show' do diff --git a/spec/services/protocol_importers/search_protocols_service_spec.rb b/spec/services/protocol_importers/search_protocols_service_spec.rb index 3a321bd4e..184e8eaeb 100644 --- a/spec/services/protocol_importers/search_protocols_service_spec.rb +++ b/spec/services/protocol_importers/search_protocols_service_spec.rb @@ -72,7 +72,7 @@ describe ProtocolImporters::SearchProtocolsService do .and_return(normalized_list)) end - it 'returns an error when params are invalid' do + it 'returns normalized list' do expect(service_call.protocols_list).to be == normalized_list end end