Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jul 25, 2019
1 parent ede503d commit d013656
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/services/symphony_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 49 additions & 1 deletion spec/controllers/renewals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions spec/features/renew_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d013656

Please sign in to comment.