From d013656dcbe9744e3fa7aeef4ab80ba6c9e4a244 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Thu, 25 Jul 2019 14:14:15 -0700 Subject: [PATCH] tests --- app/services/symphony_client.rb | 4 +- spec/controllers/renewals_controller_spec.rb | 50 +++++++++++++++++++- spec/features/renew_item_spec.rb | 8 ++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/app/services/symphony_client.rb b/app/services/symphony_client.rb index d5c6fb84b..8424e3970 100644 --- a/app/services/symphony_client.rb +++ b/app/services/symphony_client.rb @@ -99,9 +99,9 @@ def renew_items(checkouts) case response.status when 200 - flash[:success] << t('mylibrary.renew_item.success_html', title: checkout.title) + flash[:success] << I18n.t('mylibrary.renew_item.success_html', title: checkout.title) else - flash[:error] << t('mylibrary.renew_item.error_html', title: checkout.title) + flash[:error] << I18n.t('mylibrary.renew_item.error_html', title: checkout.title) end end end diff --git a/spec/controllers/renewals_controller_spec.rb b/spec/controllers/renewals_controller_spec.rb index 196eba0f5..ca11686c4 100644 --- a/spec/controllers/renewals_controller_spec.rb +++ b/spec/controllers/renewals_controller_spec.rb @@ -4,7 +4,9 @@ RSpec.describe RenewalsController, type: :controller do let(:api_response) { instance_double('Response', status: 200, content_type: :json) } - let(:mock_client) { instance_double(SymphonyClient, renew_item: api_response) } + let(:mock_client) do + instance_double(SymphonyClient, renew_item: api_response) + end let(:user) do { username: 'somesunetid', patron_key: '123' } end @@ -42,4 +44,50 @@ end end end + + describe '#all_eligible' do + let(:mock_client) do + instance_double(SymphonyClient, renew_items: api_response) + end + let(:api_response) { { success: ['Success!'], error: ['Sorry!']} } + let(:mock_patron) { instance_double(Patron, checkouts: checkouts) } + let(:checkouts) do + [ + instance_double(Checkout, key: '1', renewable?: true, item_key: '123', title: 'ABC', resource: 'item'), + instance_double(Checkout, key: '2', renewable?: true, item_key: '456', title: 'XYZ', resource: 'item'), + instance_double(Checkout, key: '3', renewable?: false, item_key: '789', title: 'Not', resource: 'item') + ] + end + + before do + allow(controller).to receive(:patron).and_return(mock_patron) + end + + it 'sends renewal requests to symphony for eligible items' do + post :all_eligible + + expect(mock_client).to have_received(:renew_items).with([ + having_attributes(key: '1'), + having_attributes(key: '2') + ]) + end + + it 'sets a success flash message' do + post :all_eligible + + expect(flash[:success]).to include(/Success!/) + end + + it 'sets an reror flash message' do + post :all_eligible + + expect(flash[:error]).to include(/Sorry!/) + end + + it 'renews the item and redirects to checkouts_path' do + post :all_eligible + + expect(response).to redirect_to checkouts_path + end + end end diff --git a/spec/features/renew_item_spec.rb b/spec/features/renew_item_spec.rb index a7f424abb..897a2c834 100644 --- a/spec/features/renew_item_spec.rb +++ b/spec/features/renew_item_spec.rb @@ -16,4 +16,12 @@ end expect(page).to have_css '.flash_messages', text: 'Success!' end + + it 'has a button to renew all items' do + visit checkouts_path + + click_on 'Renew 9 eligible items' + + expect(page).to have_css '.flash_messages', text: 'Success!' + end end