diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/finders/design_management | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/finders/design_management')
-rw-r--r-- | spec/finders/design_management/designs_finder_spec.rb | 105 | ||||
-rw-r--r-- | spec/finders/design_management/versions_finder_spec.rb | 129 |
2 files changed, 234 insertions, 0 deletions
diff --git a/spec/finders/design_management/designs_finder_spec.rb b/spec/finders/design_management/designs_finder_spec.rb new file mode 100644 index 00000000000..04bd0ad0a45 --- /dev/null +++ b/spec/finders/design_management/designs_finder_spec.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe DesignManagement::DesignsFinder do + include DesignManagementTestHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :private) } + let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:design1) { create(:design, :with_file, issue: issue, versions_count: 1) } + let_it_be(:design2) { create(:design, :with_file, issue: issue, versions_count: 1) } + let_it_be(:design3) { create(:design, :with_file, issue: issue, versions_count: 1) } + let(:params) { {} } + + subject(:designs) { described_class.new(issue, user, params).execute } + + describe '#execute' do + context 'when user can not read designs of an issue' do + it 'returns no results' do + is_expected.to be_empty + end + end + + context 'when user can read designs of an issue' do + before do + project.add_developer(user) + end + + context 'when design management feature is disabled' do + it 'returns no results' do + is_expected.to be_empty + end + end + + context 'when design management feature is enabled' do + before do + enable_design_management + end + + it 'returns the designs' do + is_expected.to contain_exactly(design1, design2, design3) + end + + context 'when argument is the ids of designs' do + let(:params) { { ids: [design1.id] } } + + it { is_expected.to eq([design1]) } + end + + context 'when argument is the filenames of designs' do + let(:params) { { filenames: [design2.filename] } } + + it { is_expected.to eq([design2]) } + end + + context 'when passed empty array' do + context 'for filenames' do + let(:params) { { filenames: [] } } + + it { is_expected.to be_empty } + end + + context "for ids" do + let(:params) { { ids: [] } } + + it { is_expected.to be_empty } + end + end + + describe 'returning designs that existed at a particular given version' do + let(:all_versions) { issue.design_collection.versions.ordered } + let(:first_version) { all_versions.last } + let(:second_version) { all_versions.second } + + context 'when argument is the first version' do + let(:params) { { visible_at_version: first_version } } + + it { is_expected.to eq([design1]) } + end + + context 'when arguments are version and id' do + context 'when id is absent at version' do + let(:params) { { visible_at_version: first_version, ids: [design2.id] } } + + it { is_expected.to eq([]) } + end + + context 'when id is present at version' do + let(:params) { { visible_at_version: second_version, ids: [design2.id] } } + + it { is_expected.to eq([design2]) } + end + end + + context 'when argument is the second version' do + let(:params) { { visible_at_version: second_version } } + + it { is_expected.to contain_exactly(design1, design2) } + end + end + end + end + end +end diff --git a/spec/finders/design_management/versions_finder_spec.rb b/spec/finders/design_management/versions_finder_spec.rb new file mode 100644 index 00000000000..11d53d0d630 --- /dev/null +++ b/spec/finders/design_management/versions_finder_spec.rb @@ -0,0 +1,129 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe DesignManagement::VersionsFinder do + include DesignManagementTestHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :private) } + let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:design_1) { create(:design, :with_file, issue: issue, versions_count: 1) } + let_it_be(:design_2) { create(:design, :with_file, issue: issue, versions_count: 1) } + let(:version_1) { design_1.versions.first } + let(:version_2) { design_2.versions.first } + let(:design_or_collection) { issue.design_collection } + let(:params) { {} } + + let(:finder) { described_class.new(design_or_collection, user, params) } + + subject(:versions) { finder.execute } + + describe '#execute' do + shared_examples 'returns no results' do + it 'returns no results when passed a DesignCollection' do + expect(design_or_collection).is_a?(DesignManagement::DesignCollection) + is_expected.to be_empty + end + + context 'when passed a Design' do + let(:design_or_collection) { design_1 } + + it 'returns no results when passed a Design' do + is_expected.to be_empty + end + end + end + + context 'when user cannot read designs of an issue' do + include_examples 'returns no results' + end + + context 'when user can read designs of an issue' do + before do + project.add_developer(user) + end + + context 'when design management feature is disabled' do + include_examples 'returns no results' + end + + context 'when design management feature is enabled' do + before do + enable_design_management + end + + describe 'passing a DesignCollection or a Design for the initial scoping' do + it 'returns the versions scoped to the DesignCollection' do + expect(design_or_collection).is_a?(DesignManagement::DesignCollection) + is_expected.to eq(issue.design_collection.versions.ordered) + end + + context 'when passed a Design' do + let(:design_or_collection) { design_1 } + + it 'returns the versions scoped to the Design' do + is_expected.to eq(design_1.versions) + end + end + end + + describe 'returning versions earlier or equal to a version' do + context 'when argument is the first version' do + let(:params) { { earlier_or_equal_to: version_1 }} + + it { is_expected.to eq([version_1]) } + end + + context 'when argument is the second version' do + let(:params) { { earlier_or_equal_to: version_2 }} + + it { is_expected.to contain_exactly(version_1, version_2) } + end + end + + describe 'returning versions by SHA' do + context 'when argument is the first version' do + let(:params) { { sha: version_1.sha } } + + it { is_expected.to contain_exactly(version_1) } + end + + context 'when argument is the second version' do + let(:params) { { sha: version_2.sha } } + + it { is_expected.to contain_exactly(version_2) } + end + end + + describe 'returning versions by ID' do + context 'when argument is the first version' do + let(:params) { { version_id: version_1.id } } + + it { is_expected.to contain_exactly(version_1) } + end + + context 'when argument is the second version' do + let(:params) { { version_id: version_2.id } } + + it { is_expected.to contain_exactly(version_2) } + end + end + + describe 'mixing id and sha' do + context 'when arguments are consistent' do + let(:params) { { version_id: version_1.id, sha: version_1.sha } } + + it { is_expected.to contain_exactly(version_1) } + end + + context 'when arguments are in-consistent' do + let(:params) { { version_id: version_1.id, sha: version_2.sha } } + + it { is_expected.to be_empty } + end + end + end + end + end +end |