Commit 8281ec84 authored by Eugenia Grieff's avatar Eugenia Grieff

De-duplicate issues create service EE specs

rm ee/spec/services/issues/create_service_spec.rb
parent fcf2ee20
...@@ -217,14 +217,12 @@ Gitlab/DuplicateSpecLocation: ...@@ -217,14 +217,12 @@ Gitlab/DuplicateSpecLocation:
- ee/spec/helpers/auth_helper_spec.rb - ee/spec/helpers/auth_helper_spec.rb
- ee/spec/lib/gitlab/gl_repository_spec.rb - ee/spec/lib/gitlab/gl_repository_spec.rb
- ee/spec/models/namespace_spec.rb - ee/spec/models/namespace_spec.rb
- ee/spec/services/issues/create_service_spec.rb
- ee/spec/services/merge_requests/create_service_spec.rb - ee/spec/services/merge_requests/create_service_spec.rb
- ee/spec/services/merge_requests/refresh_service_spec.rb - ee/spec/services/merge_requests/refresh_service_spec.rb
- ee/spec/services/merge_requests/update_service_spec.rb - ee/spec/services/merge_requests/update_service_spec.rb
- ee/spec/services/system_hooks_service_spec.rb - ee/spec/services/system_hooks_service_spec.rb
- ee/spec/helpers/ee/auth_helper_spec.rb - ee/spec/helpers/ee/auth_helper_spec.rb
- ee/spec/models/ee/namespace_spec.rb - ee/spec/models/ee/namespace_spec.rb
- ee/spec/services/ee/issues/create_service_spec.rb
- ee/spec/services/ee/merge_requests/create_service_spec.rb - ee/spec/services/ee/merge_requests/create_service_spec.rb
- ee/spec/services/ee/merge_requests/refresh_service_spec.rb - ee/spec/services/ee/merge_requests/refresh_service_spec.rb
- ee/spec/services/ee/merge_requests/update_service_spec.rb - ee/spec/services/ee/merge_requests/update_service_spec.rb
......
...@@ -3,59 +3,105 @@ ...@@ -3,59 +3,105 @@
require 'spec_helper' require 'spec_helper'
describe Issues::CreateService do describe Issues::CreateService do
let(:group) { create(:group) } let_it_be(:group) { create(:group) }
let(:project) { create(:project, group: group) } let(:project) { create(:project, group: group) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:epic) { create(:epic, group: group) } let(:params) { { title: 'Awesome issue', description: 'please fix', weight: 9 } }
let(:service) { described_class.new(project, user, params) } let(:service) { described_class.new(project, user, params) }
before do describe '#execute' do
stub_licensed_features(epics: true) context 'when current user cannot admin issues in the project' do
end before do
project.add_guest(user)
end
context 'quick actions' do it 'filters out params that cannot be set without the :admin_issue permission' do
before do issue = service.execute
project.add_maintainer(user)
expect(issue).to be_persisted
expect(issue.weight).to be_nil
end
end end
context '/epic action' do context 'when current user can admin issues in the project' do
let(:params) do before do
{ stub_licensed_features(epics: true)
title: 'New issue', project.add_reporter(user)
description: "/epic #{epic.to_reference(project)}"
}
end end
it 'adds an issue to the passed epic' do it 'sets permitted params correctly' do
issue = service.execute issue = service.execute
expect(issue).to be_persisted expect(issue).to be_persisted
expect(issue.epic).to eq(epic) expect(issue.weight).to eq(9)
end
context 'when epics are enabled' do
let_it_be(:epic) { create(:epic, group: group, start_date_is_fixed: false, due_date_is_fixed: false) }
before do
stub_licensed_features(epics: true)
project.add_reporter(user)
end
it_behaves_like 'issue with epic_id parameter' do
let(:execute) { service.execute }
end
context 'when using quick actions' do
before do
group.add_reporter(user)
end
context '/epic action' do
let(:params) { { title: 'New issue', description: "/epic #{epic.to_reference(project)}" } }
it 'adds an issue to the passed epic' do
issue = service.execute
expect(issue).to be_persisted
expect(issue.epic).to eq(epic)
end
end
context 'with epic and milestone in commands only' do
let(:milestone) { create(:milestone, group: group, start_date: Date.today, due_date: 7.days.from_now) }
let(:params) do
{
title: 'Awesome issue',
description: %(/epic #{epic.to_reference}\n/milestone #{milestone.to_reference}")
}
end
it 'sets epic and milestone to issuable and update epic start and due date' do
issue = service.execute
expect(issue.milestone).to eq(milestone)
expect(issue.epic).to eq(epic)
expect(epic.reload.start_date).to eq(milestone.start_date)
expect(epic.due_date).to eq(milestone.due_date)
end
end
end
end end
end end
end
describe '#execute' do
it_behaves_like 'new issuable with scoped labels' do it_behaves_like 'new issuable with scoped labels' do
let(:parent) { project } let(:parent) { project }
end end
it_behaves_like 'issue with epic_id parameter' do
let(:execute) { service.execute }
end
describe 'publish to status page' do describe 'publish to status page' do
let(:execute) { service.execute } let(:execute) { service.execute }
let(:issue_id) { execute&.id } let(:issue_id) { execute&.id }
context 'when creation succeeds' do context 'when creation succeeds' do
let(:params) { { title: 'New title' } } let_it_be(:params) { { title: 'New title' } }
include_examples 'trigger status page publish' include_examples 'trigger status page publish'
end end
context 'when creation fails' do context 'when creation fails' do
let(:params) { { title: nil } } let_it_be(:params) { { title: nil } }
include_examples 'no trigger status page publish' include_examples 'no trigger status page publish'
end end
......
# frozen_string_literal: true
require 'spec_helper'
describe Issues::CreateService do
let(:project) { create(:project) }
let(:opts) do
{
title: 'Awesome issue',
description: 'please fix',
weight: 9
}
end
context 'when current user cannot admin issues in the project' do
let(:guest) { create(:user) }
before do
project.add_guest(guest)
end
it 'filters out params that cannot be set without the :admin_issue permission' do
issue = described_class.new(project, guest, opts).execute
expect(issue).to be_persisted
expect(issue.weight).to be_nil
end
end
context 'when current user can admin issues in the project' do
let(:reporter) { create(:user) }
before do
stub_licensed_features(epics: true)
project.add_reporter(reporter)
end
it 'sets permitted params correctly' do
issue = described_class.new(project, reporter, opts).execute
expect(issue).to be_persisted
expect(issue.weight).to eq(9)
end
context 'when epics are enabled' do
let(:group) { create(:group) }
let(:project1) { create(:project, group: group) }
let(:epic) { create(:epic, group: group, start_date_is_fixed: false, due_date_is_fixed: false) }
before do
stub_licensed_features(epics: true)
group.add_reporter(reporter)
project1.add_reporter(reporter)
end
context 'when using quick actions' do
context 'with epic and milestone in commands only' do
let(:milestone) { create(:milestone, group: group, start_date: Date.today, due_date: 7.days.from_now) }
let(:opts) do
{
title: 'Awesome issue',
description: %(/epic #{epic.to_reference}\n/milestone #{milestone.to_reference}")
}
end
it 'sets epic and milestone to issuable and update epic start and due date' do
issue = described_class.new(project1, reporter, opts).execute
expect(issue.milestone).to eq(milestone)
expect(issue.epic).to eq(epic)
expect(epic.reload.start_date).to eq(milestone.start_date)
expect(epic.due_date).to eq(milestone.due_date)
end
end
end
end
end
end
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