Skip to content

Commit

Permalink
Merge pull request #182 from mlibrary/LIBSEARCH-930-get-this-Asia-lib…
Browse files Browse the repository at this point in the history
…rary-backlog

Libsearch 930 get this asia library backlog
  • Loading branch information
bertrama authored Jun 11, 2024
2 parents beaeee8 + 7eabae5 commit bd4481f
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ token.txt
/.wget-hsts
.bash_history
.byebug_history
.solargraph.yml

!public/

Expand Down
4 changes: 2 additions & 2 deletions config/get_this.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
- not_building_use_only?
- not_game?

# Pickup (5 of 6) WORK_ORDER_DEPARTMENT AcqTechServices for ISEEES
# Pickup (5 of 6) WORK_ORDER_DEPARTMENT AcqTechServices for ISEEES and ASIA transit
- label: Request for pick up at a library
summary: We'll find the item and send it to the library of your choice for pick up in 1-5 days.
description:
Expand All @@ -206,7 +206,7 @@
grants:
holding:
- ann_arbor?
- in_international_studies_acquisitions_technical_services?
- in_slower_pickup?
- can_request?

# Pickup (6 of 6)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PhysicalItemDecorator < SimpleDelegator
ETAS_START = "Full text available,"

extend Forwardable
def_delegators :@work_order_option, :in_labeling?, :in_international_studies_acquisitions_technical_services?
def_delegators :@work_order_option, :in_labeling?

attr_reader :hathi_holding
def initialize(item, hathi_holdings = [], work_order_option = Spectrum::Entities::GetThisWorkOrderOption.for(item))
Expand Down Expand Up @@ -90,6 +90,10 @@ def not_etas?
!etas?
end

def in_slower_pickup?
@work_order_option.in_getable_acq_work_order? || in_asia_transit?
end

def music_pickup?
MUSIC_PICKUP.include?(@item.library)
end
Expand Down Expand Up @@ -171,8 +175,8 @@ def not_in_labeling?
!in_labeling?
end

def not_in_international_studies_acquisitions_technical_services?
!in_international_studies_acquisitions_technical_services?
def in_asia_transit?
@item.library == "HATCH" && @item.location == "ASIA" && @item.process_type == "TRANSIT"
end

def building_use_only?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def initialize(option:, patron:, item:, now:)
@item = item

@weight = option["weight"] || 0
@summary = option["summary"]
@description = option["description"]
@faq = option["faq"]
@label = option["label"]
Expand Down Expand Up @@ -42,6 +43,7 @@ def form

def to_h
{
summary: @summary,
description: @description,
faq: @faq,
form: form,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
class Spectrum::Entities::GetThisWorkOrderOption
def self.for(item, client=AlmaRestClient.client)
def self.for(item, client = AlmaRestClient.client)
if item.process_type == "WORK_ORDER_DEPARTMENT"
response = client.get("/items", query: {item_barcode: item.barcode})
raise StandardError if response.code != 200
self.new(response.parsed_response)
new(response.parsed_response)
else
GetThisWorkOrderNotApplicable.new
end
rescue
GetThisWorkOrderNotApplicable.new
GetThisWorkOrderNotApplicable.new
end

def initialize(data)
@data = data
end

def in_labeling?
["Labeling"].include?(@data.dig("item_data","work_order_type","value"))
["Labeling"].include?(@data.dig("item_data", "work_order_type", "value"))
end

def in_getable_acq_work_order?
in_international_studies_acquisitions_technical_services? || in_asia_backlog?
end

def in_international_studies_acquisitions_technical_services?
["AcqWorkOrder"].include?(@data.dig("item_data","work_order_type","value")) &&
["IS-SEEES"].include?(@data.dig("item_data","location","value"))
["AcqWorkOrder"].include?(@data.dig("item_data", "work_order_type", "value")) &&
["IS-SEEES"].include?(@data.dig("item_data", "location", "value"))
end

def in_asia_backlog?
["AcqWorkOrder"].include?(@data.dig("item_data", "work_order_type", "value")) &&
["ASIA"].include?(@data.dig("item_data", "location", "value"))
end


class GetThisWorkOrderNotApplicable < self
def initialize
end

def in_international_studies_acquisitions_technical_services?
false
end

def in_labeling?
false
end
end

def in_getable_acq_work_order?
false
end
end
end
51 changes: 44 additions & 7 deletions spec/spectrum/decorators/physical_item_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
solr_item: double("BibRecord::AlmaItem", process_type: nil, item_policy: "01", barcode: "somebarcode", fulfillment_unit: "General"),
bib_record: instance_double(Spectrum::BibRecord)
}
@get_this_work_order_double = instance_double(Spectrum::Entities::GetThisWorkOrderOption, in_labeling?: "in_labeling", in_international_studies_acquisitions_technical_services?: "in_international_studies_acquisitions_technical_services")
@get_this_work_order_double = instance_double(Spectrum::Entities::GetThisWorkOrderOption,
in_labeling?: "in_labeling",
in_international_studies_acquisitions_technical_services?: "in_international_studies_acquisitions_technical_services",
in_getable_acq_work_order?: false)
end
subject do
item = Spectrum::Entities::AlmaItem.new(**@input)
Expand All @@ -17,12 +20,6 @@
context "work order methods" do
# mrio: both of these would be booleans, but having them return strings shows
# that the correct path through the code is being used.
it "responds to #in_international_studies_acquisitions_technical_services?" do
expect(subject.in_international_studies_acquisitions_technical_services?).to eq("in_international_studies_acquisitions_technical_services")
end
it "responds to #not_in_international_studies_acquisitions_technical_services?" do
expect(subject.not_in_international_studies_acquisitions_technical_services?).to eq(false)
end
it "responds to #in_labeling?" do
expect(subject.in_labeling?).to eq("in_labeling")
end
Expand All @@ -31,6 +28,46 @@
expect(subject.not_in_labeling?).to eq(false)
end
end
context "in_slower_pickup?" do
it "is true when in_getable_acq_work_order?" do
allow(@get_this_work_order_double).to receive(:in_getable_acq_work_order?).and_return(true)
expect(subject.in_slower_pickup?).to eq(true)
end

it "is true when in_asia_transit? is true" do
allow(@get_this_work_order_double).to receive(:in_getable_acq_work_order?).and_return(false)
allow(@input[:solr_item]).to receive(:library).and_return("HATCH")
allow(@input[:solr_item]).to receive(:location).and_return("ASIA")
allow(@input[:solr_item]).to receive(:process_type).and_return("TRANSIT")
expect(subject.in_slower_pickup?).to eq(true)
end

it "is false when neither in_getable_acq_work_order? or in_asia_transit?" do
allow(@input[:solr_item]).to receive(:library).and_return("SHAP")
allow(@input[:solr_item]).to receive(:location).and_return("MAIN")
expect(subject.in_slower_pickup?).to eq(false)
end
end
context "in_asia_transit?" do
it "is true when in Asia library and process type transit" do
allow(@input[:solr_item]).to receive(:library).and_return("HATCH")
allow(@input[:solr_item]).to receive(:location).and_return("ASIA")
allow(@input[:solr_item]).to receive(:process_type).and_return("TRANSIT")
expect(subject.in_asia_transit?).to eq(true)
end

it "is false when in Asia library and does not have process type transit" do
allow(@input[:solr_item]).to receive(:library).and_return("HATCH")
allow(@input[:solr_item]).to receive(:location).and_return("ASIA")
expect(subject.in_asia_transit?).to eq(false)
end
it "is false when not in Asia library and process type transit" do
allow(@input[:solr_item]).to receive(:library).and_return("SHAP")
allow(@input[:solr_item]).to receive(:location).and_return("MAIN")
allow(@input[:solr_item]).to receive(:process_type).and_return("TRANSIT")
expect(subject.in_asia_transit?).to eq(false)
end
end
context "#can_scan?" do
it "is true for a scannable material type" do
allow(@input[:solr_item]).to receive(:material_type).and_return("BOOK")
Expand Down
48 changes: 39 additions & 9 deletions spec/spectrum/entities/get_this_work_order_option_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
require_relative '../../rails_helper'
require_relative "../../rails_helper"
describe Spectrum::Entities::GetThisWorkOrderOption do
before(:each) do
@item = double('Spectrum::Decorators::PhysicalItemDecorator', location: 'HATCH', process_type: "WORK_ORDER_DEPARTMENT", barcode: "BARCODE")
@alma_item = JSON.parse(File.read('./spec/fixtures/get_this/alma_work_order_item.json'))
@item = double("Spectrum::Decorators::PhysicalItemDecorator", location: "HATCH", process_type: "WORK_ORDER_DEPARTMENT", barcode: "BARCODE")
@alma_item = JSON.parse(File.read("./spec/fixtures/get_this/alma_work_order_item.json"))
end
subject do
stub_alma_get_request(url: "items", output: @alma_item.to_json, query: {item_barcode: 'BARCODE'})
stub_alma_get_request(url: "items", output: @alma_item.to_json, query: {item_barcode: "BARCODE"})
described_class.for(@item)
end
context ".for" do
it "returns a GetThisWorkOrderOption object for an item with a WORK_ORDER_DEPARTMENT process type" do
it "returns a GetThisWorkOrderOption object for an item with a WORK_ORDER_DEPARTMENT process type" do
expect(subject.class.to_s).to include("GetThisWorkOrderOption")
end
it "returns a GetThisWorkOrderNotApplicable object for an item with a non work order process type" do
it "returns a GetThisWorkOrderNotApplicable object for an item with a non work order process type" do
allow(@item).to receive(:process_type).and_return("IN_TRANSIT")
expect(subject.class.to_s).to include("GetThisWorkOrderNotApplicable")
end
it "returns a GetThisWorkOrderNotApplicable if the api response returns not 200" do
stub_alma_get_request(url: "items", query: {item_barcode: 'BARCODE'}, status: 500)
it "returns a GetThisWorkOrderNotApplicable if the api response returns not 200" do
stub_alma_get_request(url: "items", query: {item_barcode: "BARCODE"}, status: 500)
expect(described_class.for(@item).class.to_s).to include("GetThisWorkOrderNotApplicable")
end
end
Expand All @@ -30,8 +30,23 @@
expect(subject.in_labeling?).to eq(false)
end
end
context "in_asia_backlog?" do
it "is true when an item is in Asia Library and has work order type AcqWorkOrder" do
@alma_item["item_data"]["work_order_type"]["value"] = "AcqWorkOrder"
@alma_item["item_data"]["location"]["value"] = "ASIA"
expect(subject.in_asia_backlog?).to eq(true)
end
it "is false when not in Asia Library but has AcqWorkOrder" do
@alma_item["item_data"]["work_order_type"]["value"] = "AcqWorkOrder"
expect(subject.in_asia_backlog?).to eq(false)
end
it "is false when in Asia library but not in AcqWorkorder" do
@alma_item["item_data"]["location"]["value"] = "ASIA"
expect(subject.in_asia_backlog?).to eq(false)
end
end
context "in_international_studies_acquisitions_technical_services?" do
it "is true when an item is in international studies and is in the AqcWork Order" do
it "is true when an item is in international studies and is in AcqWorkOrder" do
@alma_item["item_data"]["work_order_type"]["value"] = "AcqWorkOrder"
@alma_item["item_data"]["location"]["value"] = "IS-SEEES"
expect(subject.in_international_studies_acquisitions_technical_services?).to eq(true)
Expand All @@ -45,6 +60,21 @@
expect(subject.in_international_studies_acquisitions_technical_services?).to eq(false)
end
end
context "in_getable_acq_work_order?" do
it "is true when isees is true" do
@alma_item["item_data"]["work_order_type"]["value"] = "AcqWorkOrder"
@alma_item["item_data"]["location"]["value"] = "IS-SEEES"
expect(subject.in_getable_acq_work_order?).to eq(true)
end
it "is true when asia backlog is true" do
@alma_item["item_data"]["work_order_type"]["value"] = "AcqWorkOrder"
@alma_item["item_data"]["location"]["value"] = "ASIA"
expect(subject.in_getable_acq_work_order?).to eq(true)
end
it "is false when its in neither" do
expect(subject.in_getable_acq_work_order?).to eq(false)
end
end
end
describe Spectrum::Entities::GetThisWorkOrderOption::GetThisWorkOrderNotApplicable do
subject do
Expand Down

0 comments on commit bd4481f

Please sign in to comment.