2021-05-27 18:10:52 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe BulkImports::ExportStatus do
|
|
|
|
let_it_be(:relation) { 'labels' }
|
|
|
|
let_it_be(:import) { create(:bulk_import) }
|
|
|
|
let_it_be(:config) { create(:bulk_import_configuration, bulk_import: import) }
|
|
|
|
let_it_be(:entity) { create(:bulk_import_entity, bulk_import: import, source_full_path: 'foo') }
|
|
|
|
let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) }
|
|
|
|
|
|
|
|
let(:response_double) do
|
2022-05-27 15:08:25 +00:00
|
|
|
instance_double(HTTParty::Response,
|
|
|
|
parsed_response: [{ 'relation' => 'labels', 'status' => status, 'error' => 'error!' }]
|
|
|
|
)
|
2022-03-30 00:09:03 +00:00
|
|
|
end
|
|
|
|
|
2021-05-27 18:10:52 +00:00
|
|
|
subject { described_class.new(tracker, relation) }
|
|
|
|
|
|
|
|
before do
|
2021-06-11 15:09:58 +00:00
|
|
|
allow_next_instance_of(BulkImports::Clients::HTTP) do |client|
|
2021-05-27 18:10:52 +00:00
|
|
|
allow(client).to receive(:get).and_return(response_double)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#started?' do
|
|
|
|
context 'when export status is started' do
|
|
|
|
let(:status) { BulkImports::Export::STARTED }
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(subject.started?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when export status is not started' do
|
|
|
|
let(:status) { BulkImports::Export::FAILED }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.started?).to eq(false)
|
|
|
|
end
|
2022-05-27 15:08:25 +00:00
|
|
|
end
|
2022-03-30 00:09:03 +00:00
|
|
|
|
2022-05-27 15:08:25 +00:00
|
|
|
context 'when export status is not present' do
|
|
|
|
let(:response_double) do
|
|
|
|
instance_double(HTTParty::Response, parsed_response: [])
|
|
|
|
end
|
2022-03-30 00:09:03 +00:00
|
|
|
|
2022-05-27 15:08:25 +00:00
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.started?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when something goes wrong during export status fetch' do
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(BulkImports::Clients::HTTP) do |client|
|
|
|
|
allow(client).to receive(:get).and_raise(
|
|
|
|
BulkImports::NetworkError.new("Unsuccessful response", response: nil)
|
|
|
|
)
|
2022-03-30 00:09:03 +00:00
|
|
|
end
|
|
|
|
end
|
2022-05-27 15:08:25 +00:00
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.started?).to eq(false)
|
|
|
|
end
|
2021-05-27 18:10:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-27 15:08:25 +00:00
|
|
|
describe '#failed?' do
|
2021-05-27 18:10:52 +00:00
|
|
|
context 'when export status is failed' do
|
|
|
|
let(:status) { BulkImports::Export::FAILED }
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(subject.failed?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when export status is not failed' do
|
|
|
|
let(:status) { BulkImports::Export::STARTED }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.failed?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2022-03-14 09:08:52 +00:00
|
|
|
|
|
|
|
context 'when export status is not present' do
|
|
|
|
let(:response_double) do
|
2022-05-27 15:08:25 +00:00
|
|
|
instance_double(HTTParty::Response, parsed_response: [])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.started?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when something goes wrong during export status fetch' do
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(BulkImports::Clients::HTTP) do |client|
|
|
|
|
allow(client).to receive(:get).and_raise(
|
|
|
|
BulkImports::NetworkError.new("Unsuccessful response", response: nil)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.started?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#empty?' do
|
|
|
|
context 'when export status is present' do
|
|
|
|
let(:status) { 'any status' }
|
|
|
|
|
|
|
|
it { expect(subject.empty?).to eq(false) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when export status is not present' do
|
|
|
|
let(:response_double) do
|
|
|
|
instance_double(HTTParty::Response, parsed_response: [])
|
2022-03-14 09:08:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
2022-05-27 15:08:25 +00:00
|
|
|
expect(subject.empty?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when export status is empty' do
|
|
|
|
let(:response_double) do
|
|
|
|
instance_double(HTTParty::Response, parsed_response: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(subject.empty?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when something goes wrong during export status fetch' do
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(BulkImports::Clients::HTTP) do |client|
|
|
|
|
allow(client).to receive(:get).and_raise(
|
|
|
|
BulkImports::NetworkError.new("Unsuccessful response", response: nil)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.started?).to eq(false)
|
2022-03-14 09:08:52 +00:00
|
|
|
end
|
|
|
|
end
|
2021-05-27 18:10:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#error' do
|
|
|
|
let(:status) { BulkImports::Export::FAILED }
|
|
|
|
|
|
|
|
it 'returns error message' do
|
|
|
|
expect(subject.error).to eq('error!')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when something goes wrong during export status fetch' do
|
|
|
|
it 'returns exception class as error' do
|
2021-06-11 15:09:58 +00:00
|
|
|
allow_next_instance_of(BulkImports::Clients::HTTP) do |client|
|
2021-05-27 18:10:52 +00:00
|
|
|
allow(client).to receive(:get).and_raise(StandardError, 'Error!')
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(subject.error).to eq('Error!')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|