Skip to content

Commit

Permalink
Remove unused endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 10, 2019
1 parent fe21de7 commit ce01137
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 68 deletions.
24 changes: 3 additions & 21 deletions app/controllers/marcxml_controller.rb
@@ -1,31 +1,13 @@
# frozen_string_literal: true

class MarcxmlController < ApplicationController #:nodoc:
before_action :set_marcxml_resource

class MarcxmlController < ApplicationController #:nodoc
rescue_from(SymphonyReader::RecordIncompleteError) do |e|
render status: :internal_server_error, plain: e.message
end

def catkey
render plain: @marcxml.catkey
end

def marcxml
render xml: @marcxml.marcxml
end

def mods
render xml: @marcxml.mods
end

private

def set_marcxml_resource
@marcxml = MarcxmlResource.find_by(**marcxml_resource_params)
end
marcxml = MarcxmlResource.find_by(barcode: params[:barcode])

def marcxml_resource_params
params.slice(:barcode, :catkey).to_unsafe_h.symbolize_keys
render plain: marcxml.catkey
end
end
2 changes: 0 additions & 2 deletions config/routes.rb
Expand Up @@ -15,8 +15,6 @@
end

scope :catalog do
get 'marcxml', to: 'marcxml#marcxml'
get 'mods', to: 'marcxml#mods'
get 'catkey', to: 'marcxml#catkey'
end

Expand Down
45 changes: 0 additions & 45 deletions spec/controllers/marcxml_controller_spec.rb
Expand Up @@ -33,55 +33,10 @@
end

describe 'GET catkey' do
it 'returns the provided catkey' do
get :catkey, params: { catkey: '12345' }
expect(response.body).to eq '12345'
end

it 'looks up an item by barcode' do
stub_request(:get, format(Settings.catalog.barcode_search_url, barcode: '98765')).to_return(body: { barcode: '98765', id: '12345' }.to_json)
get :catkey, params: { barcode: '98765' }
expect(response.body).to eq '12345'
end
end

describe 'GET marcxml' do
it 'retrieves MARCXML' do
stub_request(:get, format(Settings.catalog.symphony.json_url, catkey: resource.catkey)).to_return(body: body.to_json, headers: { 'Content-Length': 394 })
get :marcxml, params: { catkey: '12345' }
expect(response.body).to start_with '<record'
end

context 'when incomplete response from Symphony' do
before do
stub_request(:get, format(Settings.catalog.symphony.json_url, catkey: resource.catkey)).to_return(body: '{}', headers: { 'Content-Length': 0 })
end

it 'returns a 500 error' do
get :marcxml, params: { catkey: '12345' }
expect(response.status).to eq(500)
expect(response.body).to eq('Incomplete response received from Symphony for 12345 - expected 0 bytes but got 2')
end
end
end

describe 'GET mods' do
it 'transforms the MARCXML into MODS' do
stub_request(:get, format(Settings.catalog.symphony.json_url, catkey: resource.catkey)).to_return(body: body.to_json, headers: { 'Content-Length': 394 })
get :mods, params: { catkey: '12345' }
expect(response.body).to match(/mods/)
end

context 'when incomplete response from Symphony' do
before do
stub_request(:get, format(Settings.catalog.symphony.json_url, catkey: resource.catkey)).to_return(body: '{}', headers: { 'Content-Length': 0 })
end

it 'returns a 500 error' do
get :mods, params: { catkey: '12345' }
expect(response.status).to eq(500)
expect(response.body).to eq('Incomplete response received from Symphony for 12345 - expected 0 bytes but got 2')
end
end
end
end

0 comments on commit ce01137

Please sign in to comment.