debian-mirror-gitlab/spec/requests/api/services_spec.rb

93 lines
3.1 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require "spec_helper"
describe API::API, api: true do
include ApiHelpers
let(:user) { create(:user) }
2015-10-24 18:46:33 +05:30
let(:admin) { create(:admin) }
let(:user2) { create(:user) }
2014-09-02 18:07:02 +05:30
let(:project) {create(:project, creator_id: user.id, namespace: user.namespace) }
2015-09-25 12:07:36 +05:30
Service.available_services_names.each do |service|
describe "PUT /projects/:id/services/#{service.dasherize}" do
include_context service
2014-09-02 18:07:02 +05:30
2016-09-13 17:45:13 +05:30
it "updates #{service} settings" do
2015-09-25 12:07:36 +05:30
put api("/projects/#{project.id}/services/#{dashed_service}", user), service_attrs
2014-09-02 18:07:02 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-09-25 12:07:36 +05:30
end
2015-09-11 14:41:01 +05:30
2016-09-13 17:45:13 +05:30
it "returns if required fields missing" do
2015-09-25 12:07:36 +05:30
attrs = service_attrs
2015-09-11 14:41:01 +05:30
2015-09-25 12:07:36 +05:30
required_attributes = service_attrs_list.select do |attr|
service_klass.validators_on(attr).any? do |v|
v.class == ActiveRecord::Validations::PresenceValidator
end
end
2015-09-11 14:41:01 +05:30
2015-09-25 12:07:36 +05:30
if required_attributes.empty?
expected_code = 200
else
2015-12-23 02:04:40 +05:30
attrs.delete(required_attributes.sample)
2015-09-25 12:07:36 +05:30
expected_code = 400
end
2016-09-13 17:45:13 +05:30
2015-09-25 12:07:36 +05:30
put api("/projects/#{project.id}/services/#{dashed_service}", user), attrs
2015-09-11 14:41:01 +05:30
2015-09-25 12:07:36 +05:30
expect(response.status).to eq(expected_code)
end
2015-09-11 14:41:01 +05:30
end
2014-09-02 18:07:02 +05:30
2015-09-25 12:07:36 +05:30
describe "DELETE /projects/:id/services/#{service.dasherize}" do
include_context service
2014-09-02 18:07:02 +05:30
2016-09-13 17:45:13 +05:30
it "deletes #{service}" do
2015-09-25 12:07:36 +05:30
delete api("/projects/#{project.id}/services/#{dashed_service}", user)
2015-04-26 12:48:37 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-11-26 14:37:03 +05:30
project.send(service_method).reload
2015-09-25 12:07:36 +05:30
expect(project.send(service_method).activated?).to be_falsey
end
2015-04-26 12:48:37 +05:30
end
2015-09-25 12:07:36 +05:30
describe "GET /projects/:id/services/#{service.dasherize}" do
include_context service
2015-04-26 12:48:37 +05:30
2015-10-24 18:46:33 +05:30
# inject some properties into the service
before do
project.build_missing_services
service_object = project.send(service_method)
service_object.properties = service_attrs
service_object.save
end
2016-09-13 17:45:13 +05:30
it 'returns authentication error when unauthenticated' do
2015-10-24 18:46:33 +05:30
get api("/projects/#{project.id}/services/#{dashed_service}")
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(401)
2015-10-24 18:46:33 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns all properties of service #{service} when authenticated as admin" do
2015-10-24 18:46:33 +05:30
get api("/projects/#{project.id}/services/#{dashed_service}", admin)
2016-09-13 17:45:13 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-10-24 18:46:33 +05:30
expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list.map)
end
2016-09-13 17:45:13 +05:30
it "returns properties of service #{service} other than passwords when authenticated as project owner" do
2015-09-25 12:07:36 +05:30
get api("/projects/#{project.id}/services/#{dashed_service}", user)
2015-04-26 12:48:37 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-10-24 18:46:33 +05:30
expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list_without_passwords)
2015-09-25 12:07:36 +05:30
end
2015-10-24 18:46:33 +05:30
2016-09-13 17:45:13 +05:30
it "returns error when authenticated but not a project owner" do
2015-10-24 18:46:33 +05:30
project.team << [user2, :developer]
get api("/projects/#{project.id}/services/#{dashed_service}", user2)
2016-09-13 17:45:13 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(403)
2015-10-24 18:46:33 +05:30
end
2014-09-02 18:07:02 +05:30
end
end
end