Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/services_spec.rb')
-rw-r--r--spec/requests/api/services_spec.rb186
1 files changed, 104 insertions, 82 deletions
diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb
index f7394fa0cb4..e550132e776 100644
--- a/spec/requests/api/services_spec.rb
+++ b/spec/requests/api/services_spec.rb
@@ -24,14 +24,14 @@ RSpec.describe API::Services do
expect(response).to have_gitlab_http_status(:forbidden)
end
- context 'project with services' do
+ context 'with integrations' do
let!(:active_integration) { create(:emails_on_push_integration, project: project, active: true) }
let!(:integration) { create(:custom_issue_tracker_integration, project: project, active: false) }
- it "returns a list of all active services" do
+ it "returns a list of all active integrations" do
get api("/projects/#{project.id}/services", user)
- aggregate_failures 'expect successful response with all active services' do
+ aggregate_failures 'expect successful response with all active integrations' do
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_an Array
expect(json_response.count).to eq(1)
@@ -42,41 +42,39 @@ RSpec.describe API::Services do
end
end
- Integration.available_services_names.each do |service|
- describe "PUT /projects/:id/services/#{service.dasherize}" do
- include_context service
+ Integration.available_integration_names.each do |integration|
+ describe "PUT /projects/:id/services/#{integration.dasherize}" do
+ include_context integration
- it "updates #{service} settings" do
- put api("/projects/#{project.id}/services/#{dashed_service}", user), params: service_attrs
+ it "updates #{integration} settings" do
+ put api("/projects/#{project.id}/services/#{dashed_integration}", user), params: integration_attrs
expect(response).to have_gitlab_http_status(:ok)
- current_service = project.integrations.first
- events = current_service.event_names.empty? ? ["foo"].freeze : current_service.event_names
+ current_integration = project.integrations.first
+ events = current_integration.event_names.empty? ? ["foo"].freeze : current_integration.event_names
query_strings = []
events.each do |event|
- query_strings << "#{event}=#{!current_service[event]}"
+ query_strings << "#{event}=#{!current_integration[event]}"
end
query_strings = query_strings.join('&')
- put api("/projects/#{project.id}/services/#{dashed_service}?#{query_strings}", user), params: service_attrs
+ put api("/projects/#{project.id}/services/#{dashed_integration}?#{query_strings}", user), params: integration_attrs
expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['slug']).to eq(dashed_service)
+ expect(json_response['slug']).to eq(dashed_integration)
events.each do |event|
next if event == "foo"
- expect(project.integrations.first[event]).not_to eq(current_service[event]),
- "expected #{!current_service[event]} for event #{event} for service #{current_service.title}, got #{current_service[event]}"
+ expect(project.integrations.first[event]).not_to eq(current_integration[event]),
+ "expected #{!current_integration[event]} for event #{event} for service #{current_integration.title}, got #{current_integration[event]}"
end
end
it "returns if required fields missing" do
- attrs = service_attrs
-
- required_attributes = service_attrs_list.select do |attr|
- service_klass.validators_on(attr).any? do |v|
- v.class == ActiveRecord::Validations::PresenceValidator &&
+ required_attributes = integration_attrs_list.select do |attr|
+ integration_klass.validators_on(attr).any? do |v|
+ v.instance_of?(ActiveRecord::Validations::PresenceValidator) &&
# exclude presence validators with conditional since those are not really required
![:if, :unless].any? { |cond| v.options.include?(cond) }
end
@@ -85,85 +83,85 @@ RSpec.describe API::Services do
if required_attributes.empty?
expected_code = :ok
else
- attrs.delete(required_attributes.sample)
+ integration_attrs.delete(required_attributes.sample)
expected_code = :bad_request
end
- put api("/projects/#{project.id}/services/#{dashed_service}", user), params: attrs
+ put api("/projects/#{project.id}/services/#{dashed_integration}", user), params: integration_attrs
expect(response).to have_gitlab_http_status(expected_code)
end
end
- describe "DELETE /projects/:id/services/#{service.dasherize}" do
- include_context service
+ describe "DELETE /projects/:id/services/#{integration.dasherize}" do
+ include_context integration
before do
- initialize_service(service)
+ initialize_integration(integration)
end
- it "deletes #{service}" do
- delete api("/projects/#{project.id}/services/#{dashed_service}", user)
+ it "deletes #{integration}" do
+ delete api("/projects/#{project.id}/services/#{dashed_integration}", user)
expect(response).to have_gitlab_http_status(:no_content)
- project.send(service_method).reload
- expect(project.send(service_method).activated?).to be_falsey
+ project.send(integration_method).reload
+ expect(project.send(integration_method).activated?).to be_falsey
end
end
- describe "GET /projects/:id/services/#{service.dasherize}" do
- include_context service
+ describe "GET /projects/:id/services/#{integration.dasherize}" do
+ include_context integration
- let!(:initialized_service) { initialize_service(service, active: true) }
+ let!(:initialized_integration) { initialize_integration(integration, active: true) }
let_it_be(:project2) do
create(:project, creator_id: user.id, namespace: user.namespace)
end
- def deactive_service!
- return initialized_service.update!(active: false) unless initialized_service.is_a?(PrometheusService)
+ def deactive_integration!
+ return initialized_integration.update!(active: false) unless initialized_integration.is_a?(::Integrations::Prometheus)
- # PrometheusService sets `#active` itself within a `before_save`:
- initialized_service.manual_configuration = false
- initialized_service.save!
+ # Integrations::Prometheus sets `#active` itself within a `before_save`:
+ initialized_integration.manual_configuration = false
+ initialized_integration.save!
end
it 'returns authentication error when unauthenticated' do
- get api("/projects/#{project.id}/services/#{dashed_service}")
+ get api("/projects/#{project.id}/services/#{dashed_integration}")
expect(response).to have_gitlab_http_status(:unauthorized)
end
- it "returns all properties of active service #{service}" do
- get api("/projects/#{project.id}/services/#{dashed_service}", user)
+ it "returns all properties of active service #{integration}" do
+ get api("/projects/#{project.id}/services/#{dashed_integration}", user)
- expect(initialized_service).to be_active
+ expect(initialized_integration).to be_active
expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['properties'].keys).to match_array(service_instance.api_field_names)
+ expect(json_response['properties'].keys).to match_array(integration_instance.api_field_names)
end
- it "returns all properties of inactive service #{service}" do
- deactive_service!
+ it "returns all properties of inactive integration #{integration}" do
+ deactive_integration!
- get api("/projects/#{project.id}/services/#{dashed_service}", user)
+ get api("/projects/#{project.id}/services/#{dashed_integration}", user)
- expect(initialized_service).not_to be_active
+ expect(initialized_integration).not_to be_active
expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['properties'].keys).to match_array(service_instance.api_field_names)
+ expect(json_response['properties'].keys).to match_array(integration_instance.api_field_names)
end
- it "returns not found if service does not exist" do
- get api("/projects/#{project2.id}/services/#{dashed_service}", user)
+ it "returns not found if integration does not exist" do
+ get api("/projects/#{project2.id}/services/#{dashed_integration}", user)
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Service Not Found')
end
- it "returns not found if service exists but is in `Project#disabled_services`" do
+ it "returns not found if service exists but is in `Project#disabled_integrations`" do
expect_next_found_instance_of(Project) do |project|
- expect(project).to receive(:disabled_services).at_least(:once).and_return([service])
+ expect(project).to receive(:disabled_integrations).at_least(:once).and_return([integration])
end
- get api("/projects/#{project.id}/services/#{dashed_service}", user)
+ get api("/projects/#{project.id}/services/#{dashed_integration}", user)
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Service Not Found')
@@ -171,7 +169,7 @@ RSpec.describe API::Services do
it "returns error when authenticated but not a project owner" do
project.add_developer(user2)
- get api("/projects/#{project.id}/services/#{dashed_service}", user2)
+ get api("/projects/#{project.id}/services/#{dashed_integration}", user2)
expect(response).to have_gitlab_http_status(:forbidden)
end
@@ -179,10 +177,10 @@ RSpec.describe API::Services do
end
describe 'POST /projects/:id/services/:slug/trigger' do
- describe 'Mattermost Service' do
- let(:service_name) { 'mattermost_slash_commands' }
+ describe 'Mattermost integration' do
+ let(:integration_name) { 'mattermost_slash_commands' }
- context 'no service is available' do
+ context 'when no integration is available' do
it 'returns a not found message' do
post api("/projects/#{project.id}/services/idonotexist/trigger")
@@ -191,34 +189,34 @@ RSpec.describe API::Services do
end
end
- context 'the service exists' do
+ context 'when the integration exists' do
let(:params) { { token: 'token' } }
- context 'the service is not active' do
+ context 'when the integration is not active' do
before do
- project.create_mattermost_slash_commands_service(
+ project.create_mattermost_slash_commands_integration(
active: false,
properties: params
)
end
- it 'when the service is inactive' do
- post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: params
+ it 'when the integration is inactive' do
+ post api("/projects/#{project.id}/services/#{integration_name}/trigger"), params: params
expect(response).to have_gitlab_http_status(:not_found)
end
end
- context 'the service is active' do
+ context 'when the integration is active' do
before do
- project.create_mattermost_slash_commands_service(
+ project.create_mattermost_slash_commands_integration(
active: true,
properties: params
)
end
it 'returns status 200' do
- post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: params
+ post api("/projects/#{project.id}/services/#{integration_name}/trigger"), params: params
expect(response).to have_gitlab_http_status(:ok)
end
@@ -226,7 +224,7 @@ RSpec.describe API::Services do
context 'when the project can not be found' do
it 'returns a generic 404' do
- post api("/projects/404/services/#{service_name}/trigger"), params: params
+ post api("/projects/404/services/#{integration_name}/trigger"), params: params
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response["message"]).to eq("404 Service Not Found")
@@ -235,18 +233,18 @@ RSpec.describe API::Services do
end
end
- describe 'Slack Service' do
- let(:service_name) { 'slack_slash_commands' }
+ describe 'Slack Integration' do
+ let(:integration_name) { 'slack_slash_commands' }
before do
- project.create_slack_slash_commands_service(
+ project.create_slack_slash_commands_integration(
active: true,
properties: { token: 'token' }
)
end
it 'returns status 200' do
- post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: { token: 'token', text: 'help' }
+ post api("/projects/#{project.id}/services/#{integration_name}/trigger"), params: { token: 'token', text: 'help' }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['response_type']).to eq("ephemeral")
@@ -254,29 +252,29 @@ RSpec.describe API::Services do
end
end
- describe 'Mattermost service' do
- let(:service_name) { 'mattermost' }
+ describe 'Mattermost integration' do
+ let(:integration_name) { 'mattermost' }
let(:params) do
{ webhook: 'https://hook.example.com', username: 'username' }
end
before do
- project.create_mattermost_service(
+ project.create_mattermost_integration(
active: true,
properties: params
)
end
it 'accepts a username for update' do
- put api("/projects/#{project.id}/services/#{service_name}", user), params: params.merge(username: 'new_username')
+ put api("/projects/#{project.id}/services/#{integration_name}", user), params: params.merge(username: 'new_username')
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['properties']['username']).to eq('new_username')
end
end
- describe 'Microsoft Teams service' do
- let(:service_name) { 'microsoft-teams' }
+ describe 'Microsoft Teams integration' do
+ let(:integration_name) { 'microsoft-teams' }
let(:params) do
{
webhook: 'https://hook.example.com',
@@ -286,29 +284,31 @@ RSpec.describe API::Services do
end
before do
- project.create_microsoft_teams_service(
+ project.create_microsoft_teams_integration(
active: true,
properties: params
)
end
it 'accepts branches_to_be_notified for update' do
- put api("/projects/#{project.id}/services/#{service_name}", user), params: params.merge(branches_to_be_notified: 'all')
+ put api("/projects/#{project.id}/services/#{integration_name}", user),
+ params: params.merge(branches_to_be_notified: 'all')
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['properties']['branches_to_be_notified']).to eq('all')
end
it 'accepts notify_only_broken_pipelines for update' do
- put api("/projects/#{project.id}/services/#{service_name}", user), params: params.merge(notify_only_broken_pipelines: true)
+ put api("/projects/#{project.id}/services/#{integration_name}", user),
+ params: params.merge(notify_only_broken_pipelines: true)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['properties']['notify_only_broken_pipelines']).to eq(true)
end
end
- describe 'Hangouts Chat service' do
- let(:service_name) { 'hangouts-chat' }
+ describe 'Hangouts Chat integration' do
+ let(:integration_name) { 'hangouts-chat' }
let(:params) do
{
webhook: 'https://hook.example.com',
@@ -324,16 +324,38 @@ RSpec.describe API::Services do
end
it 'accepts branches_to_be_notified for update', :aggregate_failures do
- put api("/projects/#{project.id}/services/#{service_name}", user), params: params.merge(branches_to_be_notified: 'all')
+ put api("/projects/#{project.id}/services/#{integration_name}", user), params: params.merge(branches_to_be_notified: 'all')
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['properties']['branches_to_be_notified']).to eq('all')
end
it 'only requires the webhook param' do
- put api("/projects/#{project.id}/services/#{service_name}", user), params: { webhook: 'https://hook.example.com' }
+ put api("/projects/#{project.id}/services/#{integration_name}", user), params: { webhook: 'https://hook.example.com' }
expect(response).to have_gitlab_http_status(:ok)
end
end
+
+ describe 'Pipelines Email Integration' do
+ let(:integration_name) { 'pipelines-email' }
+
+ context 'notify_only_broken_pipelines property was saved as a string' do
+ before do
+ project.create_pipelines_email_integration(
+ active: false,
+ properties: {
+ "notify_only_broken_pipelines": "true",
+ "branches_to_be_notified": "default"
+ }
+ )
+ end
+
+ it 'returns boolean values for notify_only_broken_pipelines' do
+ get api("/projects/#{project.id}/services/#{integration_name}", user)
+
+ expect(json_response['properties']['notify_only_broken_pipelines']).to eq(true)
+ end
+ end
+ end
end