Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ids filter #999

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 15 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,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