berkeley_library-alma 0.0.3 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ module BerkeleyLibrary
4
+ module Alma
5
+ module SRU
6
+ describe XMLReader do
7
+ let(:sru_xml_1) { File.read('spec/data/availability-sru-page-1.xml') }
8
+ let(:sru_xml_2) { File.read('spec/data/availability-sru-page-2.xml') }
9
+
10
+ let(:reader) { XMLReader.read(sru_xml_2) }
11
+ let(:expected_ids) { %w[991008719659706532 991005668209706532 991008363529706532 991008402049706532 991008719819706532] }
12
+
13
+ it 'reads the records' do
14
+ records = reader.to_a
15
+ expect(records.size).to eq(expected_ids.size)
16
+ expect(records.map(&:record_id)).to eq(expected_ids)
17
+ end
18
+
19
+ describe :new do
20
+ it 'raises an error for unreadable sources' do
21
+ not_xml = Object.new
22
+ expect { XMLReader.read(not_xml) }.to raise_error(ArgumentError)
23
+ end
24
+ end
25
+
26
+ describe :num_records do
27
+ it 'returns the <numberOfRecords/> value' do
28
+ reader.first # make sure we've gotten far enough in the doc to parse
29
+ expect(reader.num_records).to eq(15)
30
+ end
31
+ end
32
+
33
+ describe :last_record_position do
34
+ it 'returns the (1-indexed) position of the most recent record' do
35
+ position_base = 11
36
+ reader.each_with_index do |_, i|
37
+ expect(reader.last_record_position).to eq(position_base + i)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe :last_record_id do
43
+ it 'returns the ID of the most recent record' do
44
+ reader.each do |record|
45
+ expect(reader.last_record_id).to eq(record.record_id)
46
+ end
47
+ end
48
+ end
49
+
50
+ describe :next_record_position do
51
+ it 'returns nil if there is no next page' do
52
+ reader.to_a # read all records
53
+ expect(reader.next_record_position).to be_nil
54
+ end
55
+
56
+ it 'returns the record position of the next page' do
57
+ reader = XMLReader.read(sru_xml_1)
58
+ reader.to_a # read all records
59
+ expect(reader.next_record_position).to eq(11)
60
+ end
61
+ end
62
+
63
+ describe :records_yielded do
64
+ it 'returns the number of records yielded' do
65
+ expect(reader.records_yielded).to eq(0)
66
+ reader.each_with_index do |_, i|
67
+ expect(reader.records_yielded).to eq(i)
68
+ end
69
+ expect(reader.records_yielded).to eq(5)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
data/spec/spec_helper.rb CHANGED
@@ -31,26 +31,17 @@ require 'berkeley_library/alma'
31
31
  # ------------------------------------------------------------
32
32
  # Utility methods
33
33
 
34
- def sru_url_for(record_id)
35
- sru_url_base = 'https://berkeley.alma.exlibrisgroup.com/view/sru/01UCS_BER?version=1.2&operation=searchRetrieve&query='
36
-
37
- if BerkeleyLibrary::Alma::Constants::ALMA_RECORD_RE =~ record_id
38
- "#{sru_url_base}alma.mms_id%3D#{record_id}"
39
- elsif BerkeleyLibrary::Alma::Constants::MILLENNIUM_RECORD_RE =~ record_id
40
- full_bib_number = BerkeleyLibrary::Alma::BibNumber.new(record_id).to_s
41
- "#{sru_url_base}alma.local_field_996%3D#{full_bib_number}"
42
- else
43
- raise ArgumentError, "Unknown record ID type: #{record_id}"
44
- end
34
+ def sru_url_for(index, value)
35
+ "https://berkeley.alma.exlibrisgroup.com/view/sru/01UCS_BER?version=1.2&operation=searchRetrieve&query=#{index}%3D#{value}"
45
36
  end
46
37
 
47
38
  def sru_data_path_for(record_id)
48
39
  "spec/data/#{record_id}-sru.xml"
49
40
  end
50
41
 
51
- def stub_sru_request(record_id)
52
- sru_url = sru_url_for(record_id)
53
- marc_xml_path = sru_data_path_for(record_id)
42
+ def stub_sru_request(index, value)
43
+ sru_url_ = sru_url_for(index, value)
44
+ marc_xml_path = sru_data_path_for(value)
54
45
 
55
- stub_request(:get, sru_url).to_return(status: 200, body: File.read(marc_xml_path))
46
+ stub_request(:get, sru_url_).to_return(status: 200, body: File.read(marc_xml_path))
56
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkeley_library-alma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-03 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: berkeley_library-logging
@@ -47,7 +47,7 @@ dependencies:
47
47
  version: '0.1'
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: 0.1.1
50
+ version: 0.1.2
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -57,7 +57,7 @@ dependencies:
57
57
  version: '0.1'
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 0.1.1
60
+ version: 0.1.2
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: nokogiri
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -269,12 +269,16 @@ files:
269
269
  - bin/alma-mms-lookup
270
270
  - docker-compose.yml
271
271
  - lib/berkeley_library/alma.rb
272
+ - lib/berkeley_library/alma/barcode.rb
272
273
  - lib/berkeley_library/alma/bib_number.rb
273
274
  - lib/berkeley_library/alma/config.rb
274
275
  - lib/berkeley_library/alma/constants.rb
275
276
  - lib/berkeley_library/alma/mms_id.rb
276
277
  - lib/berkeley_library/alma/module_info.rb
277
278
  - lib/berkeley_library/alma/record_id.rb
279
+ - lib/berkeley_library/alma/sru.rb
280
+ - lib/berkeley_library/alma/sru/sru.rb
281
+ - lib/berkeley_library/alma/sru/xml_reader.rb
278
282
  - rakelib/bundle.rake
279
283
  - rakelib/coverage.rake
280
284
  - rakelib/gem.rake
@@ -282,12 +286,19 @@ files:
282
286
  - rakelib/spec.rake
283
287
  - spec/.rubocop.yml
284
288
  - spec/data/991054360089706532-sru.xml
285
- - spec/data/b11082434-sru.xml
289
+ - spec/data/C084093187-sru.xml
290
+ - spec/data/availability-sru-page-1.xml
291
+ - spec/data/availability-sru-page-2.xml
292
+ - spec/data/availability-sru.xml
293
+ - spec/data/b110824349-sru.xml
286
294
  - spec/data/bibs_with_check_digits.txt
295
+ - spec/lib/berkeley_library/alma/barcode_spec.rb
287
296
  - spec/lib/berkeley_library/alma/bib_number_spec.rb
288
297
  - spec/lib/berkeley_library/alma/config_spec.rb
289
298
  - spec/lib/berkeley_library/alma/mms_id_spec.rb
290
299
  - spec/lib/berkeley_library/alma/record_id_spec.rb
300
+ - spec/lib/berkeley_library/alma/sru/sru_spec.rb
301
+ - spec/lib/berkeley_library/alma/sru/xml_reader_spec.rb
291
302
  - spec/spec_helper.rb
292
303
  homepage: https://github.com/BerkeleyLibrary/alma
293
304
  licenses:
@@ -315,10 +326,17 @@ summary: Alma/Primo utilities for the UC Berkeley Library
315
326
  test_files:
316
327
  - spec/.rubocop.yml
317
328
  - spec/data/991054360089706532-sru.xml
318
- - spec/data/b11082434-sru.xml
329
+ - spec/data/C084093187-sru.xml
330
+ - spec/data/availability-sru-page-1.xml
331
+ - spec/data/availability-sru-page-2.xml
332
+ - spec/data/availability-sru.xml
333
+ - spec/data/b110824349-sru.xml
319
334
  - spec/data/bibs_with_check_digits.txt
335
+ - spec/lib/berkeley_library/alma/barcode_spec.rb
320
336
  - spec/lib/berkeley_library/alma/bib_number_spec.rb
321
337
  - spec/lib/berkeley_library/alma/config_spec.rb
322
338
  - spec/lib/berkeley_library/alma/mms_id_spec.rb
323
339
  - spec/lib/berkeley_library/alma/record_id_spec.rb
340
+ - spec/lib/berkeley_library/alma/sru/sru_spec.rb
341
+ - spec/lib/berkeley_library/alma/sru/xml_reader_spec.rb
324
342
  - spec/spec_helper.rb