debian-mirror-gitlab/spec/finders/bulk_imports/entities_finder_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
4 KiB
Ruby
Raw Normal View History

2021-09-30 23:02:18 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::EntitiesFinder do
let_it_be(:user) { create(:user) }
let_it_be(:user_import_1) { create(:bulk_import, user: user) }
let_it_be(:started_entity_1) { create(:bulk_import_entity, :started, bulk_import: user_import_1) }
let_it_be(:finished_entity_1) { create(:bulk_import_entity, :finished, bulk_import: user_import_1) }
let_it_be(:failed_entity_1) { create(:bulk_import_entity, :failed, bulk_import: user_import_1) }
let_it_be(:user_import_2) { create(:bulk_import, user: user) }
let_it_be(:started_entity_2) { create(:bulk_import_entity, :started, bulk_import: user_import_2) }
let_it_be(:finished_entity_2) { create(:bulk_import_entity, :finished, bulk_import: user_import_2) }
let_it_be(:failed_entity_2) { create(:bulk_import_entity, :failed, bulk_import: user_import_2) }
let_it_be(:not_user_import) { create(:bulk_import) }
let_it_be(:started_entity_3) { create(:bulk_import_entity, :started, bulk_import: not_user_import) }
let_it_be(:finished_entity_3) { create(:bulk_import_entity, :finished, bulk_import: not_user_import) }
let_it_be(:failed_entity_3) { create(:bulk_import_entity, :failed, bulk_import: not_user_import) }
subject { described_class.new(user: user) }
describe '#execute' do
it 'returns a list of import entities associated with user' do
expect(subject.execute)
.to contain_exactly(
started_entity_1, finished_entity_1, failed_entity_1,
started_entity_2, finished_entity_2, failed_entity_2
)
end
context 'when bulk import is specified' do
subject { described_class.new(user: user, bulk_import: user_import_1) }
it 'returns a list of import entities filtered by bulk import' do
expect(subject.execute)
.to contain_exactly(
started_entity_1, finished_entity_1, failed_entity_1
)
end
context 'when specified import is not associated with user' do
subject { described_class.new(user: user, bulk_import: not_user_import) }
it 'does not return entities' do
expect(subject.execute).to be_empty
end
end
end
context 'when status is specified' do
2022-06-21 17:19:12 +05:30
subject { described_class.new(user: user, params: { status: 'failed' }) }
2021-09-30 23:02:18 +05:30
it 'returns a list of import entities filtered by status' do
expect(subject.execute)
.to contain_exactly(
failed_entity_1, failed_entity_2
)
end
context 'when invalid status is specified' do
2022-06-21 17:19:12 +05:30
subject { described_class.new(user: user, params: { status: 'invalid' }) }
2021-09-30 23:02:18 +05:30
it 'does not filter entities by status' do
expect(subject.execute)
.to contain_exactly(
started_entity_1, finished_entity_1, failed_entity_1,
started_entity_2, finished_entity_2, failed_entity_2
)
end
end
end
context 'when bulk import and status are specified' do
2022-06-21 17:19:12 +05:30
subject { described_class.new(user: user, bulk_import: user_import_2, params: { status: 'finished' }) }
2021-09-30 23:02:18 +05:30
it 'returns matched import entities' do
expect(subject.execute).to contain_exactly(finished_entity_2)
end
end
2022-06-21 17:19:12 +05:30
context 'when order is specifed' do
subject { described_class.new(user: user, params: { sort: order }) }
context 'when order is specified as asc' do
let(:order) { :asc }
it 'returns entities sorted ascending' do
2022-10-11 01:57:18 +05:30
expect(subject.execute).to eq(
[
started_entity_1, finished_entity_1, failed_entity_1,
started_entity_2, finished_entity_2, failed_entity_2
])
2022-06-21 17:19:12 +05:30
end
end
context 'when order is specified as desc' do
let(:order) { :desc }
it 'returns entities sorted descending' do
2022-10-11 01:57:18 +05:30
expect(subject.execute).to eq(
[
failed_entity_2, finished_entity_2, started_entity_2,
failed_entity_1, finished_entity_1, started_entity_1
])
2022-06-21 17:19:12 +05:30
end
end
end
2021-09-30 23:02:18 +05:30
end
end