diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index 28434ff8c..3967fd564 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -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 diff --git a/app/models/client.rb b/app/models/client.rb index 6f36bbf93..7ba2e7ce5 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -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 diff --git a/openapi.yaml b/openapi.yaml index eaac3e6d1..abd336d28 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -207,6 +207,7 @@ paths: - repository - periodical - igsnCatalog + - raidRegistry - in: query name: repository-type schema: @@ -350,6 +351,7 @@ paths: - repository - periodical - igsnCatalog + - raidRegistry - in: query name: certificate schema: diff --git a/spec/models/client_spec.rb b/spec/models/client_spec.rb index a317b4147..7693d580a 100644 --- a/spec/models/client_spec.rb +++ b/spec/models/client_spec.rb @@ -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 diff --git a/spec/requests/clients_spec.rb b/spec/requests/clients_spec.rb index 9b2329785..31d13ee9e 100644 --- a/spec/requests/clients_spec.rb +++ b/spec/requests/clients_spec.rb @@ -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 @@ -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 diff --git a/spec/requests/datacite_dois_spec.rb b/spec/requests/datacite_dois_spec.rb index 769b8bb9e..914d1986a 100755 --- a/spec/requests/datacite_dois_spec.rb +++ b/spec/requests/datacite_dois_spec.rb @@ -429,7 +429,9 @@ 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 @@ -437,7 +439,7 @@ 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) @@ -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