From 14a87e283a517eb0a467768d8a97910002d2907d Mon Sep 17 00:00:00 2001 From: jrhoads Date: Fri, 18 Aug 2023 17:28:13 -0400 Subject: [PATCH 1/2] Add specs for ids filter. Fix issue with string values --- app/models/doi/graphql_query.rb | 4 +++ spec/models/doi/graphql_query_builder_spec.rb | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/models/doi/graphql_query.rb b/app/models/doi/graphql_query.rb index 1da39ed92..2399d7652 100644 --- a/app/models/doi/graphql_query.rb +++ b/app/models/doi/graphql_query.rb @@ -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? diff --git a/spec/models/doi/graphql_query_builder_spec.rb b/spec/models/doi/graphql_query_builder_spec.rb index b6d5a125a..ad5d87aad 100644 --- a/spec/models/doi/graphql_query_builder_spec.rb +++ b/spec/models/doi/graphql_query_builder_spec.rb @@ -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 From c4a9e959315e97d8aed9856b00ce98ea6a0731de Mon Sep 17 00:00:00 2001 From: jrhoads Date: Fri, 18 Aug 2023 17:29:31 -0400 Subject: [PATCH 2/2] Appease Rubocop --- spec/models/doi/graphql_query_builder_spec.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/spec/models/doi/graphql_query_builder_spec.rb b/spec/models/doi/graphql_query_builder_spec.rb index ad5d87aad..c506a9017 100644 --- a/spec/models/doi/graphql_query_builder_spec.rb +++ b/spec/models/doi/graphql_query_builder_spec.rb @@ -71,15 +71,5 @@ 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