2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::JiraImport::BaseImporter do
|
2020-05-24 23:13:21 +05:30
|
|
|
include JiraServiceHelper
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
describe 'with any inheriting class' do
|
2020-05-24 23:13:21 +05:30
|
|
|
context 'when project validation is ok' do
|
2021-09-30 23:02:18 +05:30
|
|
|
let!(:jira_integration) { create(:jira_integration, project: project) }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
before do
|
2021-09-30 23:02:18 +05:30
|
|
|
stub_jira_integration_test
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
allow(Gitlab::JiraImport).to receive(:validate_project_settings!)
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Jira service exists' do
|
|
|
|
context 'when Jira import data is not present' do
|
|
|
|
it 'raises exception' do
|
|
|
|
expect { described_class.new(project) }.to raise_error(Projects::ImportService::Error, 'Unable to find Jira project to import data from.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when import data exists' do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:jira_import) { create(:jira_import_state, project: project) }
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:subject) { described_class.new(project) }
|
|
|
|
|
|
|
|
context 'when #imported_items_cache_key is not implemented' do
|
|
|
|
it { expect { subject.send(:imported_items_cache_key) }.to raise_error(NotImplementedError) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when #imported_items_cache_key is implemented' do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:imported_items_cache_key).and_return('dumb-importer-key')
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#imported_items_cache_key' do
|
|
|
|
it { expect(subject.send(:imported_items_cache_key)).to eq('dumb-importer-key') }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#mark_as_imported', :clean_gitlab_redis_cache do
|
|
|
|
it 'stores id in redis cache' do
|
|
|
|
expect(Gitlab::Cache::Import::Caching).to receive(:set_add).once.and_call_original
|
|
|
|
|
|
|
|
subject.send(:mark_as_imported, 'some-id')
|
|
|
|
|
|
|
|
expect(Gitlab::Cache::Import::Caching.set_includes?(subject.send(:imported_items_cache_key), 'some-id')).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#already_imported?', :clean_gitlab_redis_cache do
|
|
|
|
it 'returns false if value is not in cache' do
|
|
|
|
expect(Gitlab::Cache::Import::Caching).to receive(:set_includes?).once.and_call_original
|
|
|
|
|
|
|
|
expect(subject.send(:already_imported?, 'some-id')).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true if value already stored in cache' do
|
|
|
|
Gitlab::Cache::Import::Caching.set_add(subject.send(:imported_items_cache_key), 'some-id')
|
|
|
|
|
|
|
|
expect(subject.send(:already_imported?, 'some-id')).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|