diff --git a/spec/models/client_spec.rb b/spec/models/client_spec.rb index 4dfdb1c17..9a3f18893 100644 --- a/spec/models/client_spec.rb +++ b/spec/models/client_spec.rb @@ -25,6 +25,16 @@ end end + # describe "prefixes" do + # let(:client) { create(:client, provider: provider) } + # let!(:prefix) { create(:prefix, prefix: "10.5072") } + + # it "automatically adds 10.5072 prefix" do + # prefix = client.prefixes + # expect(client.prefixes.count).to eq(2) + # end + # end + describe "methods" do it "should not update the symbol" do client.update_attributes :symbol => client.symbol+'foo.bar' @@ -40,6 +50,8 @@ # expect(Doi.where(datacentre: client.id).count).to eq(5) # expect(Doi.where(datacentre: target.id).count).to eq(0) # client.target_id = target.symbol + # client.save + # sleep 1 # expect(Doi.where(datacentre: client.id).count).to eq(0) # expect(Doi.where(datacentre: target.id).count).to eq(5) # end diff --git a/spec/requests/clients_spec.rb b/spec/requests/clients_spec.rb index 7da1faa88..cbf0494e4 100644 --- a/spec/requests/clients_spec.rb +++ b/spec/requests/clients_spec.rb @@ -100,47 +100,51 @@ end end - # Test suite for POST /clients describe 'POST /clients' do - # context 'when the request is valid' do - # before { post '/clients', params: params.to_json, headers: headers } - # - # it 'creates a client' do - # expect(json.dig('data', 'attributes')).to eq("Imperial College") - # end - # - # it 'returns status code 201' do - # expect(response).to have_http_status(201) - # end - # end + context 'when the request is valid' do + before { post '/clients', params: params.to_json, headers: headers } + + it 'creates a client' do + attributes = json.dig('data', 'attributes') + expect(attributes["name"]).to eq("Imperial College") + expect(attributes["contact-name"]).to eq("Madonna") + + relationships = json.dig('data', 'relationships') + expect(relationships.dig("provider", "data", "id")).to eq(provider.symbol.downcase) + end + + it 'returns status code 201' do + expect(response).to have_http_status(201) + end + end context 'when the request is invalid' do let(:params) do { "data" => { "type" => "clients", "attributes" => { "symbol" => provider.symbol + ".IMPERIAL", - "name" => "Imperial College"}, + "name" => "Imperial College", "contact-name" => "Madonna" }, "relationships": { "provider": { - "data":{ + "data": { "type": "providers", - "id": provider.symbol + "id": provider.symbol.downcase } } - } } + }} } end before { post '/clients', params: params.to_json, headers: headers } - it 'returns status code 500' do - expect(response).to have_http_status(500) + it 'returns status code 422' do + expect(response).to have_http_status(422) end - # it 'returns a validation failure message' do - # expect(json["errors"]).to eq("id"=>"contact_name", "title"=>"Contact name can't be blank") - # end + it 'returns a validation failure message' do + expect(json["errors"]).to eq([{"source"=>"contact_email", "title"=>"Can't be blank"}, {"source"=>"contact_email", "title"=>"Is invalid"}]) + end end end @@ -206,7 +210,6 @@ end end - # Test suite for DELETE /clients/:id describe 'DELETE /clients/:id' do before { delete "/clients/#{client.uid}", headers: headers } diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index 9ad805476..4dd3f0ed7 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -463,7 +463,7 @@ expect(json.dig('data', 'attributes', 'title')).to eq("Eating your own Dog Food") expect(json.dig('data', 'attributes', 'schema-version')).to eq("http://datacite.org/schema/kernel-4") expect(json.dig('data', 'attributes', 'source')).to eq("test") - # expect(json.dig('data', 'relationships', 'resource-type')).to eq(2) + expect(json.dig('data', 'relationships', 'resource-type', 'data', 'id')).to eq("text") xml = Maremma.from_xml(Base64.decode64(json.dig('data', 'attributes', 'xml'))).fetch("resource", {}) expect(xml.dig("resourceType")).to eq("resourceTypeGeneral"=>"Text", "__content__"=>"BlogPosting") @@ -815,6 +815,7 @@ # end # it 'returns status code 201' do + # expect(response.body).to eq(2) # expect(response).to have_http_status(201) # end @@ -906,11 +907,12 @@ # end # it 'returns status code 201' do + # expect(response.body).to eq(2) # expect(response).to have_http_status(201) # end # it 'sets state to registered' do - # #expect(json.dig('data', 'attributes', 'state')).to eq("draft") + # expect(json.dig('data', 'attributes', 'state')).to eq("draft") # end end