Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements raidRegistry client_type for Client #1185

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ module Facetable
CLIENT_TYPES = {
"repository" => "Repository",
"periodical" => "Periodical",
"igsnCatalog" => "IGSN ID Catalog"
"igsnCatalog" => "IGSN ID Catalog",
"raidRegistry" => "RAiD Registry",
}.freeze

OTHER = { "__other__" => "Other", "__missing__" => "Missing" }.freeze
Expand Down
2 changes: 1 addition & 1 deletion app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Client < ApplicationRecord
in: %w[ROLE_DATACENTRE],
message: "Role %s is not included in the list"
validates_inclusion_of :client_type,
in: %w[repository periodical igsnCatalog],
in: %w[repository periodical igsnCatalog raidRegistry],
message: "Client type %s is not included in the list"
validates_associated :provider
validate :check_id, on: :create
Expand Down
2 changes: 2 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ paths:
- repository
- periodical
- igsnCatalog
- raidRegistry
- in: query
name: repository-type
schema:
Expand Down Expand Up @@ -350,6 +351,7 @@ paths:
- repository
- periodical
- igsnCatalog
- raidRegistry
- in: query
name: certificate
schema:
Expand Down
6 changes: 6 additions & 0 deletions spec/models/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@
expect(client.errors.details).to be_empty
end

it "raidRegistry" do
client.client_type = "raidRegistry"
expect(client.save).to be true
expect(client.errors.details).to be_empty
end

it "unsupported" do
client.client_type = "conference"
expect(client.save).to be false
Expand Down
40 changes: 40 additions & 0 deletions spec/requests/clients_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,26 @@
}
end

let(:raid_registry_client_id) { provider.symbol + ".RAID" }
let(:params_raid_registry) do
{
"data" => {
"type" => "clients",
"attributes" => {
"symbol" => raid_registry_client_id,
"name" => "Imperial College",
"contactEmail" => "bob@example.com",
"clientType" => "raidRegistry",
},
"relationships": {
"provider": {
"data": { "type": "providers", "id": provider.uid },
},
},
},
}
end

it "creates a client" do
post "/clients", params, headers

Expand Down Expand Up @@ -168,6 +188,26 @@
{ "count" => 1, "id" => "igsnCatalog", "title" => "IGSN ID Catalog" },
)
end

it "creates a client with raidRegistry client_type" do
post "/clients", params_raid_registry, headers

expect(last_response.status).to eq(201)
attributes = json.dig("data", "attributes")
expect(attributes["clientType"]).to eq("raidRegistry")

Client.import
sleep 2

get "/clients", nil, headers

expect(json["data"].size).to eq(2)
raid_registry_client = json.dig("data").find { |client| client.dig("attributes", "clientType") == "raidRegistry" }
expect(raid_registry_client.dig("attributes", "symbol")).to eq(raid_registry_client_id)
expect(json.dig("meta", "clientTypes").find { |clientTypeAgg| clientTypeAgg["id"] == "raidRegistry" }).to eq(
{ "count" => 1, "id" => "raidRegistry", "title" => "RAiD Registry" },
)
end
end

context "when the request is invalid" do
Expand Down
12 changes: 11 additions & 1 deletion spec/requests/datacite_dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,17 @@
describe "GET /dois with client-type filter", elasticsearch: true do
let!(:dois) { create_list(:doi, 10, client: client, aasm_state: "findable", version_info: "testtag") }
let(:client_igsn_id_catalog) { create(:client, provider: provider, client_type: "igsnCatalog") }
let(:client_raid_registry) { create(:client, provider: provider, client_type: "raidRegistry") }
let!(:doi_igsn_id) { create(:doi, client: client_igsn_id_catalog, aasm_state: "findable", types: { "resourceTypeGeneral": "PhysicalObject" }) }
let!(:doi_raid_registry) { create(:doi, client: client_raid_registry, aasm_state: "findable", types: { "resourceTypeGeneral": "Other", "resourceType": "Project" }) }
let!(:dois_other) { create_list(:doi, 5, client: client_igsn_id_catalog, aasm_state: "findable", types: { "resourceTypeGeneral": "Dataset" }) }

before do
DataciteDoi.import
sleep 2
end

it "filters by client_type when client-type is set", vcr: true do
it "filters by repository client_type when client-type is set", vcr: true do
get "/dois?client-type=repository", nil, headers

expect(last_response.status).to eq(200)
Expand All @@ -452,6 +454,14 @@
expect(json.dig("data", 0, "id")).to eq(doi_igsn_id.uid)
expect(json.dig("meta", "createdByMonth", 0, "title")).to eq(doi_igsn_id.created.to_time.strftime("%Y-%m"))
end

it "filters by raidRegistry client_type when client-type is set", vcr: true do
get "/dois?client-type=raidRegistry", nil, headers

expect(last_response.status).to eq(200)
expect(json["data"].size).to eq(1)
expect(json.dig("data", 0, "id")).to eq(doi_raid_registry.uid)
end
end

describe "GET /dois with resource-type-id filter", elasticsearch: true do
Expand Down