Commit ee9b7754 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '211887-dedup-issues-create-service-specs' into 'master'

De-duplicate issues create service EE specs

Closes #211887

See merge request gitlab-org/gitlab!28213
parents 8d02faa1 8281ec84
......@@ -217,13 +217,11 @@ Gitlab/DuplicateSpecLocation:
- ee/spec/helpers/auth_helper_spec.rb
- ee/spec/lib/gitlab/gl_repository_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/refresh_service_spec.rb
- ee/spec/services/merge_requests/update_service_spec.rb
- ee/spec/helpers/ee/auth_helper_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/refresh_service_spec.rb
- ee/spec/services/ee/merge_requests/update_service_spec.rb
......
......@@ -3,59 +3,105 @@
require 'spec_helper'
describe Issues::CreateService do
let(:group) { create(:group) }
let_it_be(:group) { create(:group) }
let(:project) { create(:project, group: group) }
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) }
describe '#execute' do
context 'when current user cannot admin issues in the project' do
before do
project.add_guest(user)
end
it 'filters out params that cannot be set without the :admin_issue permission' do
issue = service.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
before do
stub_licensed_features(epics: true)
project.add_reporter(user)
end
it 'sets permitted params correctly' do
issue = service.execute
expect(issue).to be_persisted
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 'quick actions' do
context 'when using quick actions' do
before do
project.add_maintainer(user)
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: 'New issue',
description: "/epic #{epic.to_reference(project)}"
title: 'Awesome issue',
description: %(/epic #{epic.to_reference}\n/milestone #{milestone.to_reference}")
}
end
it 'adds an issue to the passed epic' do
it 'sets epic and milestone to issuable and update epic start and due date' do
issue = service.execute
expect(issue).to be_persisted
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
describe '#execute' do
it_behaves_like 'new issuable with scoped labels' do
let(:parent) { project }
end
it_behaves_like 'issue with epic_id parameter' do
let(:execute) { service.execute }
end
describe 'publish to status page' do
let(:execute) { service.execute }
let(:issue_id) { execute&.id }
context 'when creation succeeds' do
let(:params) { { title: 'New title' } }
let_it_be(:params) { { title: 'New title' } }
include_examples 'trigger status page publish'
end
context 'when creation fails' do
let(:params) { { title: nil } }
let_it_be(:params) { { title: nil } }
include_examples 'no trigger status page publish'
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