Commit c8e24280 authored by Jarka Košanová's avatar Jarka Košanová

Simplify factories for services

- use predefined factories when creating
projects with services
- remove unnecessary arguments
parent 00b944af
...@@ -306,34 +306,18 @@ FactoryBot.define do ...@@ -306,34 +306,18 @@ FactoryBot.define do
factory :redmine_project, parent: :project do factory :redmine_project, parent: :project do
has_external_issue_tracker true has_external_issue_tracker true
after :create do |project| redmine_service
project.create_redmine_service(
active: true,
properties: {
'project_url' => 'http://redmine/projects/project_name_in_redmine',
'issues_url' => 'http://redmine/projects/project_name_in_redmine/issues/:id',
'new_issue_url' => 'http://redmine/projects/project_name_in_redmine/issues/new'
}
)
end
end end
factory :youtrack_project, parent: :project do factory :youtrack_project, parent: :project do
has_external_issue_tracker true has_external_issue_tracker true
after :create do |project| youtrack_service
project.create_youtrack_service(
active: true,
properties: {
'project_url' => 'http://youtrack/projects/project_guid_in_youtrack',
'issues_url' => 'http://youtrack/issues/:id'
}
)
end
end end
factory :jira_project, parent: :project do factory :jira_project, parent: :project do
has_external_issue_tracker true has_external_issue_tracker true
jira_service jira_service
end end
......
...@@ -79,14 +79,12 @@ FactoryBot.define do ...@@ -79,14 +79,12 @@ FactoryBot.define do
trait :issue_tracker do trait :issue_tracker do
properties( properties(
project_url: 'http://issue-tracker.example.com', project_url: 'http://issue-tracker.example.com',
issues_url: 'http://issue-tracker.example.com', issues_url: 'http://issue-tracker.example.com/issues/:id',
new_issue_url: 'http://issue-tracker.example.com' new_issue_url: 'http://issue-tracker.example.com'
) )
end end
factory :jira_cloud_service, class: JiraService do trait :jira_cloud_service do
project
active true
properties( properties(
url: 'https://mysite.atlassian.net', url: 'https://mysite.atlassian.net',
username: 'jira_user', username: 'jira_user',
......
# frozen_string_literal: true # frozen_string_literal: true
# these factories should never be called directly, they are used when creating services
FactoryBot.define do FactoryBot.define do
factory :jira_tracker_data do factory :jira_tracker_data do
service service
url 'http://jira.example.com'
api_url 'http://api-jira.example.com'
username 'jira_username'
password 'jira_password'
end end
factory :issue_tracker_data do factory :issue_tracker_data do
service service
project_url 'http://issuetracker.example.com'
issues_url 'http://issues.example.com'
new_issue_url 'http://new-issue.example.com'
end end
end end
...@@ -32,7 +32,7 @@ describe Banzai::Pipeline::GfmPipeline do ...@@ -32,7 +32,7 @@ describe Banzai::Pipeline::GfmPipeline do
result = described_class.call(markdown, project: project)[:output] result = described_class.call(markdown, project: project)[:output]
link = result.css('a').first link = result.css('a').first
expect(link['href']).to eq 'http://redmine/projects/project_name_in_redmine/issues/12' expect(link['href']).to eq 'http://issue-tracker.example.com/issues/12'
end end
it 'parses cross-project references to regular issues' do it 'parses cross-project references to regular issues' do
...@@ -61,7 +61,7 @@ describe Banzai::Pipeline::GfmPipeline do ...@@ -61,7 +61,7 @@ describe Banzai::Pipeline::GfmPipeline do
result = described_class.call(markdown, project: project)[:output] result = described_class.call(markdown, project: project)[:output]
link = result.css('a').first link = result.css('a').first
expect(link['href']).to eq 'http://redmine/projects/project_name_in_redmine/issues/12' expect(link['href']).to eq 'http://issue-tracker.example.com/issues/12'
end end
it 'allows to use long external reference syntax for Redmine' do it 'allows to use long external reference syntax for Redmine' do
...@@ -70,7 +70,7 @@ describe Banzai::Pipeline::GfmPipeline do ...@@ -70,7 +70,7 @@ describe Banzai::Pipeline::GfmPipeline do
result = described_class.call(markdown, project: project)[:output] result = described_class.call(markdown, project: project)[:output]
link = result.css('a').first link = result.css('a').first
expect(link['href']).to eq 'http://redmine/projects/project_name_in_redmine/issues/12' expect(link['href']).to eq 'http://issue-tracker.example.com/issues/12'
end end
it 'parses cross-project references to regular issues' do it 'parses cross-project references to regular issues' do
......
...@@ -8,7 +8,7 @@ describe Gitlab::UsageData do ...@@ -8,7 +8,7 @@ describe Gitlab::UsageData do
before do before do
create(:jira_service, project: projects[0]) create(:jira_service, project: projects[0])
create(:jira_service, project: projects[1]) create(:jira_service, project: projects[1])
create(:jira_cloud_service, project: projects[2]) create(:jira_service, :jira_cloud_service, project: projects[2])
create(:prometheus_service, project: projects[1]) create(:prometheus_service, project: projects[1])
create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true) create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true)
create(:service, project: projects[1], type: 'SlackService', active: true) create(:service, project: projects[1], type: 'SlackService', active: true)
......
...@@ -85,9 +85,7 @@ describe API::Services do ...@@ -85,9 +85,7 @@ describe API::Services do
include_context service include_context service
# inject some properties into the service # inject some properties into the service
before do let!(:initialized_service) { initialize_service(service) }
initialize_service(service)
end
it 'returns authentication error when unauthenticated' do it 'returns authentication error when unauthenticated' do
get api("/projects/#{project.id}/services/#{dashed_service}") get api("/projects/#{project.id}/services/#{dashed_service}")
...@@ -108,6 +106,15 @@ describe API::Services do ...@@ -108,6 +106,15 @@ describe API::Services do
expect(json_response['properties'].keys).to match_array(service_instance.api_field_names) expect(json_response['properties'].keys).to match_array(service_instance.api_field_names)
end end
it "returns empty hash if properties are empty" do
# deprecated services are not valid for update
initialized_service.update_attribute(:properties, {})
get api("/projects/#{project.id}/services/#{dashed_service}", user)
expect(response).to have_gitlab_http_status(200)
expect(json_response['properties'].keys).to be_empty
end
it "returns error when authenticated but not a project owner" do it "returns error when authenticated but not a project owner" do
project.add_developer(user2) project.add_developer(user2)
get api("/projects/#{project.id}/services/#{dashed_service}", user2) get api("/projects/#{project.id}/services/#{dashed_service}", user2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment