diff options
Diffstat (limited to 'spec/serializers')
-rw-r--r-- | spec/serializers/build_details_entity_spec.rb | 1 | ||||
-rw-r--r-- | spec/serializers/ci/pipeline_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/diff_file_entity_spec.rb | 4 | ||||
-rw-r--r-- | spec/serializers/diff_file_metadata_entity_spec.rb | 10 | ||||
-rw-r--r-- | spec/serializers/diffs_entity_spec.rb | 22 | ||||
-rw-r--r-- | spec/serializers/diffs_metadata_entity_spec.rb | 58 | ||||
-rw-r--r-- | spec/serializers/integrations/project_entity_spec.rb | 26 | ||||
-rw-r--r-- | spec/serializers/integrations/project_serializer_spec.rb | 9 | ||||
-rw-r--r-- | spec/serializers/jira_connect/app_data_serializer_spec.rb | 34 | ||||
-rw-r--r-- | spec/serializers/jira_connect/group_entity_spec.rb | 18 | ||||
-rw-r--r-- | spec/serializers/jira_connect/subscription_entity_spec.rb | 22 | ||||
-rw-r--r-- | spec/serializers/merge_request_poll_cached_widget_entity_spec.rb | 10 | ||||
-rw-r--r-- | spec/serializers/merge_request_poll_widget_entity_spec.rb | 48 | ||||
-rw-r--r-- | spec/serializers/merge_request_widget_entity_spec.rb | 43 | ||||
-rw-r--r-- | spec/serializers/paginated_diff_entity_spec.rb | 18 |
15 files changed, 251 insertions, 74 deletions
diff --git a/spec/serializers/build_details_entity_spec.rb b/spec/serializers/build_details_entity_spec.rb index 4a58f341658..8a63715ed86 100644 --- a/spec/serializers/build_details_entity_spec.rb +++ b/spec/serializers/build_details_entity_spec.rb @@ -133,6 +133,7 @@ RSpec.describe BuildDetailsEntity do let(:message) { subject[:callout_message] } before do + build.pipeline.unlocked! build.drop!(:missing_dependency_failure) end diff --git a/spec/serializers/ci/pipeline_entity_spec.rb b/spec/serializers/ci/pipeline_entity_spec.rb index 054406e4e65..f79bbd91a0a 100644 --- a/spec/serializers/ci/pipeline_entity_spec.rb +++ b/spec/serializers/ci/pipeline_entity_spec.rb @@ -18,7 +18,7 @@ RSpec.describe Ci::PipelineEntity do let(:pipeline) { create(:ci_empty_pipeline) } it 'contains required fields' do - expect(subject).to include :id, :user, :path, :coverage, :source + expect(subject).to include :id, :iid, :user, :path, :coverage, :source expect(subject).to include :ref, :commit expect(subject).to include :updated_at, :created_at end diff --git a/spec/serializers/diff_file_entity_spec.rb b/spec/serializers/diff_file_entity_spec.rb index c15c9324f94..ebfb21c4311 100644 --- a/spec/serializers/diff_file_entity_spec.rb +++ b/spec/serializers/diff_file_entity_spec.rb @@ -82,7 +82,7 @@ RSpec.describe DiffFileEntity do describe '#is_fully_expanded' do context 'file with a conflict' do - let(:options) { { conflicts: { diff_file.new_path => double(diff_lines_for_serializer: []) } } } + let(:options) { { conflicts: { diff_file.new_path => double(diff_lines_for_serializer: [], conflict_type: :both_modified) } } } it 'returns false' do expect(diff_file).not_to receive(:fully_expanded?) @@ -90,4 +90,6 @@ RSpec.describe DiffFileEntity do end end end + + it_behaves_like 'diff file with conflict_type' end diff --git a/spec/serializers/diff_file_metadata_entity_spec.rb b/spec/serializers/diff_file_metadata_entity_spec.rb index 3ce1ea49677..6f76d812177 100644 --- a/spec/serializers/diff_file_metadata_entity_spec.rb +++ b/spec/serializers/diff_file_metadata_entity_spec.rb @@ -4,8 +4,9 @@ require 'spec_helper' RSpec.describe DiffFileMetadataEntity do let(:merge_request) { create(:merge_request_with_diffs) } - let(:raw_diff_file) { merge_request.merge_request_diff.diffs.raw_diff_files.first } - let(:entity) { described_class.new(raw_diff_file) } + let(:diff_file) { merge_request.merge_request_diff.diffs.raw_diff_files.first } + let(:options) { {} } + let(:entity) { described_class.new(diff_file, options) } context 'as json' do subject { entity.as_json } @@ -20,8 +21,11 @@ RSpec.describe DiffFileMetadataEntity do :deleted_file, :submodule, :file_identifier_hash, - :file_hash + :file_hash, + :conflict_type ) end + + it_behaves_like 'diff file with conflict_type' end end diff --git a/spec/serializers/diffs_entity_spec.rb b/spec/serializers/diffs_entity_spec.rb index a7446f14745..aef7d3732f8 100644 --- a/spec/serializers/diffs_entity_spec.rb +++ b/spec/serializers/diffs_entity_spec.rb @@ -9,8 +9,14 @@ RSpec.describe DiffsEntity do let(:request) { EntityRequest.new(project: project, current_user: user) } let(:merge_request_diffs) { merge_request.merge_request_diffs } + let(:allow_tree_conflicts) { false } let(:options) do - { request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs } + { + request: request, + merge_request: merge_request, + merge_request_diffs: merge_request_diffs, + allow_tree_conflicts: allow_tree_conflicts + } end let(:entity) do @@ -87,7 +93,7 @@ RSpec.describe DiffsEntity do let(:diff_file_without_conflict) { diff_files.to_a[-2] } let(:resolvable_conflicts) { true } - let(:conflict_file) { double(our_path: diff_file_with_conflict.new_path) } + let(:conflict_file) { double(path: diff_file_with_conflict.new_path, conflict_type: :both_modified) } let(:conflicts) { double(conflicts: double(files: [conflict_file]), can_be_resolved_in_ui?: resolvable_conflicts) } let(:merge_ref_head_diff) { true } @@ -123,6 +129,18 @@ RSpec.describe DiffsEntity do subject end + + context 'when allow_tree_conflicts is set to true' do + let(:allow_tree_conflicts) { true } + + it 'conflicts are still highlighted' do + expect(conflict_file).to receive(:diff_lines_for_serializer) + expect(diff_file_with_conflict).not_to receive(:diff_lines_for_serializer) + expect(diff_file_without_conflict).to receive(:diff_lines_for_serializer).twice # for highlighted_diff_lines and is_fully_expanded + + subject + end + end end end end diff --git a/spec/serializers/diffs_metadata_entity_spec.rb b/spec/serializers/diffs_metadata_entity_spec.rb index b1cbe7e216e..3311b434ce5 100644 --- a/spec/serializers/diffs_metadata_entity_spec.rb +++ b/spec/serializers/diffs_metadata_entity_spec.rb @@ -9,12 +9,17 @@ RSpec.describe DiffsMetadataEntity do let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let(:merge_request_diffs) { merge_request.merge_request_diffs } let(:merge_request_diff) { merge_request_diffs.last } + let(:options) { {} } let(:entity) do - described_class.new(merge_request_diff.diffs, - request: request, - merge_request: merge_request, - merge_request_diffs: merge_request_diffs) + described_class.new( + merge_request_diff.diffs, + options.merge( + request: request, + merge_request: merge_request, + merge_request_diffs: merge_request_diffs + ) + ) end context 'as json' do @@ -38,20 +43,61 @@ RSpec.describe DiffsMetadataEntity do end describe 'diff_files' do - it 'returns diff files metadata' do - raw_diff_files = merge_request_diff.diffs.raw_diff_files + let!(:raw_diff_files) { merge_request_diff.diffs.raw_diff_files } + before do expect_next_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff) do |instance| # Use lightweight version instead. Several methods delegate to it, so putting a 5 # calls limit. expect(instance).to receive(:raw_diff_files).at_most(5).times.and_call_original expect(instance).not_to receive(:diff_files) end + end + it 'returns diff files metadata' do payload = DiffFileMetadataEntity.represent(raw_diff_files).as_json expect(subject[:diff_files]).to eq(payload) end + + context 'when merge_ref_head_diff and allow_tree_conflicts options are set' do + let(:conflict_file) { double(path: raw_diff_files.first.new_path, conflict_type: :both_modified) } + let(:conflicts) { double(conflicts: double(files: [conflict_file]), can_be_resolved_in_ui?: false) } + + before do + allow(MergeRequests::Conflicts::ListService).to receive(:new).and_return(conflicts) + end + + context 'when merge_ref_head_diff is true and allow_tree_conflicts is false' do + let(:options) { { merge_ref_head_diff: true, allow_tree_conflicts: false } } + + it 'returns diff files metadata without conflicts' do + payload = DiffFileMetadataEntity.represent(raw_diff_files).as_json + + expect(subject[:diff_files]).to eq(payload) + end + end + + context 'when merge_ref_head_diff is false and allow_tree_conflicts is true' do + let(:options) { { merge_ref_head_diff: false, allow_tree_conflicts: true } } + + it 'returns diff files metadata without conflicts' do + payload = DiffFileMetadataEntity.represent(raw_diff_files).as_json + + expect(subject[:diff_files]).to eq(payload) + end + end + + context 'when merge_ref_head_diff and allow_tree_conflicts are true' do + let(:options) { { merge_ref_head_diff: true, allow_tree_conflicts: true } } + + it 'returns diff files metadata with conflicts' do + payload = DiffFileMetadataEntity.represent(raw_diff_files, conflicts: { conflict_file.path => conflict_file }).as_json + + expect(subject[:diff_files]).to eq(payload) + end + end + end end end end diff --git a/spec/serializers/integrations/project_entity_spec.rb b/spec/serializers/integrations/project_entity_spec.rb new file mode 100644 index 00000000000..1564f7fad63 --- /dev/null +++ b/spec/serializers/integrations/project_entity_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Integrations::ProjectEntity do + let_it_be(:project) { create(:project, :with_avatar) } + + let(:entity) do + described_class.new(project) + end + + context 'as json' do + include Gitlab::Routing.url_helpers + + subject { entity.as_json } + + it 'contains needed attributes' do + expect(subject).to include( + avatar_url: include('uploads'), + name: project.name, + full_path: project_path(project), + full_name: project.full_name + ) + end + end +end diff --git a/spec/serializers/integrations/project_serializer_spec.rb b/spec/serializers/integrations/project_serializer_spec.rb new file mode 100644 index 00000000000..053548075bb --- /dev/null +++ b/spec/serializers/integrations/project_serializer_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Integrations::ProjectSerializer do + it 'represents Integrations::ProjectEntity entities' do + expect(described_class.entity_class).to eq(Integrations::ProjectEntity) + end +end diff --git a/spec/serializers/jira_connect/app_data_serializer_spec.rb b/spec/serializers/jira_connect/app_data_serializer_spec.rb new file mode 100644 index 00000000000..9c10a8a54a1 --- /dev/null +++ b/spec/serializers/jira_connect/app_data_serializer_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe JiraConnect::AppDataSerializer do + describe '#as_json' do + subject(:app_data_json) { described_class.new(subscriptions, signed_in).as_json } + + let_it_be(:subscriptions) { create_list(:jira_connect_subscription, 2) } + + let(:signed_in) { false } + + it 'uses the subscription entity' do + expect(JiraConnect::SubscriptionEntity).to receive(:represent).with(subscriptions) + + app_data_json + end + + it 'includes a group path with already subscribed namespaces as skip_groups' do + expected_path = "/api/v4/groups?min_access_level=40&skip_groups%5B%5D=#{subscriptions.first.namespace_id}&skip_groups%5B%5D=#{subscriptions.last.namespace_id}" + + expect(app_data_json).to include(groups_path: expected_path) + end + + it { is_expected.to include(subscriptions_path: '/-/jira_connect/subscriptions') } + it { is_expected.to include(login_path: '/-/jira_connect/users') } + + context 'when signed in' do + let(:signed_in) { true } + + it { is_expected.to include(login_path: nil) } + end + end +end diff --git a/spec/serializers/jira_connect/group_entity_spec.rb b/spec/serializers/jira_connect/group_entity_spec.rb new file mode 100644 index 00000000000..ade5ae89c52 --- /dev/null +++ b/spec/serializers/jira_connect/group_entity_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe JiraConnect::GroupEntity do + subject do + described_class.new(subscription.namespace).as_json + end + + let(:subscription) { create(:jira_connect_subscription) } + + it 'contains all necessary elements of the group', :aggregate_failures do + expect(subject[:name]).to eq(subscription.namespace.name) + expect(subject[:avatar_url]).to eq(subscription.namespace.avatar_url) + expect(subject[:full_name]).to eq(subscription.namespace.full_name) + expect(subject[:description]).to eq(subscription.namespace.description) + end +end diff --git a/spec/serializers/jira_connect/subscription_entity_spec.rb b/spec/serializers/jira_connect/subscription_entity_spec.rb new file mode 100644 index 00000000000..5d5d6d585f2 --- /dev/null +++ b/spec/serializers/jira_connect/subscription_entity_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe JiraConnect::SubscriptionEntity do + subject do + described_class.new(subscription).as_json + end + + let(:subscription) { create(:jira_connect_subscription) } + + it 'contains all necessary elements of the subscription', :aggregate_failures do + expect(subject).to include(:created_at) + expect(subject[:unlink_path]).to eq("/-/jira_connect/subscriptions/#{subscription.id}") + expect(subject[:group]).to eq( + name: subscription.namespace.name, + avatar_url: subscription.namespace.avatar_url, + full_name: subscription.namespace.full_name, + description: subscription.namespace.description + ) + end +end diff --git a/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb b/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb index 5845a868e53..5f4b734fcea 100644 --- a/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb +++ b/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb @@ -302,16 +302,6 @@ RSpec.describe MergeRequestPollCachedWidgetEntity do expect(subject[:merge_pipeline]).to be_nil end end - - context 'when merge_request_cached_merge_pipeline_serializer is disabled' do - before do - stub_feature_flags(merge_request_cached_merge_pipeline_serializer: false) - end - - it 'returns nil' do - expect(subject[:merge_pipeline]).to be_nil - end - end end end diff --git a/spec/serializers/merge_request_poll_widget_entity_spec.rb b/spec/serializers/merge_request_poll_widget_entity_spec.rb index 9a0e25516cb..3aebe16438c 100644 --- a/spec/serializers/merge_request_poll_widget_entity_spec.rb +++ b/spec/serializers/merge_request_poll_widget_entity_spec.rb @@ -22,54 +22,6 @@ RSpec.describe MergeRequestPollWidgetEntity do .to eq(resource.default_merge_commit_message(include_description: true)) end - describe 'merge_pipeline' do - before do - stub_feature_flags(merge_request_cached_merge_pipeline_serializer: false) - end - - it 'returns nil' do - expect(subject[:merge_pipeline]).to be_nil - end - - context 'when is merged' do - let_it_be(:resource) { create(:merged_merge_request, source_project: project, merge_commit_sha: project.commit.id) } - let_it_be(:pipeline) { create(:ci_empty_pipeline, project: project, ref: resource.target_branch, sha: resource.merge_commit_sha) } - - before do - project.add_maintainer(user) - end - - context 'when user cannot read pipelines on target project' do - before do - project.team.truncate - end - - it 'returns nil' do - expect(subject[:merge_pipeline]).to be_nil - end - end - - it 'returns merge_pipeline' do - pipeline_payload = - MergeRequests::PipelineEntity - .represent(pipeline, request: request) - .as_json - - expect(subject[:merge_pipeline]).to eq(pipeline_payload) - end - - context 'when merge_request_cached_merge_pipeline_serializer is enabled' do - before do - stub_feature_flags(merge_request_cached_merge_pipeline_serializer: true) - end - - it 'returns nil' do - expect(subject[:merge_pipeline]).to be_nil - end - end - end - end - describe 'new_blob_path' do context 'when user can push to project' do it 'returns path' do diff --git a/spec/serializers/merge_request_widget_entity_spec.rb b/spec/serializers/merge_request_widget_entity_spec.rb index 926b33e8e1f..35846b0d4ea 100644 --- a/spec/serializers/merge_request_widget_entity_spec.rb +++ b/spec/serializers/merge_request_widget_entity_spec.rb @@ -58,7 +58,7 @@ RSpec.describe MergeRequestWidgetEntity do data = described_class.new(resource, request: request, issues_links: true).as_json expect(data).to include(:issues_links) - expect(data[:issues_links]).to include(:assign_to_closing, :closing, :mentioned_but_not_closing) + expect(data[:issues_links]).to include(:assign_to_closing, :closing, :mentioned_but_not_closing, :closing_count, :mentioned_count) end it 'omits issue links by default' do @@ -354,4 +354,45 @@ RSpec.describe MergeRequestWidgetEntity do end end end + + describe 'when gitpod is disabled' do + before do + allow(Gitlab::CurrentSettings).to receive(:gitpod_enabled).and_return(false) + end + + it 'exposes gitpod attributes' do + expect(subject).to include( + show_gitpod_button: false, + gitpod_url: nil, + gitpod_enabled: false + ) + end + end + + describe 'when gitpod is enabled' do + before do + allow(Gitlab::CurrentSettings).to receive(:gitpod_enabled).and_return(true) + allow(Gitlab::CurrentSettings).to receive(:gitpod_url).and_return("https://gitpod.example.com") + end + + it 'exposes gitpod attributes' do + mr_url = Gitlab::Routing.url_helpers.project_merge_request_url(resource.project, resource) + + expect(subject).to include( + show_gitpod_button: true, + gitpod_url: "https://gitpod.example.com##{mr_url}", + gitpod_enabled: false + ) + end + + describe 'when gitpod is enabled for user' do + before do + allow(user).to receive(:gitpod_enabled).and_return(true) + end + + it 'exposes gitpod_enabled as true' do + expect(subject[:gitpod_enabled]).to be(true) + end + end + end end diff --git a/spec/serializers/paginated_diff_entity_spec.rb b/spec/serializers/paginated_diff_entity_spec.rb index f408deb734e..db8bf92cbf5 100644 --- a/spec/serializers/paginated_diff_entity_spec.rb +++ b/spec/serializers/paginated_diff_entity_spec.rb @@ -7,11 +7,13 @@ RSpec.describe PaginatedDiffEntity do let(:request) { double('request', current_user: user) } let(:merge_request) { create(:merge_request) } let(:diff_batch) { merge_request.merge_request_diff.diffs_in_batch(2, 3, diff_options: nil) } + let(:allow_tree_conflicts) { false } let(:options) do { request: request, merge_request: merge_request, - pagination_data: diff_batch.pagination_data + pagination_data: diff_batch.pagination_data, + allow_tree_conflicts: allow_tree_conflicts } end @@ -34,7 +36,7 @@ RSpec.describe PaginatedDiffEntity do let(:diff_file_without_conflict) { diff_files.first } let(:resolvable_conflicts) { true } - let(:conflict_file) { double(our_path: diff_file_with_conflict.new_path) } + let(:conflict_file) { double(path: diff_file_with_conflict.new_path, conflict_type: :both_modified) } let(:conflicts) { double(conflicts: double(files: [conflict_file]), can_be_resolved_in_ui?: resolvable_conflicts) } let(:merge_ref_head_diff) { true } @@ -70,6 +72,18 @@ RSpec.describe PaginatedDiffEntity do subject end + + context 'when allow_tree_conflicts is set to true' do + let(:allow_tree_conflicts) { true } + + it 'conflicts are still highlighted' do + expect(conflict_file).to receive(:diff_lines_for_serializer) + expect(diff_file_with_conflict).not_to receive(:diff_lines_for_serializer) + expect(diff_file_without_conflict).to receive(:diff_lines_for_serializer).twice # for highlighted_diff_lines and is_fully_expanded + + subject + end + end end end end |