diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-16 13:42:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-16 13:42:19 +0300 |
commit | 84d1bd786125c1c14a3ba5f63e38a4cc736a9027 (patch) | |
tree | f550fa965f507077e20dbb6d61a8269a99ef7107 /spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb | |
parent | 3a105e36e689f7b75482236712f1a47fd5a76814 (diff) |
Add latest changes from gitlab-org/gitlab@16-8-stable-eev16.8.0-rc42
Diffstat (limited to 'spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb')
-rw-r--r-- | spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb b/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb index aa8243154ef..cbe27934bd5 100644 --- a/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb @@ -5,16 +5,13 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::ImportIssueEventWorker, feature_category: :importers do subject(:worker) { described_class.new } - describe '#import' do - let(:import_state) { create(:import_state, :started) } - - let(:project) do - instance_double('Project', full_path: 'foo/bar', id: 1, import_state: import_state) + describe '#execute' do + let_it_be(:project) do + create(:project, import_url: 'https://github.com/foo/bar.git', import_state: create(:import_state, :started)) end - let(:client) { instance_double('Gitlab::GithubImport::Client') } - let(:importer) { instance_double('Gitlab::GithubImport::Importer::IssueEventImporter') } - + let(:client) { instance_double(Gitlab::GithubImport::Client) } + let(:extended_events) { true } let(:event_hash) do { 'id' => 6501124486, @@ -29,23 +26,55 @@ RSpec.describe Gitlab::GithubImport::ImportIssueEventWorker, feature_category: : } end - it 'imports an issue event' do - expect(Gitlab::GithubImport::Importer::IssueEventImporter) - .to receive(:new) - .with( - an_instance_of(Gitlab::GithubImport::Representation::IssueEvent), - project, - client - ) - .and_return(importer) + before do + allow_next_instance_of(Gitlab::GithubImport::Settings) do |setting| + allow(setting).to receive(:extended_events?).and_return(extended_events) + end + end - expect(importer).to receive(:execute) + it 'imports an issue event and increase importer counter' do + expect_next_instance_of(Gitlab::GithubImport::Importer::IssueEventImporter, + an_instance_of(Gitlab::GithubImport::Representation::IssueEvent), + project, + client + ) do |importer| + expect(importer).to receive(:execute) + end expect(Gitlab::GithubImport::ObjectCounter) .to receive(:increment) + .with(project, :issue_event, :imported) .and_call_original worker.import(project, client, event_hash) end + + context 'when event should increment a mapped importer counter' do + before do + stub_const('Gitlab::GithubImport::Importer::IssueEventImporter::EVENT_COUNTER_MAP', { + 'closed' => 'custom_type' + }) + + allow_next_instance_of(Gitlab::GithubImport::Importer::IssueEventImporter) do |importer| + allow(importer).to receive(:execute) + end + end + + it 'increments the mapped importer counter' do + expect(Gitlab::GithubImport::ObjectCounter).to receive(:increment).with(project, 'custom_type', :imported) + + worker.import(project, client, event_hash) + end + + context 'when extended_events is disabled' do + let(:extended_events) { false } + + it 'increments the issue_event importer counter' do + expect(Gitlab::GithubImport::ObjectCounter).to receive(:increment).with(project, :issue_event, :imported) + + worker.import(project, client, event_hash) + end + end + end end end |