diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-24 00:09:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-24 00:09:55 +0300 |
commit | 4e175ca905e0c6bdcf83f78fcffd1f5bc8767f82 (patch) | |
tree | 7285e810a23238b2eba789419554cd86c9d968f3 /spec/finders | |
parent | 3ca896b640def57a58485def308748b2fccbd0bb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders')
-rw-r--r-- | spec/finders/releases_finder_spec.rb | 101 |
1 files changed, 82 insertions, 19 deletions
diff --git a/spec/finders/releases_finder_spec.rb b/spec/finders/releases_finder_spec.rb index 858a0e566f6..a3418f08b7d 100644 --- a/spec/finders/releases_finder_spec.rb +++ b/spec/finders/releases_finder_spec.rb @@ -2,20 +2,15 @@ require 'spec_helper' -RSpec.describe ReleasesFinder do - let(:user) { create(:user) } - let(:group) { create :group } - let(:project) { create(:project, :repository, group: group) } +RSpec.describe ReleasesFinder, feature_category: :release_orchestration do + let_it_be(:user) { create(:user) } + let_it_be(:group) { create :group } + let_it_be(:project) { create(:project, :repository, group: group) } let(:params) { {} } let(:args) { {} } let(:repository) { project.repository } - let(:v1_0_0) { create(:release, project: project, tag: 'v1.0.0') } - let(:v1_1_0) { create(:release, project: project, tag: 'v1.1.0') } - - before do - v1_0_0.update_attribute(:released_at, 2.days.ago) - v1_1_0.update_attribute(:released_at, 1.day.ago) - end + let_it_be(:v1_0_0) { create(:release, project: project, tag: 'v1.0.0') } + let_it_be(:v1_1_0) { create(:release, project: project, tag: 'v1.1.0') } shared_examples_for 'when the user is not part of the project' do it 'returns no releases' do @@ -67,21 +62,20 @@ RSpec.describe ReleasesFinder do context 'when the user is a project guest' do before do project.add_guest(user) + + v1_0_0.update!(released_at: 2.days.ago, created_at: 1.day.ago) + v1_1_0.update!(released_at: 1.day.ago, created_at: 2.days.ago) end - it 'sorts by release date' do + it 'returns the releases' do is_expected.to be_present expect(subject.size).to eq(2) - expect(subject).to eq([v1_1_0, v1_0_0]) + expect(subject).to match_array([v1_1_0, v1_0_0]) end context 'with sorting parameters' do - before do - v1_1_0.update_attribute(:created_at, 3.days.ago) - end - - context 'by default is released_at in descending order' do - it { is_expected.to eq([v1_1_0, v1_0_0]) } + it 'sorted by released_at in descending order by default' do + is_expected.to eq([v1_1_0, v1_0_0]) end context 'released_at in ascending order' do @@ -107,4 +101,73 @@ RSpec.describe ReleasesFinder do it_behaves_like 'when a tag parameter is passed' end end + + describe 'when parent is an array of projects' do + let_it_be(:project2) { create(:project, :repository, group: group) } + let_it_be(:v2_0_0) { create(:release, project: project2, tag: 'v2.0.0') } + let_it_be(:v2_1_0) { create(:release, project: project2, tag: 'v2.1.0') } + + subject { described_class.new([project, project2], user, params).execute(**args) } + + context 'when the user is not part of any project' do + it_behaves_like 'when the user is not part of the project' + end + + context 'when the user is only part of one project' do + before do + project.add_guest(user) + end + + it 'returns the releases of only the authorized project' do + is_expected.to be_present + expect(subject.size).to eq(2) + expect(subject).to match_array([v1_1_0, v1_0_0]) + end + end + + context 'when the user is a guest on all projects' do + before do + project.add_guest(user) + project2.add_guest(user) + + v1_0_0.update!(released_at: 4.days.ago, created_at: 1.day.ago) + v1_1_0.update!(released_at: 3.days.ago, created_at: 2.days.ago) + v2_0_0.update!(released_at: 2.days.ago, created_at: 3.days.ago) + v2_1_0.update!(released_at: 1.day.ago, created_at: 4.days.ago) + end + + it 'returns the releases of all projects' do + is_expected.to be_present + expect(subject.size).to eq(4) + expect(subject).to match_array([v2_1_0, v2_0_0, v1_1_0, v1_0_0]) + end + + it_behaves_like 'preload' + it_behaves_like 'when a tag parameter is passed' + + context 'with sorting parameters' do + it 'sorted by released_at in descending order by default' do + is_expected.to eq([v2_1_0, v2_0_0, v1_1_0, v1_0_0]) + end + + context 'released_at in ascending order' do + let(:params) { { sort: 'asc' } } + + it { is_expected.to eq([v1_0_0, v1_1_0, v2_0_0, v2_1_0]) } + end + + context 'order by created_at in descending order' do + let(:params) { { order_by: 'created_at' } } + + it { is_expected.to eq([v1_0_0, v1_1_0, v2_0_0, v2_1_0]) } + end + + context 'order by created_at in ascending order' do + let(:params) { { order_by: 'created_at', sort: 'asc' } } + + it { is_expected.to eq([v2_1_0, v2_0_0, v1_1_0, v1_0_0]) } + end + end + end + end end |