-
Notifications
You must be signed in to change notification settings - Fork 14
/
primo_engine_test.rb
73 lines (51 loc) · 2.36 KB
/
primo_engine_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'test_helper'
class PrimoEngineTest < ActiveSupport::TestCase
extend TestWithCassette
# dummy host needs to be in all lowercase, and not explicitly
# say '80' to work right with VCR
@@host_port = (ENV['PRIMO_HOST_PORT'] || 'example.org' )
@@institution = (ENV['PRIMO_INSTITUTION'] || 'DUMMY_INSTITUTION')
VCR.configure do |c|
c.filter_sensitive_data("example.org", :primo) { @@host_port }
c.filter_sensitive_data("DUMMY_INSTITUTION", :primo) { @@institution }
end
def setup
@engine = BentoSearch::PrimoEngine.new(:host_port => @@host_port, :institution => @@institution)
end
test("always includes indx") do
# primo sometimes requires an indx, of for instance 1
url = @engine.construct_query(:query => "cancer")
query_params = CGI.parse( URI.parse(url).query )
assert_equal ["1"], query_params["indx"]
end
test("sort params") do
url = @engine.construct_query(:query => "cancer", :sort => "title_asc")
query_params = CGI.parse( URI.parse(url).query )
assert_equal ["stitle"], query_params["sortField"]
# for 'relevance', no sortField should be passed to primo api
url = @engine.construct_query(:query => "cancer", :sort => "relevance")
query_params = CGI.parse( URI.parse(url).query )
assert ! query_params.has_key?("sortField"), "for relevance sort, no sortField should be passed to primo api"
end
test_with_cassette("search smoke test", :primo) do
results = @engine.search_implementation(:query => "globalization from below", :per_page => 10)
assert_present results, "has results"
assert_present results.total_items, "has total_items"
first = results[6]
# not every result has every field, but at time we recorded
# with VCR, this result for this search did. Sorry, a bit fragile.
# publisher
%w{format_str format title authors volume issue start_page journal_title issn unique_id}.each do |attr|
assert_present first.send(attr), "must have #{attr}"
end
end
# test of highlighting assumes if search for 'cancer', then
# that word will be in title of first hit.
test_with_cassette("proper tags for snippets", :primo) do
results = @engine.search("cancer")
first = results.first
assert first.title.html_safe?, "title is HTML safe"
assert_includes first.title, '<b class="bento_search_highlight">'
assert_present first.snippets
end
end