Skip to content

Commit

Permalink
Add specs for ids filter. Fix issue with string values
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhoads committed Aug 18, 2023
1 parent 9595700 commit 14a87e2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/doi/graphql_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def must

def filters
options = @options

# turn ids into an array if provided as comma-separated string
options[:ids] = options[:ids].split(",") if options[:ids].is_a?(String)

filter = []
filter << { terms: { doi: options[:ids].map(&:upcase) } } if options[:ids].present?
filter << { term: { "types.resourceTypeGeneral": options[:resource_type_id].underscore.camelize } } if options[:resource_type_id].present?
Expand Down
25 changes: 25 additions & 0 deletions spec/models/doi/graphql_query_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,29 @@
expect(described_class.new("foo/bar", {}).clean_query).to eq("foo\\/bar")
end
end

describe "filters" do
it "is an empty array if not set" do
expect(described_class.new("", {}).filters).to eq([])
expect(described_class.new(nil, {}).filters).to eq([])
end

it "can filter for ids" do
expect(described_class.new("foo", { ids: ["bar"] }).filters).to eq([{ terms: { doi: ["BAR"] } }])
end

it "can filter for ids as single string" do
expect(described_class.new("foo", { ids: "bar" }).filters).to eq([{ terms: { doi: ["BAR"] } }])
end


end








end

0 comments on commit 14a87e2

Please sign in to comment.