diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/lib/gitlab/github_import/importer/events/changed_reviewer_spec.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/lib/gitlab/github_import/importer/events/changed_reviewer_spec.rb')
-rw-r--r-- | spec/lib/gitlab/github_import/importer/events/changed_reviewer_spec.rb | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/spec/lib/gitlab/github_import/importer/events/changed_reviewer_spec.rb b/spec/lib/gitlab/github_import/importer/events/changed_reviewer_spec.rb new file mode 100644 index 00000000000..ff813dd41d9 --- /dev/null +++ b/spec/lib/gitlab/github_import/importer/events/changed_reviewer_spec.rb @@ -0,0 +1,101 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::Importer::Events::ChangedReviewer do + subject(:importer) { described_class.new(project, client) } + + let_it_be(:project) { create(:project, :repository) } + let_it_be(:requested_reviewer) { create(:user) } + let_it_be(:review_requester) { create(:user) } + + let(:client) { instance_double('Gitlab::GithubImport::Client') } + let(:issuable) { create(:merge_request, source_project: project, target_project: project) } + + let(:issue_event) do + Gitlab::GithubImport::Representation::IssueEvent.from_json_hash( + 'id' => 6501124486, + 'actor' => { 'id' => 4, 'login' => 'alice' }, + 'event' => event_type, + 'commit_id' => nil, + 'created_at' => '2022-04-26 18:30:53 UTC', + 'review_requester' => { 'id' => review_requester.id, 'login' => review_requester.username }, + 'requested_reviewer' => { 'id' => requested_reviewer.id, 'login' => requested_reviewer.username }, + 'issue' => { 'number' => issuable.iid, pull_request: issuable.is_a?(MergeRequest) } + ) + end + + let(:note_attrs) do + { + noteable_id: issuable.id, + noteable_type: issuable.class.name, + project_id: project.id, + author_id: review_requester.id, + system: true, + created_at: issue_event.created_at, + updated_at: issue_event.created_at + }.stringify_keys + end + + let(:expected_system_note_metadata_attrs) do + { + action: 'reviewer', + created_at: issue_event.created_at, + updated_at: issue_event.created_at + }.stringify_keys + end + + shared_examples 'create expected notes' do + it 'creates expected note' do + expect { importer.execute(issue_event) }.to change { issuable.notes.count } + .from(0).to(1) + + expect(issuable.notes.last) + .to have_attributes(expected_note_attrs) + end + + it 'creates expected system note metadata' do + expect { importer.execute(issue_event) }.to change(SystemNoteMetadata, :count) + .from(0).to(1) + + expect(SystemNoteMetadata.last) + .to have_attributes( + expected_system_note_metadata_attrs.merge( + note_id: Note.last.id + ) + ) + end + end + + shared_examples 'process review_requested & review_request_removed MR events' do + context 'when importing a review_requested event' do + let(:event_type) { 'review_requested' } + let(:expected_note_attrs) { note_attrs.merge(note: "requested review from @#{requested_reviewer.username}") } + + it_behaves_like 'create expected notes' + end + + context 'when importing a review_request_removed event' do + let(:event_type) { 'review_request_removed' } + let(:expected_note_attrs) { note_attrs.merge(note: "removed review request for @#{requested_reviewer.username}") } + + it_behaves_like 'create expected notes' + end + end + + describe '#execute' do + before do + allow_next_instance_of(Gitlab::GithubImport::IssuableFinder) do |finder| + allow(finder).to receive(:database_id).and_return(issuable.id) + end + allow_next_instance_of(Gitlab::GithubImport::UserFinder) do |finder| + allow(finder).to receive(:find).with(requested_reviewer.id, requested_reviewer.username) + .and_return(requested_reviewer.id) + allow(finder).to receive(:find).with(review_requester.id, review_requester.username) + .and_return(review_requester.id) + end + end + + it_behaves_like 'process review_requested & review_request_removed MR events' + end +end |