Skip to content

Commit

Permalink
Merge pull request #999 from datacite/fix-ids-filter
Browse files Browse the repository at this point in the history
Fix ids filter
jrhoads authored Aug 21, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
2 parents 9595700 + c4a9e95 commit 655944a
Showing 2 changed files with 19 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
@@ -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?
15 changes: 15 additions & 0 deletions spec/models/doi/graphql_query_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -57,4 +57,19 @@
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 655944a

Please sign in to comment.