From d05867a0062b9eba309e41685cd0c0bfdb192f75 Mon Sep 17 00:00:00 2001 From: Bryceson Laing Date: Mon, 23 Oct 2023 13:45:39 +0200 Subject: [PATCH 1/2] Added quick fix for returning Project as resourceType --- app/models/doi.rb | 14 ++++++- config/initializers/constants.rb | 1 + spec/graphql/types/work_type_spec.rb | 61 ++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/app/models/doi.rb b/app/models/doi.rb index 9e533e364..49f381dc1 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -1196,14 +1196,14 @@ def uid end def resource_type_id - r = types.to_h["resourceTypeGeneral"] + r = handleResourceType(types) # types.to_h["resourceTypeGeneral"] r.underscore.dasherize if RESOURCE_TYPES_GENERAL[r].present? rescue TypeError nil end def resource_type_id_and_name - r = types.to_h["resourceTypeGeneral"] + r = handleResourceType(types) # types.to_h["resourceTypeGeneral"] "#{r.underscore.dasherize}:#{RESOURCE_TYPES_GENERAL[r]}" if RESOURCE_TYPES_GENERAL[r].present? rescue TypeError nil @@ -2367,4 +2367,14 @@ def self.add_index_type(options = {}) "Finished updating dois, total #{count}" end + + + # QUICK FIX UNTIL PROJECT IS A RESOURCE_TYPE_GENERAL IN THE SCHEMA + def handleResourceType(types) + if types["resourceType"] == "Project" && (types["resourceTypeGeneral"] == "Text" || types["resourceTypeGeneral"] == "Other") + "Project" + else + types.to_h["resourceTypeGeneral"] + end + end end diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index a112ce3c4..289133dd0 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -82,6 +82,7 @@ class IdentifierError < RuntimeError; end "Standard" => "Standard", "Text" => "Text", "Workflow" => "Workflow", + "Project" => "Project", "Other" => "Other", }.freeze diff --git a/spec/graphql/types/work_type_spec.rb b/spec/graphql/types/work_type_spec.rb index 789136736..784adc7b2 100644 --- a/spec/graphql/types/work_type_spec.rb +++ b/spec/graphql/types/work_type_spec.rb @@ -2031,3 +2031,64 @@ end end end + + + +describe "query with projects (TEMPORARY UNTIL PROJECT IS A RESOURCE_TYPE_GENERAL)", elasticsearch: true do + let!(:text_projects) do + create_list(:doi, 5, aasm_state: "findable", + types: { + "resourceTypeGeneral" => "Text", + "resourceType" => "Project" + }, + ) + end + + let!(:other_projects) do + create_list(:doi, 5, aasm_state: "findable", + types: { + "resourceTypeGeneral" => "Other", + "resourceType" => "Project" + }, + ) + end + + let!(:invalid_projects) do + create_list(:doi, 5, aasm_state: "findable", + types: { + "resourceTypeGeneral" => "Dataset", + "resourceType" => "Project" + }, + ) + end + + before do + Doi.import + sleep 2 + end + + let(:query) do + "query($first: Int, $cursor: String, $facetCount: Int) { + works(first: $first, after: $cursor, facetCount: $facetCount) { + resourceTypes { + id + title + count + } + } + }" + end + + it "returns project resource types" do + response = + LupoSchema.execute( + query, + variables: { first: 15, cursor: nil } + ). + as_json + + expect(response.dig("data", "works", "resourceTypes")).to eq( + [{ "count" => 10, "id" => "project", "title" => "Project" }, { "count" => 5, "id" => "dataset", "title" => "Dataset" }] + ) + end +end \ No newline at end of file From 0415f9a18f9f53f50bcee00d51ac616d6680fff9 Mon Sep 17 00:00:00 2001 From: Bryceson Laing Date: Mon, 23 Oct 2023 15:40:29 +0200 Subject: [PATCH 2/2] Appease Rubocop --- spec/graphql/types/work_type_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/graphql/types/work_type_spec.rb b/spec/graphql/types/work_type_spec.rb index 784adc7b2..81b9a79d1 100644 --- a/spec/graphql/types/work_type_spec.rb +++ b/spec/graphql/types/work_type_spec.rb @@ -2091,4 +2091,4 @@ [{ "count" => 10, "id" => "project", "title" => "Project" }, { "count" => 5, "id" => "dataset", "title" => "Dataset" }] ) end -end \ No newline at end of file +end