diff --git a/spec/models/borrow_direct_requests_spec.rb b/spec/models/borrow_direct_requests_spec.rb
new file mode 100644
index 000000000..2e7b7121a
--- /dev/null
+++ b/spec/models/borrow_direct_requests_spec.rb
@@ -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
diff --git a/spec/models/patron_spec.rb b/spec/models/patron_spec.rb
index 4d5c35081..877c61219 100644
--- a/spec/models/patron_spec.rb
+++ b/spec/models/patron_spec.rb
@@ -334,12 +334,19 @@
context 'with requests' do
before do
fields[:holdRecordList] = [{ key: 1, fields: {} }]
+ allow(BorrowDirectRequests).to receive(:new).and_return(
+ instance_double(BorrowDirectRequests, requests: [{ key: 2 }])
+ )
end
describe '#requests' do
it 'returns a list of requests for the patron' do
expect(patron.requests).to include a_kind_of(Request).and(have_attributes(key: 1))
end
+
+ it 'includes requests that come from the BorrowDirectRequests class' do
+ expect(patron.requests.last[:key]).to be 2
+ end
end
end
end