-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a BorrowDirectRequests model to wrap BorrowDirect and add it to t…
…he UI.
- Loading branch information
Showing
5 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
## | ||
# Wrap the BorrowDirect::RequestQuery in a class that we | ||
# can inject our patron barcode from (and do error handling) | ||
class BorrowDirectRequests | ||
attr_reader :patron | ||
def initialize(patron) | ||
@patron = patron | ||
end | ||
|
||
def requests | ||
request_client.requests('open', true).map { |request| BorrowDirectRequests::Request.new(request) }.select(&:active?) | ||
rescue BorrowDirect::Error | ||
[] | ||
end | ||
|
||
private | ||
|
||
def request_client | ||
@request_client ||= BorrowDirect::RequestQuery.new(patron.barcode) | ||
end | ||
|
||
## | ||
# Wrap the BorrowDirect::RequestQuery::Item in a class | ||
# so we can give it a similar iterface to Symphony Requests | ||
class Request < SimpleDelegator | ||
# Request becomes ON_LOAN once we receive it (and should show as a request ready for pickup/checkout) | ||
# Request becomes COMPLETED once the uesr returns it | ||
ACTIVE_REQUEST_STATUSES = %w[ | ||
ENTERED IN_PROCESS SHIPPED | ||
].freeze | ||
|
||
def active? | ||
ACTIVE_REQUEST_STATUSES.include? request_status | ||
end | ||
|
||
def key | ||
request_number | ||
end | ||
|
||
def expiration_date; end | ||
|
||
def fill_by_date; end | ||
|
||
def ready_for_pickup? | ||
false | ||
end | ||
|
||
def to_partial_path | ||
'requests/borrow_direct_request' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<li class="row d-flex flex-wrap list-group-item"> | ||
<div class="d-flex flex-row flex-grow-1 justify-content-between w-100 row col-md-4"> | ||
<div class="w-50 col-md-6 library"> | ||
<span class="d-md-none">Deliver to </span> Stanford | ||
</div> | ||
<div class="w-50 col-md-6 text-right text-md-left date"> | ||
In transit | ||
</div> | ||
</div> | ||
<div class="d-flex flex-grow-1 flex-column flex-md-row w-75 row col-md-8"> | ||
<h3 class="col-md-7 clamp-2 record-title title text-reset"><%= borrow_direct_request.title %></h3> | ||
<div class="d-flex flex-row row col-md-5"> | ||
<div class="w-50 col-md-6"></div> | ||
<div class="w-50 col-md-6"></div> | ||
</div> | ||
</div> | ||
<div> | ||
<button class="btn collapsed" type="button" data-toggle="collapse" data-target="#collapseRequest-<%= borrow_direct_request.key %>" aria-expanded="false" aria-controls="collapseRequest-<%= borrow_direct_request.key %>"> | ||
<span class="expand-icon"><%= sul_icon :'sharp-add-24px' %><span class="sr-only">Expand</span></span> | ||
<span class="collapse-icon"><%= sul_icon :'sharp-remove-24px' %><span class="sr-only">Collapse</span></span> | ||
</button> | ||
</div> | ||
<div class="collapse w-100" id="collapseRequest-<%= borrow_direct_request.key %>"> | ||
<dl class="row mb-0"> | ||
<dt class="col-3 offset-1 col-md-2 offset-md-2">Requested:</dt> | ||
<dd class="col-8"><%= l(borrow_direct_request.date_submitted, format: :short) %></dd> | ||
<dt class="col-3 offset-1 col-md-2 offset-md-2">Source:</dt> | ||
<dd class="col-8">BorrowDirect</dd> | ||
</dl> | ||
</div> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe BorrowDirectRequests do | ||
subject(:bd_requests) { described_class.new(patron) } | ||
|
||
let(:patron) { instance_double(Patron, barcode: '123456') } | ||
let(:in_process_request) do | ||
instance_double( | ||
BorrowDirect::RequestQuery::Item, | ||
request_number: 'STA-123454321', | ||
request_status: 'IN_PROCESS', | ||
date_submitted: Time.zone.today - 3.days | ||
) | ||
end | ||
let(:completed_request) { instance_double(BorrowDirect::RequestQuery::Item, request_status: 'COMPLETED') } | ||
let(:mock_requests) do | ||
instance_double(BorrowDirect::RequestQuery, requests: [in_process_request, completed_request]) | ||
end | ||
|
||
context 'when successful' do | ||
before do | ||
allow(BorrowDirect::RequestQuery).to receive(:new).with(patron.barcode).and_return(mock_requests) | ||
end | ||
|
||
it 'only return requests with active statuses' do | ||
expect(bd_requests.requests.length).to be(1) | ||
end | ||
end | ||
|
||
context 'when borrow direct returns an error' do | ||
before do | ||
allow(BorrowDirect::RequestQuery).to receive(:new).with(patron.barcode).and_raise( | ||
BorrowDirect::Error, 'Item not Found' | ||
) | ||
end | ||
|
||
it 'returns an empty array' do | ||
expect(bd_requests.requests).to eq([]) | ||
end | ||
end | ||
|
||
describe 'BorrowDirectRequests::Request' do | ||
let(:request) do | ||
BorrowDirectRequests::Request.new(in_process_request) | ||
end | ||
|
||
it 'delegates methods to the given request oboject' do | ||
expect(request.date_submitted).to eq in_process_request.date_submitted | ||
end | ||
|
||
it 'returns the request_number as the key' do | ||
expect(request.key).to eq in_process_request.request_number | ||
end | ||
|
||
it { expect(request).not_to be_ready_for_pickup } | ||
|
||
context 'when in an active state' do | ||
it { expect(request).to be_active } | ||
end | ||
|
||
context 'when not in an active state' do | ||
let(:request) do | ||
BorrowDirectRequests::Request.new(completed_request) | ||
end | ||
|
||
it { expect(request).not_to be_active } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters