summaryrefslogtreecommitdiff
path: root/spec/serializers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/serializers
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
downloadgitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/base_discussion_entity_spec.rb9
-rw-r--r--spec/serializers/merge_request_user_entity_spec.rb53
-rw-r--r--spec/serializers/pipeline_serializer_spec.rb16
-rw-r--r--spec/serializers/test_suite_comparer_entity_spec.rb44
-rw-r--r--spec/serializers/test_suite_summary_entity_spec.rb4
5 files changed, 120 insertions, 6 deletions
diff --git a/spec/serializers/base_discussion_entity_spec.rb b/spec/serializers/base_discussion_entity_spec.rb
index 5f483da4113..334e71d23f4 100644
--- a/spec/serializers/base_discussion_entity_spec.rb
+++ b/spec/serializers/base_discussion_entity_spec.rb
@@ -66,4 +66,13 @@ RSpec.describe BaseDiscussionEntity do
)
end
end
+
+ context 'when issues are disabled in a project' do
+ let(:project) { create(:project, :issues_disabled) }
+ let(:note) { create(:discussion_note_on_merge_request, project: project) }
+
+ it 'does not show a new issues path' do
+ expect(entity.as_json[:resolve_with_issue_path]).to be_nil
+ end
+ end
end
diff --git a/spec/serializers/merge_request_user_entity_spec.rb b/spec/serializers/merge_request_user_entity_spec.rb
index dcd4ef6acfb..697fa3001e3 100644
--- a/spec/serializers/merge_request_user_entity_spec.rb
+++ b/spec/serializers/merge_request_user_entity_spec.rb
@@ -3,19 +3,22 @@
require 'spec_helper'
RSpec.describe MergeRequestUserEntity do
- let(:user) { create(:user) }
- let(:project) { create(:project, :repository) }
- let(:request) { EntityRequest.new(project: project, current_user: user) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:merge_request) { create(:merge_request) }
+ let(:request) { EntityRequest.new(project: merge_request.target_project, current_user: user) }
let(:entity) do
- described_class.new(user, request: request)
+ described_class.new(user, request: request, merge_request: merge_request)
end
- context 'as json' do
+ describe '#as_json' do
subject { entity.as_json }
it 'exposes needed attributes' do
- expect(subject).to include(:id, :name, :username, :state, :avatar_url, :web_url, :can_merge)
+ is_expected.to include(
+ :id, :name, :username, :state, :avatar_url, :web_url,
+ :can_merge, :can_update_merge_request, :reviewed, :approved
+ )
end
context 'when `status` is not preloaded' do
@@ -24,6 +27,22 @@ RSpec.describe MergeRequestUserEntity do
end
end
+ context 'when the user has not approved the merge-request' do
+ it 'exposes that the user has not approved the MR' do
+ expect(subject).to include(approved: false)
+ end
+ end
+
+ context 'when the user has approved the merge-request' do
+ before do
+ merge_request.approvals.create!(user: user)
+ end
+
+ it 'exposes that the user has approved the MR' do
+ expect(subject).to include(approved: true)
+ end
+ end
+
context 'when `status` is preloaded' do
before do
user.create_status!(availability: :busy)
@@ -35,5 +54,27 @@ RSpec.describe MergeRequestUserEntity do
expect(subject[:availability]).to eq('busy')
end
end
+
+ describe 'performance' do
+ let_it_be(:user_a) { create(:user) }
+ let_it_be(:user_b) { create(:user) }
+ let_it_be(:merge_request_b) { create(:merge_request) }
+
+ it 'is linear in the number of merge requests' do
+ pending "See: https://gitlab.com/gitlab-org/gitlab/-/issues/322549"
+ baseline = ActiveRecord::QueryRecorder.new do
+ ent = described_class.new(user_a, request: request, merge_request: merge_request)
+ ent.as_json
+ end
+
+ expect do
+ a = described_class.new(user_a, request: request, merge_request: merge_request_b)
+ b = described_class.new(user_b, request: request, merge_request: merge_request_b)
+
+ a.as_json
+ b.as_json
+ end.not_to exceed_query_limit(baseline)
+ end
+ end
end
end
diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb
index e0f6ab68034..bcaaa61eb04 100644
--- a/spec/serializers/pipeline_serializer_spec.rb
+++ b/spec/serializers/pipeline_serializer_spec.rb
@@ -209,6 +209,22 @@ RSpec.describe PipelineSerializer do
end
end
+ context 'with scheduled and manual builds' do
+ let(:ref) { 'feature' }
+
+ before do
+ create(:ci_build, :scheduled, pipeline: resource.first)
+ create(:ci_build, :scheduled, pipeline: resource.second)
+ create(:ci_build, :manual, pipeline: resource.first)
+ create(:ci_build, :manual, pipeline: resource.second)
+ end
+
+ it 'sends at most one metadata query for each type of build', :request_store do
+ # 1 for the existing failed builds and 2 for the added scheduled and manual builds
+ expect { subject }.not_to exceed_query_limit(1 + 2).for_query /SELECT "ci_builds_metadata".*/
+ end
+ end
+
def create_pipeline(status)
create(:ci_empty_pipeline,
project: project,
diff --git a/spec/serializers/test_suite_comparer_entity_spec.rb b/spec/serializers/test_suite_comparer_entity_spec.rb
index a63f5683779..318d1d3c1e3 100644
--- a/spec/serializers/test_suite_comparer_entity_spec.rb
+++ b/spec/serializers/test_suite_comparer_entity_spec.rb
@@ -35,6 +35,7 @@ RSpec.describe TestSuiteComparerEntity do
end
expect(subject[:resolved_failures]).to be_empty
expect(subject[:existing_failures]).to be_empty
+ expect(subject[:suite_errors]).to be_nil
end
end
@@ -56,6 +57,7 @@ RSpec.describe TestSuiteComparerEntity do
end
expect(subject[:resolved_failures]).to be_empty
expect(subject[:existing_failures]).to be_empty
+ expect(subject[:suite_errors]).to be_nil
end
end
@@ -77,6 +79,7 @@ RSpec.describe TestSuiteComparerEntity do
expect(existing_failure[:execution_time]).to eq(test_case_failed.execution_time)
expect(existing_failure[:system_output]).to eq(test_case_failed.system_output)
end
+ expect(subject[:suite_errors]).to be_nil
end
end
@@ -98,6 +101,47 @@ RSpec.describe TestSuiteComparerEntity do
expect(resolved_failure[:system_output]).to eq(test_case_success.system_output)
end
expect(subject[:existing_failures]).to be_empty
+ expect(subject[:suite_errors]).to be_nil
+ end
+ end
+
+ context 'when head suite has suite error' do
+ before do
+ allow(head_suite).to receive(:suite_error).and_return('some error')
+ end
+
+ it 'contains suite error for head suite' do
+ expect(subject[:suite_errors]).to eq(
+ head: 'some error',
+ base: nil
+ )
+ end
+ end
+
+ context 'when base suite has suite error' do
+ before do
+ allow(base_suite).to receive(:suite_error).and_return('some error')
+ end
+
+ it 'contains suite error for head suite' do
+ expect(subject[:suite_errors]).to eq(
+ head: nil,
+ base: 'some error'
+ )
+ end
+ end
+
+ context 'when base and head suite both have suite errors' do
+ before do
+ allow(head_suite).to receive(:suite_error).and_return('head error')
+ allow(base_suite).to receive(:suite_error).and_return('base error')
+ end
+
+ it 'contains suite error for head suite' do
+ expect(subject[:suite_errors]).to eq(
+ head: 'head error',
+ base: 'base error'
+ )
end
end
end
diff --git a/spec/serializers/test_suite_summary_entity_spec.rb b/spec/serializers/test_suite_summary_entity_spec.rb
index 864781ccfce..3d43feba910 100644
--- a/spec/serializers/test_suite_summary_entity_spec.rb
+++ b/spec/serializers/test_suite_summary_entity_spec.rb
@@ -20,5 +20,9 @@ RSpec.describe TestSuiteSummaryEntity do
it 'contains the build_ids' do
expect(as_json).to include(:build_ids)
end
+
+ it 'contains the suite_error' do
+ expect(as_json).to include(:suite_error)
+ end
end
end