diff options
Diffstat (limited to 'spec/lib/gitlab/github_import/importer/events/changed_label_spec.rb')
-rw-r--r-- | spec/lib/gitlab/github_import/importer/events/changed_label_spec.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/lib/gitlab/github_import/importer/events/changed_label_spec.rb b/spec/lib/gitlab/github_import/importer/events/changed_label_spec.rb new file mode 100644 index 00000000000..b773598853d --- /dev/null +++ b/spec/lib/gitlab/github_import/importer/events/changed_label_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::Importer::Events::ChangedLabel do + subject(:importer) { described_class.new(project, user.id) } + + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + + let(:issue) { create(:issue, project: project) } + let!(:label) { create(:label, 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, + 'label_title' => label.title, + 'issue_db_id' => issue.id, + 'created_at' => '2022-04-26 18:30:53 UTC' + ) + end + + let(:event_attrs) do + { + user_id: user.id, + issue_id: issue.id, + label_id: label.id, + created_at: issue_event.created_at + }.stringify_keys + end + + shared_examples 'new event' do + it 'creates a new label event' do + expect { importer.execute(issue_event) }.to change { issue.resource_label_events.count } + .from(0).to(1) + expect(issue.resource_label_events.last) + .to have_attributes(expected_event_attrs) + end + end + + before do + allow(Gitlab::Cache::Import::Caching).to receive(:read_integer).and_return(label.id) + end + + context 'when importing a labeled event' do + let(:event_type) { 'labeled' } + let(:expected_event_attrs) { event_attrs.merge(action: 'add') } + + it_behaves_like 'new event' + end + + context 'when importing an unlabeled event' do + let(:event_type) { 'unlabeled' } + let(:expected_event_attrs) { event_attrs.merge(action: 'remove') } + + it_behaves_like 'new event' + end +end |