diff options
Diffstat (limited to 'spec/lib/bulk_imports/groups/pipelines/labels_pipeline_spec.rb')
-rw-r--r-- | spec/lib/bulk_imports/groups/pipelines/labels_pipeline_spec.rb | 87 |
1 files changed, 28 insertions, 59 deletions
diff --git a/spec/lib/bulk_imports/groups/pipelines/labels_pipeline_spec.rb b/spec/lib/bulk_imports/groups/pipelines/labels_pipeline_spec.rb index 3327a30f1d5..8af646d1101 100644 --- a/spec/lib/bulk_imports/groups/pipelines/labels_pipeline_spec.rb +++ b/spec/lib/bulk_imports/groups/pipelines/labels_pipeline_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' RSpec.describe BulkImports::Groups::Pipelines::LabelsPipeline do - let(:user) { create(:user) } - let(:group) { create(:group) } - let(:cursor) { 'cursor' } - let(:timestamp) { Time.new(2020, 01, 01).utc } - let(:entity) do + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:timestamp) { Time.new(2020, 01, 01).utc } + + let_it_be(:entity) do create( :bulk_import_entity, source_full_path: 'source/full/path', @@ -17,33 +17,15 @@ RSpec.describe BulkImports::Groups::Pipelines::LabelsPipeline do ) end - let(:context) { BulkImports::Pipeline::Context.new(entity) } + let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) } + let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) } subject { described_class.new(context) } - def label_data(title) - { - 'title' => title, - 'description' => 'desc', - 'color' => '#428BCA', - 'created_at' => timestamp.to_s, - 'updated_at' => timestamp.to_s - } - end - - def extractor_data(title:, has_next_page:, cursor: nil) - page_info = { - 'end_cursor' => cursor, - 'has_next_page' => has_next_page - } - - BulkImports::Pipeline::ExtractedData.new(data: [label_data(title)], page_info: page_info) - end - describe '#run' do it 'imports a group labels' do - first_page = extractor_data(title: 'label1', has_next_page: true, cursor: cursor) - last_page = extractor_data(title: 'label2', has_next_page: false) + first_page = extracted_data(title: 'label1', has_next_page: true) + last_page = extracted_data(title: 'label2') allow_next_instance_of(BulkImports::Common::Extractors::GraphqlExtractor) do |extractor| allow(extractor) @@ -63,38 +45,6 @@ RSpec.describe BulkImports::Groups::Pipelines::LabelsPipeline do end end - describe '#after_run' do - context 'when extracted data has next page' do - it 'updates tracker information and runs pipeline again' do - data = extractor_data(title: 'label', has_next_page: true, cursor: cursor) - - expect(subject).to receive(:run) - - subject.after_run(data) - - tracker = entity.trackers.find_by(relation: :labels) - - expect(tracker.has_next_page).to eq(true) - expect(tracker.next_page).to eq(cursor) - end - end - - context 'when extracted data has no next page' do - it 'updates tracker information and does not run pipeline' do - data = extractor_data(title: 'label', has_next_page: false) - - expect(subject).not_to receive(:run) - - subject.after_run(data) - - tracker = entity.trackers.find_by(relation: :labels) - - expect(tracker.has_next_page).to eq(false) - expect(tracker.next_page).to be_nil - end - end - end - describe '#load' do it 'creates the label' do data = label_data('label') @@ -130,4 +80,23 @@ RSpec.describe BulkImports::Groups::Pipelines::LabelsPipeline do ) end end + + def label_data(title) + { + 'title' => title, + 'description' => 'desc', + 'color' => '#428BCA', + 'created_at' => timestamp.to_s, + 'updated_at' => timestamp.to_s + } + end + + def extracted_data(title:, has_next_page: false) + page_info = { + 'has_next_page' => has_next_page, + 'next_page' => has_next_page ? 'cursor' : nil + } + + BulkImports::Pipeline::ExtractedData.new(data: [label_data(title)], page_info: page_info) + end end |