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..81b9a79d1 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