Skip to content

Commit

Permalink
Test for works type resourceTypeId argument and Schema 4.5 resourceTy…
Browse files Browse the repository at this point in the history
…peGeneral querying in GQL
  • Loading branch information
codycooperross committed Dec 7, 2023
1 parent 93cead1 commit fce75f7
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions spec/graphql/types/work_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2112,3 +2112,75 @@
expect(response.dig("data", "works", "totalCount")).to eq(10)
end
end

describe "query with resourceTypeId", elasticsearch: true do
let!(:instrument_doi) do
create(:doi, aasm_state: "findable",
types: {
"resourceTypeGeneral" => "Instrument",
},
)
end

let!(:study_registration_doi) do
create(:doi, aasm_state: "findable",
types: {
"resourceTypeGeneral" => "StudyRegistration",
},
)
end

before do
Doi.import
sleep 2
end

let(:query) do
"query($first: Int, $cursor: String, $resourceTypeId: String) {
works(first: $first, after: $cursor, resourceTypeId: $resourceTypeId) {
totalCount
resourceTypes {
id
title
count
}
nodes {
doi
types {
resourceTypeGeneral
}
}
}
}"
end

it "returns instrument resource types" do
response =
LupoSchema.execute(
query,
variables: { resourceTypeId: "instrument" }
).
as_json

expect(response.dig("data", "works", "resourceTypes")).to eq(
[{ "count" => 1, "id" => "instrument", "title" => "Instrument" }]
)
expect(response.dig("data", "works", "nodes", 0, "doi")).to eq(instrument_doi.doi.downcase)
expect(response.dig("data", "works", "nodes", 0, "types", "resourceTypeGeneral")).to eq("Instrument")
end

it "returns study registration resource types" do
response =
LupoSchema.execute(
query,
variables: { resourceTypeId: "study-registration" }
).
as_json

expect(response.dig("data", "works", "resourceTypes")).to eq(
[{ "count" => 1, "id" => "study-registration", "title" => "Study Registration" }]
)
expect(response.dig("data", "works", "nodes", 0, "doi")).to eq(study_registration_doi.doi.downcase)
expect(response.dig("data", "works", "nodes", 0, "types", "resourceTypeGeneral")).to eq("StudyRegistration")
end
end

0 comments on commit fce75f7

Please sign in to comment.