Skip to content

Commit

Permalink
Merge pull request #1028 from datacite/fair-work-feature-5
Browse files Browse the repository at this point in the history
Fair Workflows Feature 5
  • Loading branch information
bklaing2 authored Oct 24, 2023
2 parents e8f0d3c + 0415f9a commit b866d60
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions config/initializers/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class IdentifierError < RuntimeError; end
"Standard" => "Standard",
"Text" => "Text",
"Workflow" => "Workflow",
"Project" => "Project",
"Other" => "Other",
}.freeze

Expand Down
61 changes: 61 additions & 0 deletions spec/graphql/types/work_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b866d60

Please sign in to comment.