Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20200717 mk form submission spec #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/controllers/concerns/post_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def post_process(form_id, vars)
FormMailer.confirm_enhanced_email(user, bib, values).deliver_now
when 'resourcesharing'
when 'ill'
illiad_service = Illiad.new
if user.data['illiadrecord'] == 'new'
Illiad.addIlliadUser(user)
illiad_service.addIlliadUser(user)
elsif user.data['illiadrecord'] == 'modify'
Illiad.updateIlliadUser(user)
illiad_service.updateIlliadUser(user)
end

txnumber = Illiad.submit(user, bib, values)
txnumber = illiad_service.submit(user, bib, values)
FormMailer.confirm_illiad_email(user, bib, txnumber, values).deliver_now
when 'booksbymail'
FormMailer.confirm_booksbymail_email(user, bib, values).deliver_now
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/concerns/pre_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@ def pre_process(form_id, params)
end

user = User.new(username, proxy_id)
Illiad.getIlliadUserInfo(user, params)
illiad_service = Illiad.new
illiad_service.getIlliadUserInfo(user, params)

if ['B', 'BO'].member?(user.data['cleared'])
redirect_to "http://www.library.upenn.edu/access/ill/ill_blocked.html"
return
end

record = Illiad.getBibData(params)
record = illiad_service.getBibData(params)
delivery_method = record['requesttype'] == 'Book' ? "Pickup at #{user.data['illoffice_name']}" : 'Web Delivery'
show_addr_msg = false

if user.data['status'] == 'StandingFaculty'
Illiad.getCorrectedDeptDetails(user.data)
illiad_service.getCorrectedDeptDetails(user.data)
if record['requesttype'] == 'Book'
delivery_method = "Deliver to my department: #{user.data['delivery']}" if record['requesttype'] == 'Book'
show_addr_msg = true
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/form_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def confirm_fixopac_email(user, bib, values)
def confirm_illiad_email(user, bib, txnumber, values)
userinfo = user.data

@to = userinfo['emailAddr']
@from = ''
# use email from form if userinfo doesn't have an address
@to = userinfo['emailAddr'] || values['email']
@subject = 'Request Confirmation'

@name = "#{userinfo['first_name']} #{userinfo['last_name']}"
Expand Down
53 changes: 32 additions & 21 deletions app/services/illiad.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
class Illiad

@illoffices = Hash.new() { 'Van Pelt Library' }
@illoffices['BIOMED'] = 'Biomedical Library'
@illoffices['DENTAL'] = 'Dental Medicine Library'
@illoffices['VET'] = 'Veterinary Medicine Library'
def initialize
@illoffices = Hash.new { 'Van Pelt Library' }
@illoffices['BIOMED'] = 'Biomedical Library'
@illoffices['DENTAL'] = 'Dental Medicine Library'
@illoffices['VET'] = 'Veterinary Medicine Library'
end

def self.getBibData(params)
def getBibData(params)
bib_data = Hash.new
aulast = params['rft.aulast'].presence || params['aulast'].presence || nil

Expand Down Expand Up @@ -83,13 +85,22 @@ def self.getBibData(params)

bib_data['pages'] = 'none specified' if bib_data['pages'].empty?

return bib_data

bib_data
end

def self.getIlliadUserInfo(user, params)
def getIlliadUserInfo(user, params)

db = TinyTds::Client.new(username: ENV['ILLIAD_USERNAME'], password: ENV['ILLIAD_PASSWORD'], host: ENV['ILLIAD_DBHOST'], database: ENV['ILLIAD_DATABASE'])
begin
db = TinyTds::Client.new(username: ENV['ILLIAD_USERNAME'], password: ENV['ILLIAD_PASSWORD'], host: ENV['ILLIAD_DBHOST'], database: ENV['ILLIAD_DATABASE'])
rescue StandardError => e
# TODO: Allow TDS connection to fail in dev, until FreeTDS connection can be debug'd
if Rails.env.development?
puts "TinyTDS connection failed: #{e.message}"
return
end

raise e
end

tablename = Rails.env.production? ? 'usersall' : 'users'

Expand Down Expand Up @@ -131,10 +142,10 @@ def self.getIlliadUserInfo(user, params)

db.close

return userinfo
userinfo
end

def self.getCorrectedDeptDetails(userinfo)
def getCorrectedDeptDetails(userinfo)
if userinfo['status'] != 'StandingFaculty'
return nil
end
Expand All @@ -147,7 +158,7 @@ def self.getCorrectedDeptDetails(userinfo)
end
end

def self.getILLOffice(userinfo)
def getILLOffice(userinfo)
office = nil
active_i = userinfo['org_active_code'].each_with_index.select {|v,i| v != 'I'} .map {|v| v[1]}
active_i.each do |i|
Expand Down Expand Up @@ -179,10 +190,10 @@ def self.getILLOffice(userinfo)
end
end

return office || 'VPL'
office || 'VPL'
end

def self.addIlliadUser(user)
def addIlliadUser(user)

db = TinyTds::Client.new(username: ENV['ILLIAD_USERNAME'], password: ENV['ILLIAD_PASSWORD'], host: ENV['ILLIAD_DBHOST'], database: ENV['ILLIAD_DATABASE'])

Expand Down Expand Up @@ -218,7 +229,7 @@ def self.addIlliadUser(user)
db.close
end

def self.updateIlliadUser(user)
def updateIlliadUser(user)
db = TinyTds::Client.new(username: ENV['ILLIAD_USERNAME'], password: ENV['ILLIAD_PASSWORD'], host: ENV['ILLIAD_DBHOST'], database: ENV['ILLIAD_DATABASE'])

tablename = Rails.env.production? ? 'usersall' : 'users'
Expand All @@ -241,7 +252,7 @@ def self.updateIlliadUser(user)
db.close
end

def self.submit(user, bib_data, params)
def submit(user, bib_data, params)

userinfo = user.data

Expand Down Expand Up @@ -293,8 +304,8 @@ def self.submit(user, bib_data, params)
PhotoArticleTitle: bib_data['chaptitle'],
NotWantedAfter: '12/31/2010',
Notes: bib_data['comments'],
CitedIn: bib_data['sid'],
SubmitButton: 'Submit Request'}
CitedIn: bib_data['sid'],
SubmitButton: 'Submit Request'}
else
illiadreqtype = 'ArticleRequest'
illiadreqtype = 'BookChapterRequest' unless bib_data['requesttype'].index('chapter').nil?
Expand All @@ -315,15 +326,15 @@ def self.submit(user, bib_data, params)
PhotoArticleTitle: bib_data['article'],
NotWantedAfter: '12/31/2010',
Notes: bib_data['comments'],
CitedIn: bib_data['sid'],
SubmitButton: 'Submit Request'}
CitedIn: bib_data['sid'],
SubmitButton: 'Submit Request'}
end

res = HTTParty.post(illserver, body: body, headers: headers)
#/<span class="statusError">(.*)<\/span>/.match(res).nil? should be true unless error with values POSTed to ILLiad
txnumber = /Transaction Number (\d+)\<\/span>/.match(res)[1]

return txnumber
txnumber
end

end
22 changes: 22 additions & 0 deletions spec/features/forms_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
require 'rails_helper'

RSpec.feature 'Form rendering and submission', type: :feature do
before do
# Mock Illiad interactions
allow_any_instance_of(Illiad).to receive(:getIlliadUserInfo).and_return nil
allow_any_instance_of(Illiad).to receive(:addIlliadUser).and_return nil
allow_any_instance_of(Illiad).to receive(:updateIlliadUser).and_return nil
allow_any_instance_of(Illiad).to receive(:submit).and_return 'test_tx_number'
end
let(:book_params) do
{
rfe_dat: '729064964',
Expand Down Expand Up @@ -31,6 +38,21 @@
expect(page).to have_field 'Journal/Book Title', with: 'Phenomenology of perception /'
expect(page).to have_field 'ISBN/ISSN', with: '0415834333'
end
scenario 'upon submission, sends and email and renders confirmation' do
visit form_path({ id: 'ill', requesttype: 'ScanDelivery' }.merge(book_params))
# fill in required fields even though they are only required by JS
test_email = '[email protected]'
fill_in 'Email', with: test_email
fill_in 'Article/Chapter Title', with: 'Other Selves and the Human World'
fill_in 'Issue Date', with: '1945'
click_on 'Submit Request'
expect(ActionMailer::Base.deliveries.length).to eq 1
mksndz marked this conversation as resolved.
Show resolved Hide resolved
mail = ActionMailer::Base.deliveries.first
expect(mail.subject).to eq 'Request Confirmation'
expect(mail.to).to eq [test_email]
expect(page.current_path).to eq form_path(id: 'ill')
expect(page).to have_text 'Your request has been submitted'
end
end
context 'for cataloging errors' do
let(:cataloging_params) do
Expand Down