diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /spec/services/issues | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'spec/services/issues')
-rw-r--r-- | spec/services/issues/clone_service_spec.rb | 26 | ||||
-rw-r--r-- | spec/services/issues/create_service_spec.rb | 12 | ||||
-rw-r--r-- | spec/services/issues/move_service_spec.rb | 12 | ||||
-rw-r--r-- | spec/services/issues/prepare_import_csv_service_spec.rb | 51 | ||||
-rw-r--r-- | spec/services/issues/referenced_merge_requests_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/issues/update_service_spec.rb | 58 |
6 files changed, 144 insertions, 17 deletions
diff --git a/spec/services/issues/clone_service_spec.rb b/spec/services/issues/clone_service_spec.rb index 858dfc4ab3a..435488b7f66 100644 --- a/spec/services/issues/clone_service_spec.rb +++ b/spec/services/issues/clone_service_spec.rb @@ -57,8 +57,20 @@ RSpec.describe Issues::CloneService do expect(old_issue.notes.last.note).to start_with 'cloned to' end - it 'adds system note to new issue at the end' do - expect(new_issue.notes.last.note).to start_with 'cloned from' + it 'adds system note to new issue at the start' do + # We set an assignee so an assignee system note will be generated and + # we can assert that the "cloned from" note is the first one + assignee = create(:user) + new_project.add_developer(assignee) + old_issue.assignees = [assignee] + + new_issue = clone_service.execute(old_issue, new_project) + + expect(new_issue.notes.size).to eq(2) + + cloned_from_note = new_issue.notes.last + expect(cloned_from_note.note).to start_with 'cloned from' + expect(new_issue.notes.fresh.first).to eq(cloned_from_note) end it 'keeps old issue open' do @@ -128,11 +140,11 @@ RSpec.describe Issues::CloneService do context 'issue with award emoji' do let!(:award_emoji) { create(:award_emoji, awardable: old_issue) } - it 'copies the award emoji' do + it 'does not copy the award emoji' do old_issue.reload new_issue = clone_service.execute(old_issue, new_project) - expect(old_issue.award_emoji.first.name).to eq new_issue.reload.award_emoji.first.name + expect(new_issue.reload.award_emoji).to be_empty end end @@ -170,19 +182,21 @@ RSpec.describe Issues::CloneService do context 'issue with due date' do let(:date) { Date.parse('2020-01-10') } + let(:new_date) { date + 1.week } let(:old_issue) do create(:issue, title: title, description: description, project: old_project, author: author, due_date: date) end before do - SystemNoteService.change_due_date(old_issue, old_project, author, old_issue.due_date) + old_issue.update!(due_date: new_date) + SystemNoteService.change_start_date_or_due_date(old_issue, old_project, author, old_issue.previous_changes.slice('due_date')) end it 'keeps the same due date' do new_issue = clone_service.execute(old_issue, new_project) - expect(new_issue.due_date).to eq(date) + expect(new_issue.due_date).to eq(old_issue.due_date) end end diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb index 0bc8511e3e3..80c455e72b0 100644 --- a/spec/services/issues/create_service_spec.rb +++ b/spec/services/issues/create_service_spec.rb @@ -69,6 +69,12 @@ RSpec.describe Issues::CreateService do expect(issue.issue_customer_relations_contacts).to be_empty end + it 'calls NewIssueWorker with correct arguments' do + expect(NewIssueWorker).to receive(:perform_async).with(Integer, user.id, 'Issue') + + issue + end + context 'when a build_service is provided' do let(:issue) { described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params, build_service: build_service).execute } @@ -143,6 +149,12 @@ RSpec.describe Issues::CreateService do issue end + it 'calls NewIssueWorker with correct arguments' do + expect(NewIssueWorker).to receive(:perform_async).with(Integer, reporter.id, 'Issue') + + issue + end + context 'when invalid' do before do opts.merge!(title: '') diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb index 5a1bb2e8b74..863df810d01 100644 --- a/spec/services/issues/move_service_spec.rb +++ b/spec/services/issues/move_service_spec.rb @@ -16,7 +16,7 @@ RSpec.describe Issues::MoveService do let_it_be(:new_project) { create(:project, namespace: sub_group_2) } let(:old_issue) do - create(:issue, title: title, description: description, project: old_project, author: author) + create(:issue, title: title, description: description, project: old_project, author: author, created_at: 1.day.ago, updated_at: 1.day.ago) end subject(:move_service) do @@ -62,8 +62,11 @@ RSpec.describe Issues::MoveService do expect(old_issue.notes.last.note).to start_with 'moved to' end - it 'adds system note to new issue at the end' do - expect(new_issue.notes.last.note).to start_with 'moved from' + it 'adds system note to new issue at the end', :freeze_time do + system_note = new_issue.notes.last + + expect(system_note.note).to start_with 'moved from' + expect(system_note.created_at).to be_like_time(Time.current) end it 'closes old issue' do @@ -137,7 +140,8 @@ RSpec.describe Issues::MoveService do end before do - SystemNoteService.change_due_date(old_issue, old_project, author, old_issue.due_date) + old_issue.update!(due_date: Date.today) + SystemNoteService.change_start_date_or_due_date(old_issue, old_project, author, old_issue.previous_changes.slice('due_date')) end it 'does not create extra system notes' do diff --git a/spec/services/issues/prepare_import_csv_service_spec.rb b/spec/services/issues/prepare_import_csv_service_spec.rb new file mode 100644 index 00000000000..ded23ee43b9 --- /dev/null +++ b/spec/services/issues/prepare_import_csv_service_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Issues::PrepareImportCsvService do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + + let(:file) { double } + let(:upload_service) { double } + let(:uploader) { double } + let(:upload) { double } + + let(:subject) do + described_class.new(project, user, file: file).execute + end + + context 'when file is uploaded correctly' do + let(:upload_id) { 99 } + + before do + mock_upload + end + + it 'returns a success message' do + result = subject + + expect(result[:status]).to eq(:success) + expect(result[:message]).to eq("Your issues are being imported. Once finished, you'll get a confirmation email.") + end + + it 'enqueues the ImportRequirementsCsvWorker' do + expect(ImportIssuesCsvWorker).to receive(:perform_async).with(user.id, project.id, upload_id) + + subject + end + end + + context 'when file upload fails' do + before do + mock_upload(false) + end + + it 'returns an error message' do + result = subject + + expect(result[:status]).to eq(:error) + expect(result[:message]).to eq('File upload error.') + end + end +end diff --git a/spec/services/issues/referenced_merge_requests_service_spec.rb b/spec/services/issues/referenced_merge_requests_service_spec.rb index dc55ba8ebea..16166c1fa33 100644 --- a/spec/services/issues/referenced_merge_requests_service_spec.rb +++ b/spec/services/issues/referenced_merge_requests_service_spec.rb @@ -106,7 +106,7 @@ RSpec.describe Issues::ReferencedMergeRequestsService do end describe '#closed_by_merge_requests' do - let(:closed_issue) { build(:issue, :closed, project: project)} + let(:closed_issue) { build(:issue, :closed, project: project) } it 'returns the open merge requests that close this issue' do create_closing_mr(source_project: project, state: 'closed') diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index e2e8828ae89..aef3608831c 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -849,8 +849,8 @@ RSpec.describe Issues::UpdateService, :mailer do end it 'creates system note about task status change' do - note1 = find_note('marked the task **Task 1** as completed') - note2 = find_note('marked the task **Task 2** as completed') + note1 = find_note('marked the checklist item **Task 1** as completed') + note2 = find_note('marked the checklist item **Task 2** as completed') expect(note1).not_to be_nil expect(note2).not_to be_nil @@ -867,8 +867,8 @@ RSpec.describe Issues::UpdateService, :mailer do end it 'creates system note about task status change' do - note1 = find_note('marked the task **Task 1** as incomplete') - note2 = find_note('marked the task **Task 2** as incomplete') + note1 = find_note('marked the checklist item **Task 1** as incomplete') + note2 = find_note('marked the checklist item **Task 2** as incomplete') expect(note1).not_to be_nil expect(note2).not_to be_nil @@ -885,7 +885,7 @@ RSpec.describe Issues::UpdateService, :mailer do end it 'does not create a system note for the task' do - task_note = find_note('marked the task **Task 2** as incomplete') + task_note = find_note('marked the checklist item **Task 2** as incomplete') description_notes = find_notes('description') expect(task_note).to be_nil @@ -900,7 +900,7 @@ RSpec.describe Issues::UpdateService, :mailer do end it 'does not create a system note referencing the position the old item' do - task_note = find_note('marked the task **Two** as incomplete') + task_note = find_note('marked the checklist item **Two** as incomplete') description_notes = find_notes('description') expect(task_note).to be_nil @@ -988,6 +988,52 @@ RSpec.describe Issues::UpdateService, :mailer do end end + context 'updating dates' do + subject(:result) { described_class.new(project: project, current_user: user, params: params).execute(issue) } + + let(:updated_date) { 1.week.from_now.to_date } + + shared_examples 'issue update service that triggers date updates' do + it 'triggers graphql date updated subscription' do + expect(GraphqlTriggers).to receive(:issuable_dates_updated).with(issue).and_call_original + + result + end + end + + shared_examples 'issue update service that does not trigger date updates' do + it 'does not trigger date updated subscriptions' do + expect(GraphqlTriggers).not_to receive(:issuable_dates_updated) + + result + end + end + + context 'when due_date is updated' do + let(:params) { { due_date: updated_date } } + + it_behaves_like 'issue update service that triggers date updates' + end + + context 'when start_date is updated' do + let(:params) { { start_date: updated_date } } + + it_behaves_like 'issue update service that triggers date updates' + end + + context 'when no date is updated' do + let(:params) { { title: 'should not trigger date updates' } } + + it_behaves_like 'issue update service that does not trigger date updates' + end + + context 'when update is not successful but date is provided' do + let(:params) { { title: '', due_date: updated_date } } + + it_behaves_like 'issue update service that does not trigger date updates' + end + end + context 'updating asssignee_id' do it 'does not update assignee when assignee_id is invalid' do update_issue(assignee_ids: [-1]) |