diff options
Diffstat (limited to 'spec/services/work_items/parent_links')
-rw-r--r-- | spec/services/work_items/parent_links/create_service_spec.rb | 28 | ||||
-rw-r--r-- | spec/services/work_items/parent_links/destroy_service_spec.rb | 11 |
2 files changed, 33 insertions, 6 deletions
diff --git a/spec/services/work_items/parent_links/create_service_spec.rb b/spec/services/work_items/parent_links/create_service_spec.rb index 85b0ee040cd..0ba41373544 100644 --- a/spec/services/work_items/parent_links/create_service_spec.rb +++ b/spec/services/work_items/parent_links/create_service_spec.rb @@ -12,10 +12,10 @@ RSpec.describe WorkItems::ParentLinks::CreateService do let_it_be(:task1) { create(:work_item, :task, project: project) } let_it_be(:task2) { create(:work_item, :task, project: project) } let_it_be(:guest_task) { create(:work_item, :task) } - let_it_be(:invalid_task) { build_stubbed(:work_item, :task, id: non_existing_record_id)} + let_it_be(:invalid_task) { build_stubbed(:work_item, :task, id: non_existing_record_id) } let_it_be(:another_project) { (create :project) } let_it_be(:other_project_task) { create(:work_item, :task, iid: 100, project: another_project) } - let_it_be(:existing_parent_link) { create(:parent_link, work_item: task, work_item_parent: work_item)} + let_it_be(:existing_parent_link) { create(:parent_link, work_item: task, work_item_parent: work_item) } let(:parent_link_class) { WorkItems::ParentLink } let(:issuable_type) { :task } @@ -84,13 +84,26 @@ RSpec.describe WorkItems::ParentLinks::CreateService do expect(subject[:created_references].map(&:work_item_id)).to match_array([task1.id, task2.id]) end + it 'creates notes', :aggregate_failures do + subject + + work_item_notes = work_item.notes.last(2) + expect(work_item_notes.first.note).to eq("added #{task1.to_reference} as child task") + expect(work_item_notes.last.note).to eq("added #{task2.to_reference} as child task") + expect(task1.notes.last.note).to eq("added #{work_item.to_reference} as parent issue") + expect(task2.notes.last.note).to eq("added #{work_item.to_reference} as parent issue") + end + context 'when task is already assigned' do let(:params) { { issuable_references: [task, task2] } } - it 'creates links only for non related tasks' do + it 'creates links only for non related tasks', :aggregate_failures do expect { subject }.to change(parent_link_class, :count).by(1) expect(subject[:created_references].map(&:work_item_id)).to match_array([task2.id]) + expect(work_item.notes.last.note).to eq("added #{task2.to_reference} as child task") + expect(task2.notes.last.note).to eq("added #{work_item.to_reference} as parent issue") + expect(task.notes).to be_empty end end @@ -109,6 +122,15 @@ RSpec.describe WorkItems::ParentLinks::CreateService do is_expected.to eq(service_error(error, http_status: 422)) end + + it 'creates notes for valid links' do + subject + + expect(work_item.notes.last.note).to eq("added #{task1.to_reference} as child task") + expect(task1.notes.last.note).to eq("added #{work_item.to_reference} as parent issue") + expect(issue.notes).to be_empty + expect(other_project_task.notes).to be_empty + end end context 'when parent type is invalid' do diff --git a/spec/services/work_items/parent_links/destroy_service_spec.rb b/spec/services/work_items/parent_links/destroy_service_spec.rb index 574b70af397..654a03ef6f7 100644 --- a/spec/services/work_items/parent_links/destroy_service_spec.rb +++ b/spec/services/work_items/parent_links/destroy_service_spec.rb @@ -9,7 +9,7 @@ RSpec.describe WorkItems::ParentLinks::DestroyService do let_it_be(:project) { create(:project) } let_it_be(:work_item) { create(:work_item, project: project) } let_it_be(:task) { create(:work_item, :task, project: project) } - let_it_be(:parent_link) { create(:parent_link, work_item: task, work_item_parent: work_item)} + let_it_be(:parent_link) { create(:parent_link, work_item: task, work_item_parent: work_item) } let(:parent_link_class) { WorkItems::ParentLink } @@ -23,8 +23,11 @@ RSpec.describe WorkItems::ParentLinks::DestroyService do context 'when user has permissions to update work items' do let(:user) { reporter } - it 'removes relation' do + it 'removes relation and creates notes', :aggregate_failures do expect { subject }.to change(parent_link_class, :count).by(-1) + + expect(work_item.notes.last.note).to eq("removed child task #{task.to_reference}") + expect(task.notes.last.note).to eq("removed parent issue #{work_item.to_reference}") end it 'returns success message' do @@ -35,8 +38,10 @@ RSpec.describe WorkItems::ParentLinks::DestroyService do context 'when user has insufficient permissions' do let(:user) { guest } - it 'does not remove relation' do + it 'does not remove relation', :aggregate_failures do expect { subject }.not_to change(parent_link_class, :count).from(1) + + expect(SystemNoteService).not_to receive(:unrelate_work_item) end it 'returns error message' do |