Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 17:34:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 17:34:42 +0300
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /spec/serializers
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/accessibility_error_entity_spec.rb37
-rw-r--r--spec/serializers/accessibility_reports_comparer_entity_spec.rb87
-rw-r--r--spec/serializers/accessibility_reports_comparer_serializer_spec.rb65
-rw-r--r--spec/serializers/ci/dag_job_entity_spec.rb43
-rw-r--r--spec/serializers/ci/dag_job_group_entity_spec.rb58
-rw-r--r--spec/serializers/ci/dag_pipeline_entity_spec.rb112
-rw-r--r--spec/serializers/ci/dag_pipeline_serializer_spec.rb17
-rw-r--r--spec/serializers/ci/dag_stage_entity_spec.rb31
-rw-r--r--spec/serializers/cluster_application_entity_spec.rb12
-rw-r--r--spec/serializers/cluster_entity_spec.rb6
-rw-r--r--spec/serializers/cluster_serializer_spec.rb38
-rw-r--r--spec/serializers/diff_file_base_entity_spec.rb58
-rw-r--r--spec/serializers/diffs_metadata_entity_spec.rb2
-rw-r--r--spec/serializers/environment_entity_spec.rb50
-rw-r--r--spec/serializers/merge_request_poll_widget_entity_spec.rb44
-rw-r--r--spec/serializers/merge_request_sidebar_basic_entity_spec.rb2
-rw-r--r--spec/serializers/service_event_entity_spec.rb41
-rw-r--r--spec/serializers/test_case_entity_spec.rb4
-rw-r--r--spec/serializers/test_suite_entity_spec.rb50
19 files changed, 722 insertions, 35 deletions
diff --git a/spec/serializers/accessibility_error_entity_spec.rb b/spec/serializers/accessibility_error_entity_spec.rb
new file mode 100644
index 00000000000..e9bfabb7aa8
--- /dev/null
+++ b/spec/serializers/accessibility_error_entity_spec.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe AccessibilityErrorEntity do
+ let(:entity) { described_class.new(accessibility_error) }
+
+ describe '#as_json' do
+ subject { entity.as_json }
+
+ context 'when accessibility contains an error' do
+ let(:accessibility_error) do
+ {
+ code: "WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.A.NoContent",
+ type: "error",
+ typeCode: 1,
+ message: "Anchor element found with a valid href attribute, but no link content has been supplied.",
+ context: "<a href=\"/\" class=\"navbar-brand animated\"><svg height=\"36\" viewBox=\"0 0 1...</a>",
+ selector: "#main-nav > div:nth-child(1) > a",
+ runner: "htmlcs",
+ runnerExtras: {}
+ }
+ end
+
+ it 'contains correct accessibility error details', :aggregate_failures do
+ expect(subject[:code]).to eq("WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.A.NoContent")
+ expect(subject[:type]).to eq("error")
+ expect(subject[:type_code]).to eq(1)
+ expect(subject[:message]).to eq("Anchor element found with a valid href attribute, but no link content has been supplied.")
+ expect(subject[:context]).to eq("<a href=\"/\" class=\"navbar-brand animated\"><svg height=\"36\" viewBox=\"0 0 1...</a>")
+ expect(subject[:selector]).to eq("#main-nav > div:nth-child(1) > a")
+ expect(subject[:runner]).to eq("htmlcs")
+ expect(subject[:runner_extras]).to be_empty
+ end
+ end
+ end
+end
diff --git a/spec/serializers/accessibility_reports_comparer_entity_spec.rb b/spec/serializers/accessibility_reports_comparer_entity_spec.rb
new file mode 100644
index 00000000000..ed2c17de640
--- /dev/null
+++ b/spec/serializers/accessibility_reports_comparer_entity_spec.rb
@@ -0,0 +1,87 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe AccessibilityReportsComparerEntity do
+ let(:entity) { described_class.new(comparer) }
+ let(:comparer) { Gitlab::Ci::Reports::AccessibilityReportsComparer.new(base_report, head_report) }
+ let(:base_report) { Gitlab::Ci::Reports::AccessibilityReports.new }
+ let(:head_report) { Gitlab::Ci::Reports::AccessibilityReports.new }
+ let(:url) { "https://gitlab.com" }
+ let(:single_error) do
+ [
+ {
+ code: "WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.A.NoContent",
+ type: "error",
+ typeCode: 1,
+ message: "Anchor element found with a valid href attribute, but no link content has been supplied.",
+ context: "<a href=\"/\" class=\"navbar-brand animated\"><svg height=\"36\" viewBox=\"0 0 1...</a>",
+ selector: "#main-nav > div:nth-child(1) > a",
+ runner: "htmlcs",
+ runnerExtras: {}
+ }
+ ]
+ end
+ let(:different_error) do
+ [
+ {
+ code: "WCAG2AA.Principle1.Guideline1_4.1_4_3.G18.Fail",
+ type: "error",
+ typeCode: 1,
+ message: "This element has insufficient contrast at this conformance level.",
+ context: "<a href=\"/stages-devops-lifecycle/\" class=\"main-nav-link\">Product</a>",
+ selector: "#main-nav > div:nth-child(2) > ul > li:nth-child(1) > a",
+ runner: "htmlcs",
+ runnerExtras: {}
+ }
+ ]
+ end
+
+ describe '#as_json' do
+ subject { entity.as_json }
+
+ context 'when base report has error and head has a different error' do
+ before do
+ base_report.add_url(url, single_error)
+ head_report.add_url(url, different_error)
+ end
+
+ it 'contains correct compared accessibility report details', :aggregate_failures do
+ expect(subject[:status]).to eq(Gitlab::Ci::Reports::AccessibilityReportsComparer::STATUS_FAILED)
+ expect(subject[:resolved_errors].first).to include(:code, :type, :type_code, :message, :context, :selector, :runner, :runner_extras)
+ expect(subject[:new_errors].first).to include(:code, :type, :type_code, :message, :context, :selector, :runner, :runner_extras)
+ expect(subject[:existing_errors].first).to include(:code, :type, :type_code, :message, :context, :selector, :runner, :runner_extras)
+ expect(subject[:summary]).to include(total: 2, resolved: 1, errored: 1)
+ end
+ end
+
+ context 'when base report has error and head has the same error' do
+ before do
+ base_report.add_url(url, single_error)
+ head_report.add_url(url, single_error)
+ end
+
+ it 'contains correct compared accessibility report details', :aggregate_failures do
+ expect(subject[:status]).to eq(Gitlab::Ci::Reports::AccessibilityReportsComparer::STATUS_FAILED)
+ expect(subject[:new_errors]).to be_empty
+ expect(subject[:resolved_errors]).to be_empty
+ expect(subject[:existing_errors].first).to include(:code, :type, :type_code, :message, :context, :selector, :runner, :runner_extras)
+ expect(subject[:summary]).to include(total: 1, resolved: 0, errored: 1)
+ end
+ end
+
+ context 'when base report has no error and head has errors' do
+ before do
+ head_report.add_url(url, single_error)
+ end
+
+ it 'contains correct compared accessibility report details', :aggregate_failures do
+ expect(subject[:status]).to eq(Gitlab::Ci::Reports::AccessibilityReportsComparer::STATUS_FAILED)
+ expect(subject[:resolved_errors]).to be_empty
+ expect(subject[:existing_errors]).to be_empty
+ expect(subject[:new_errors].first).to include(:code, :type, :type_code, :message, :context, :selector, :runner, :runner_extras)
+ expect(subject[:summary]).to include(total: 1, resolved: 0, errored: 1)
+ end
+ end
+ end
+end
diff --git a/spec/serializers/accessibility_reports_comparer_serializer_spec.rb b/spec/serializers/accessibility_reports_comparer_serializer_spec.rb
new file mode 100644
index 00000000000..37dc760fdec
--- /dev/null
+++ b/spec/serializers/accessibility_reports_comparer_serializer_spec.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe AccessibilityReportsComparerSerializer do
+ let(:project) { double(:project) }
+ let(:serializer) { described_class.new(project: project).represent(comparer) }
+ let(:comparer) { Gitlab::Ci::Reports::AccessibilityReportsComparer.new(base_report, head_report) }
+ let(:base_report) { Gitlab::Ci::Reports::AccessibilityReports.new }
+ let(:head_report) { Gitlab::Ci::Reports::AccessibilityReports.new }
+ let(:url) { "https://gitlab.com" }
+ let(:single_error) do
+ [
+ {
+ code: "WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.A.NoContent",
+ type: "error",
+ typeCode: 1,
+ message: "Anchor element found with a valid href attribute, but no link content has been supplied.",
+ context: "<a href=\"/\" class=\"navbar-brand animated\"><svg height=\"36\" viewBox=\"0 0 1...</a>",
+ selector: "#main-nav > divnth-child(1) > a",
+ runner: "htmlcs",
+ runnerExtras: {}
+ }
+ ]
+ end
+ let(:different_error) do
+ [
+ {
+ code: "WCAG2AA.Principle1.Guideline1_4.1_4_3.G18.Fail",
+ type: "error",
+ typeCode: 1,
+ message: "This element has insufficient contrast at this conformance level.",
+ context: "<a href=\"/stages-devops-lifecycle/\" class=\"main-nav-link\">Product</a>",
+ selector: "#main-nav > divnth-child(2) > ul > linth-child(1) > a",
+ runner: "htmlcs",
+ runnerExtras: {}
+ }
+ ]
+ end
+
+ describe '#to_json' do
+ subject { serializer.as_json }
+
+ context 'when base report has error and head has a different error' do
+ before do
+ base_report.add_url(url, single_error)
+ head_report.add_url(url, different_error)
+ end
+
+ it 'matches the schema' do
+ expect(subject).to match_schema('entities/accessibility_reports_comparer')
+ end
+ end
+
+ context 'when base report has no error and head has errors' do
+ before do
+ head_report.add_url(url, single_error)
+ end
+
+ it 'matches the schema' do
+ expect(subject).to match_schema('entities/accessibility_reports_comparer')
+ end
+ end
+ end
+end
diff --git a/spec/serializers/ci/dag_job_entity_spec.rb b/spec/serializers/ci/dag_job_entity_spec.rb
new file mode 100644
index 00000000000..19b849c3879
--- /dev/null
+++ b/spec/serializers/ci/dag_job_entity_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Ci::DagJobEntity do
+ let_it_be(:request) { double(:request) }
+
+ let(:job) { create(:ci_build, name: 'dag_job') }
+ let(:entity) { described_class.new(job, request: request) }
+
+ describe '#as_json' do
+ subject { entity.as_json }
+
+ it 'contains the name' do
+ expect(subject[:name]).to eq 'dag_job'
+ end
+
+ context 'when job is stage scheduled' do
+ it 'does not expose needs' do
+ expect(subject).not_to include(:needs)
+ end
+ end
+
+ context 'when job is dag scheduled' do
+ context 'when job has needs' do
+ let(:job) { create(:ci_build, scheduling_type: 'dag') }
+ let!(:need) { create(:ci_build_need, build: job, name: 'compile') }
+
+ it 'exposes the array of needs' do
+ expect(subject[:needs]).to eq ['compile']
+ end
+ end
+
+ context 'when job has empty needs' do
+ let(:job) { create(:ci_build, scheduling_type: 'dag') }
+
+ it 'exposes an empty array of needs' do
+ expect(subject[:needs]).to eq []
+ end
+ end
+ end
+ end
+end
diff --git a/spec/serializers/ci/dag_job_group_entity_spec.rb b/spec/serializers/ci/dag_job_group_entity_spec.rb
new file mode 100644
index 00000000000..a25723894fd
--- /dev/null
+++ b/spec/serializers/ci/dag_job_group_entity_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Ci::DagJobGroupEntity do
+ let_it_be(:request) { double(:request) }
+ let_it_be(:pipeline) { create(:ci_pipeline) }
+ let_it_be(:stage) { create(:ci_stage, pipeline: pipeline) }
+
+ let(:group) { Ci::Group.new(pipeline.project, stage, name: 'test', jobs: jobs) }
+ let(:entity) { described_class.new(group, request: request) }
+
+ describe '#as_json' do
+ subject { entity.as_json }
+
+ context 'when group contains 1 job' do
+ let(:job) { create(:ci_build, stage: stage, pipeline: pipeline, name: 'test') }
+ let(:jobs) { [job] }
+
+ it 'exposes a name' do
+ expect(subject.fetch(:name)).to eq 'test'
+ end
+
+ it 'exposes the size' do
+ expect(subject.fetch(:size)).to eq 1
+ end
+
+ it 'exposes the jobs' do
+ exposed_jobs = subject.fetch(:jobs)
+
+ expect(exposed_jobs.size).to eq 1
+ expect(exposed_jobs.first.fetch(:name)).to eq 'test'
+ end
+ end
+
+ context 'when group contains multiple parallel jobs' do
+ let(:job_1) { create(:ci_build, stage: stage, pipeline: pipeline, name: 'test 1/2') }
+ let(:job_2) { create(:ci_build, stage: stage, pipeline: pipeline, name: 'test 2/2') }
+ let(:jobs) { [job_1, job_2] }
+
+ it 'exposes a name' do
+ expect(subject.fetch(:name)).to eq 'test'
+ end
+
+ it 'exposes the size' do
+ expect(subject.fetch(:size)).to eq 2
+ end
+
+ it 'exposes the jobs' do
+ exposed_jobs = subject.fetch(:jobs)
+
+ expect(exposed_jobs.size).to eq 2
+ expect(exposed_jobs.first.fetch(:name)).to eq 'test 1/2'
+ expect(exposed_jobs.last.fetch(:name)).to eq 'test 2/2'
+ end
+ end
+ end
+end
diff --git a/spec/serializers/ci/dag_pipeline_entity_spec.rb b/spec/serializers/ci/dag_pipeline_entity_spec.rb
new file mode 100644
index 00000000000..4645451e146
--- /dev/null
+++ b/spec/serializers/ci/dag_pipeline_entity_spec.rb
@@ -0,0 +1,112 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Ci::DagPipelineEntity do
+ let_it_be(:request) { double(:request) }
+
+ let(:pipeline) { create(:ci_pipeline) }
+ let(:entity) { described_class.new(pipeline, request: request) }
+
+ describe '#as_json' do
+ subject { entity.as_json }
+
+ context 'when pipeline is empty' do
+ it 'contains stages' do
+ expect(subject).to include(:stages)
+
+ expect(subject[:stages]).to be_empty
+ end
+ end
+
+ context 'when pipeline has jobs' do
+ let!(:build_job) { create(:ci_build, stage: 'build', pipeline: pipeline) }
+ let!(:test_job) { create(:ci_build, stage: 'test', pipeline: pipeline) }
+ let!(:deploy_job) { create(:ci_build, stage: 'deploy', pipeline: pipeline) }
+
+ it 'contains 3 stages' do
+ stages = subject[:stages]
+
+ expect(stages.size).to eq 3
+ expect(stages.map { |s| s[:name] }).to contain_exactly('build', 'test', 'deploy')
+ end
+ end
+
+ context 'when pipeline has parallel jobs and DAG needs' do
+ let!(:stage_build) { create(:ci_stage_entity, name: 'build', position: 1, pipeline: pipeline) }
+ let!(:stage_test) { create(:ci_stage_entity, name: 'test', position: 2, pipeline: pipeline) }
+ let!(:stage_deploy) { create(:ci_stage_entity, name: 'deploy', position: 3, pipeline: pipeline) }
+
+ let!(:job_build_1) { create(:ci_build, name: 'build 1', stage: 'build', pipeline: pipeline) }
+ let!(:job_build_2) { create(:ci_build, name: 'build 2', stage: 'build', pipeline: pipeline) }
+
+ let!(:job_rspec_1) { create(:ci_build, name: 'rspec 1/2', stage: 'test', pipeline: pipeline) }
+ let!(:job_rspec_2) { create(:ci_build, name: 'rspec 2/2', stage: 'test', pipeline: pipeline) }
+
+ let!(:job_jest) do
+ create(:ci_build, name: 'jest', stage: 'test', scheduling_type: 'dag', pipeline: pipeline).tap do |job|
+ create(:ci_build_need, name: 'build 1', build: job)
+ end
+ end
+
+ let!(:job_deploy_ruby) do
+ create(:ci_build, name: 'deploy_ruby', stage: 'deploy', scheduling_type: 'dag', pipeline: pipeline).tap do |job|
+ create(:ci_build_need, name: 'rspec 1/2', build: job)
+ create(:ci_build_need, name: 'rspec 2/2', build: job)
+ end
+ end
+
+ let!(:job_deploy_js) do
+ create(:ci_build, name: 'deploy_js', stage: 'deploy', scheduling_type: 'dag', pipeline: pipeline).tap do |job|
+ create(:ci_build_need, name: 'jest', build: job)
+ end
+ end
+
+ it 'performs the smallest number of queries' do
+ log = ActiveRecord::QueryRecorder.new { subject }
+
+ # stages, project, builds, build_needs
+ expect(log.count).to eq 4
+ end
+
+ it 'contains all the data' do
+ expected_result = {
+ stages: [
+ {
+ name: 'build',
+ groups: [
+ { name: 'build 1', size: 1, jobs: [{ name: 'build 1' }] },
+ { name: 'build 2', size: 1, jobs: [{ name: 'build 2' }] }
+ ]
+ },
+ {
+ name: 'test',
+ groups: [
+ { name: 'jest', size: 1, jobs: [{ name: 'jest', needs: ['build 1'] }] },
+ { name: 'rspec', size: 2, jobs: [{ name: 'rspec 1/2' }, { name: 'rspec 2/2' }] }
+ ]
+ },
+ {
+ name: 'deploy',
+ groups: [
+ { name: 'deploy_js', size: 1, jobs: [{ name: 'deploy_js', needs: ['jest'] }] },
+ { name: 'deploy_ruby', size: 1, jobs: [{ name: 'deploy_ruby', needs: ['rspec 1/2', 'rspec 2/2'] }] }
+ ]
+ }
+ ]
+ }
+
+ expect(subject.fetch(:stages)).not_to be_empty
+
+ expect(subject.fetch(:stages)[0].fetch(:name)).to eq 'build'
+ expect(subject.fetch(:stages)[0]).to eq expected_result.fetch(:stages)[0]
+
+ expect(subject.fetch(:stages)[1].fetch(:name)).to eq 'test'
+ expect(subject.fetch(:stages)[1]).to eq expected_result.fetch(:stages)[1]
+
+ expect(subject.fetch(:stages)[2].fetch(:name)).to eq 'deploy'
+ expect(subject.fetch(:stages)[2]).to eq expected_result.fetch(:stages)[2]
+ end
+ end
+ end
+end
diff --git a/spec/serializers/ci/dag_pipeline_serializer_spec.rb b/spec/serializers/ci/dag_pipeline_serializer_spec.rb
new file mode 100644
index 00000000000..abf895c3e77
--- /dev/null
+++ b/spec/serializers/ci/dag_pipeline_serializer_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Ci::DagPipelineSerializer do
+ describe '#represent' do
+ subject { described_class.new.represent(pipeline) }
+
+ let(:pipeline) { create(:ci_pipeline) }
+ let!(:job) { create(:ci_build, pipeline: pipeline) }
+
+ it 'includes stages' do
+ expect(subject[:stages]).to be_present
+ expect(subject[:stages].size).to eq 1
+ end
+ end
+end
diff --git a/spec/serializers/ci/dag_stage_entity_spec.rb b/spec/serializers/ci/dag_stage_entity_spec.rb
new file mode 100644
index 00000000000..5c6aa7faee4
--- /dev/null
+++ b/spec/serializers/ci/dag_stage_entity_spec.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Ci::DagStageEntity do
+ let_it_be(:pipeline) { create(:ci_pipeline) }
+ let_it_be(:request) { double(:request) }
+
+ let(:stage) { build(:ci_stage, pipeline: pipeline, name: 'test') }
+ let(:entity) { described_class.new(stage, request: request) }
+
+ let!(:job) { create(:ci_build, :success, pipeline: pipeline) }
+
+ describe '#as_json' do
+ subject { entity.as_json }
+
+ it 'contains valid name' do
+ expect(subject[:name]).to eq 'test'
+ end
+
+ it 'contains the job groups' do
+ expect(subject).to include :groups
+ expect(subject[:groups]).not_to be_empty
+
+ job_group = subject[:groups].first
+ expect(job_group[:name]).to eq 'test'
+ expect(job_group[:size]).to eq 1
+ expect(job_group[:jobs]).not_to be_empty
+ end
+ end
+end
diff --git a/spec/serializers/cluster_application_entity_spec.rb b/spec/serializers/cluster_application_entity_spec.rb
index 873fbf812cc..b81bdaa0d72 100644
--- a/spec/serializers/cluster_application_entity_spec.rb
+++ b/spec/serializers/cluster_application_entity_spec.rb
@@ -77,5 +77,17 @@ describe ClusterApplicationEntity do
expect(subject[:pages_domain]).to eq(id: pages_domain.id, domain: pages_domain.domain)
end
end
+
+ context 'for fluentd application' do
+ let(:application) { build(:clusters_applications_fluentd, :installed) }
+
+ it 'includes host, port, protocol and log fields' do
+ expect(subject[:port]).to eq(514)
+ expect(subject[:host]).to eq("example.com")
+ expect(subject[:protocol]).to eq("tcp")
+ expect(subject[:waf_log_enabled]).to be true
+ expect(subject[:cilium_log_enabled]).to be true
+ end
+ end
end
end
diff --git a/spec/serializers/cluster_entity_spec.rb b/spec/serializers/cluster_entity_spec.rb
index e3826a7221d..16247eef655 100644
--- a/spec/serializers/cluster_entity_spec.rb
+++ b/spec/serializers/cluster_entity_spec.rb
@@ -7,7 +7,7 @@ describe ClusterEntity do
subject { described_class.new(cluster).as_json }
context 'when provider type is gcp' do
- let(:cluster) { create(:cluster, provider_type: :gcp, provider_gcp: provider) }
+ let(:cluster) { create(:cluster, :instance, provider_type: :gcp, provider_gcp: provider) }
context 'when status is creating' do
let(:provider) { create(:cluster_provider_gcp, :creating) }
@@ -29,7 +29,7 @@ describe ClusterEntity do
end
context 'when provider type is user' do
- let(:cluster) { create(:cluster, provider_type: :user) }
+ let(:cluster) { create(:cluster, :instance, provider_type: :user) }
it 'has corresponded data' do
expect(subject[:status]).to eq(:created)
@@ -38,7 +38,7 @@ describe ClusterEntity do
end
context 'when no application has been installed' do
- let(:cluster) { create(:cluster) }
+ let(:cluster) { create(:cluster, :instance) }
subject { described_class.new(cluster).as_json[:applications]}
diff --git a/spec/serializers/cluster_serializer_spec.rb b/spec/serializers/cluster_serializer_spec.rb
index db0e65ca0fa..39551649ff0 100644
--- a/spec/serializers/cluster_serializer_spec.rb
+++ b/spec/serializers/cluster_serializer_spec.rb
@@ -3,23 +3,41 @@
require 'spec_helper'
describe ClusterSerializer do
+ let(:cluster) { create(:cluster, :project, provider_type: :user) }
+
+ describe '#represent_list' do
+ subject { described_class.new.represent_list(cluster).keys }
+
+ it 'serializes attrs correctly' do
+ is_expected.to contain_exactly(
+ :cluster_type,
+ :enabled,
+ :environment_scope,
+ :name,
+ :nodes,
+ :path,
+ :status)
+ end
+ end
+
describe '#represent_status' do
- subject { described_class.new.represent_status(cluster) }
+ subject { described_class.new.represent_status(cluster).keys }
+
+ context 'when provider type is gcp and cluster is errored' do
+ let(:cluster) do
+ errored_provider = create(:cluster_provider_gcp, :errored)
- context 'when provider type is gcp' do
- let(:cluster) { create(:cluster, provider_type: :gcp, provider_gcp: provider) }
- let(:provider) { create(:cluster_provider_gcp, :errored) }
+ create(:cluster, provider_type: :gcp, provider_gcp: errored_provider)
+ end
- it 'serializes only status' do
- expect(subject.keys).to contain_exactly(:status, :status_reason, :applications)
+ it 'serializes attrs correctly' do
+ is_expected.to contain_exactly(:status, :status_reason, :applications)
end
end
context 'when provider type is user' do
- let(:cluster) { create(:cluster, provider_type: :user) }
-
- it 'serializes only status' do
- expect(subject.keys).to contain_exactly(:status, :status_reason, :applications)
+ it 'serializes attrs correctly' do
+ is_expected.to contain_exactly(:status, :status_reason, :applications)
end
end
end
diff --git a/spec/serializers/diff_file_base_entity_spec.rb b/spec/serializers/diff_file_base_entity_spec.rb
index 80f5bc8f159..1fd697970de 100644
--- a/spec/serializers/diff_file_base_entity_spec.rb
+++ b/spec/serializers/diff_file_base_entity_spec.rb
@@ -34,4 +34,62 @@ describe DiffFileBaseEntity do
expect(entity[:new_size]).to eq(132)
end
end
+
+ context 'edit_path' do
+ let(:diff_file) { merge_request.diffs.diff_files.to_a.last }
+ let(:options) { { request: EntityRequest.new(current_user: create(:user)), merge_request: merge_request } }
+ let(:params) { {} }
+
+ before do
+ stub_feature_flags(web_ide_default: false)
+ end
+
+ shared_examples 'a diff file edit path to the source branch' do
+ it do
+ expect(entity[:edit_path]).to eq(Gitlab::Routing.url_helpers.project_edit_blob_path(project, File.join(merge_request.source_branch, diff_file.new_path), params))
+ end
+ end
+
+ context 'open' do
+ let(:merge_request) { create(:merge_request, source_project: project, target_branch: 'master', source_branch: 'feature') }
+ let(:params) { { from_merge_request_iid: merge_request.iid } }
+
+ it_behaves_like 'a diff file edit path to the source branch'
+
+ context 'removed source branch' do
+ before do
+ allow(merge_request).to receive(:source_branch_exists?).and_return(false)
+ end
+
+ it do
+ expect(entity[:edit_path]).to eq(nil)
+ end
+ end
+ end
+
+ context 'closed' do
+ let(:merge_request) { create(:merge_request, source_project: project, state: :closed, target_branch: 'master', source_branch: 'feature') }
+ let(:params) { { from_merge_request_iid: merge_request.iid } }
+
+ it_behaves_like 'a diff file edit path to the source branch'
+
+ context 'removed source branch' do
+ before do
+ allow(merge_request).to receive(:source_branch_exists?).and_return(false)
+ end
+
+ it do
+ expect(entity[:edit_path]).to eq(nil)
+ end
+ end
+ end
+
+ context 'merged' do
+ let(:merge_request) { create(:merge_request, source_project: project, state: :merged) }
+
+ it do
+ expect(entity[:edit_path]).to eq(Gitlab::Routing.url_helpers.project_edit_blob_path(project, File.join(merge_request.target_branch, diff_file.new_path), {}))
+ end
+ end
+ end
end
diff --git a/spec/serializers/diffs_metadata_entity_spec.rb b/spec/serializers/diffs_metadata_entity_spec.rb
index a6bf9a7700e..3ed2b7c9452 100644
--- a/spec/serializers/diffs_metadata_entity_spec.rb
+++ b/spec/serializers/diffs_metadata_entity_spec.rb
@@ -29,7 +29,7 @@ describe DiffsMetadataEntity do
:added_lines, :removed_lines, :render_overflow_warning,
:email_patch_path, :plain_diff_path,
:merge_request_diffs, :context_commits,
- :definition_path_prefix,
+ :definition_path_prefix, :source_branch_exists,
# Attributes
:diff_files
)
diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb
index b4ea90d2141..36e971c467a 100644
--- a/spec/serializers/environment_entity_spec.rb
+++ b/spec/serializers/environment_entity_spec.rb
@@ -10,7 +10,13 @@ describe EnvironmentEntity do
described_class.new(environment, request: spy('request'))
end
- let(:environment) { create(:environment) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:environment) { create(:environment, project: project) }
+
+ before do
+ allow(entity).to receive(:current_user).and_return(user)
+ end
subject { entity.as_json }
@@ -67,28 +73,48 @@ describe EnvironmentEntity do
end
context 'with auto_stop_in' do
- let(:environment) { create(:environment, :will_auto_stop) }
+ let(:environment) { create(:environment, :will_auto_stop, project: project) }
it 'exposes auto stop related information' do
+ project.add_maintainer(user)
+
expect(subject).to include(:cancel_auto_stop_path, :auto_stop_at)
end
end
context 'pod_logs' do
- it 'exposes logs keys' do
- expect(subject).to include(:logs_path)
- expect(subject).to include(:logs_api_path)
- expect(subject).to include(:enable_advanced_logs_querying)
- end
+ context 'with developer access' do
+ before do
+ project.add_developer(user)
+ end
- it 'uses k8s api when ES is not available' do
- expect(subject[:logs_api_path]).to eq(k8s_project_logs_path(environment.project, environment_name: environment.name, format: :json))
+ it 'does not expose logs keys' do
+ expect(subject).not_to include(:logs_path)
+ expect(subject).not_to include(:logs_api_path)
+ expect(subject).not_to include(:enable_advanced_logs_querying)
+ end
end
- it 'uses ES api when ES is available' do
- allow(environment).to receive(:elastic_stack_available?).and_return(true)
+ context 'with maintainer access' do
+ before do
+ project.add_maintainer(user)
+ end
+
+ it 'exposes logs keys' do
+ expect(subject).to include(:logs_path)
+ expect(subject).to include(:logs_api_path)
+ expect(subject).to include(:enable_advanced_logs_querying)
+ end
- expect(subject[:logs_api_path]).to eq(elasticsearch_project_logs_path(environment.project, environment_name: environment.name, format: :json))
+ it 'uses k8s api when ES is not available' do
+ expect(subject[:logs_api_path]).to eq(k8s_project_logs_path(project, environment_name: environment.name, format: :json))
+ end
+
+ it 'uses ES api when ES is available' do
+ allow(environment).to receive(:elastic_stack_available?).and_return(true)
+
+ expect(subject[:logs_api_path]).to eq(elasticsearch_project_logs_path(project, environment_name: environment.name, format: :json))
+ 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 fe0b717ede0..4b3bfc99c88 100644
--- a/spec/serializers/merge_request_poll_widget_entity_spec.rb
+++ b/spec/serializers/merge_request_poll_widget_entity_spec.rb
@@ -71,6 +71,50 @@ describe MergeRequestPollWidgetEntity do
end
end
+ describe 'terraform_reports_path' do
+ context 'when merge request has terraform reports' do
+ before do
+ allow(resource).to receive(:has_terraform_reports?).and_return(true)
+ end
+
+ it 'set the path to poll data' do
+ expect(subject[:terraform_reports_path]).to be_present
+ end
+ end
+
+ context 'when merge request has no terraform reports' do
+ before do
+ allow(resource).to receive(:has_terraform_reports?).and_return(false)
+ end
+
+ it 'set the path to poll data' do
+ expect(subject[:terraform_reports_path]).to be_nil
+ end
+ end
+ end
+
+ describe 'accessibility_report_path' do
+ context 'when merge request has accessibility reports' do
+ before do
+ allow(resource).to receive(:has_accessibility_reports?).and_return(true)
+ end
+
+ it 'set the path to poll data' do
+ expect(subject[:accessibility_report_path]).to be_present
+ end
+ end
+
+ context 'when merge request has no accessibility reports' do
+ before do
+ allow(resource).to receive(:has_accessibility_reports?).and_return(false)
+ end
+
+ it 'set the path to poll data' do
+ expect(subject[:accessibility_report_path]).to be_nil
+ end
+ end
+ end
+
describe 'exposed_artifacts_path' do
context 'when merge request has exposed artifacts' do
before do
diff --git a/spec/serializers/merge_request_sidebar_basic_entity_spec.rb b/spec/serializers/merge_request_sidebar_basic_entity_spec.rb
index b364b1a3306..b2db57801ea 100644
--- a/spec/serializers/merge_request_sidebar_basic_entity_spec.rb
+++ b/spec/serializers/merge_request_sidebar_basic_entity_spec.rb
@@ -13,7 +13,7 @@ describe MergeRequestSidebarBasicEntity do
describe '#current_user' do
it 'contains attributes related to the current user' do
- expect(entity[:current_user].keys).to contain_exactly(
+ expect(entity[:current_user].keys).to include(
:id, :name, :username, :state, :avatar_url, :web_url, :todo,
:can_edit, :can_move, :can_admin_label, :can_merge
)
diff --git a/spec/serializers/service_event_entity_spec.rb b/spec/serializers/service_event_entity_spec.rb
new file mode 100644
index 00000000000..fc11263807b
--- /dev/null
+++ b/spec/serializers/service_event_entity_spec.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe ServiceEventEntity do
+ let(:request) { double('request') }
+
+ subject { described_class.new(event, request: request, service: service).as_json }
+
+ before do
+ allow(request).to receive(:service).and_return(service)
+ end
+
+ describe '#as_json' do
+ context 'service without fields' do
+ let(:service) { create(:emails_on_push_service, push_events: true) }
+ let(:event) { 'push' }
+
+ it 'exposes correct attributes' do
+ expect(subject[:description]).to eq('Event will be triggered by a push to the repository')
+ expect(subject[:name]).to eq('push_events')
+ expect(subject[:title]).to eq('push')
+ expect(subject[:value]).to be(true)
+ end
+ end
+
+ context 'service with fields' do
+ let(:service) { create(:slack_service, note_events: false, note_channel: 'note-channel') }
+ let(:event) { 'note' }
+
+ it 'exposes correct attributes' do
+ expect(subject[:description]).to eq('Event will be triggered when someone adds a comment')
+ expect(subject[:name]).to eq('note_events')
+ expect(subject[:title]).to eq('note')
+ expect(subject[:value]).to eq(false)
+ expect(subject[:field][:name]).to eq('note_channel')
+ expect(subject[:field][:value]).to eq('note-channel')
+ end
+ end
+ end
+end
diff --git a/spec/serializers/test_case_entity_spec.rb b/spec/serializers/test_case_entity_spec.rb
index f16c271be4d..9f1822ff581 100644
--- a/spec/serializers/test_case_entity_spec.rb
+++ b/spec/serializers/test_case_entity_spec.rb
@@ -38,7 +38,7 @@ describe TestCaseEntity do
end
context 'when attachment is present' do
- let(:test_case) { build(:test_case, :with_attachment) }
+ let(:test_case) { build(:test_case, :failed_with_attachment) }
it 'returns the attachment_url' do
expect(subject).to include(:attachment_url)
@@ -60,7 +60,7 @@ describe TestCaseEntity do
end
context 'when attachment is present' do
- let(:test_case) { build(:test_case, :with_attachment) }
+ let(:test_case) { build(:test_case, :failed_with_attachment) }
it 'returns no attachment_url' do
expect(subject).not_to include(:attachment_url)
diff --git a/spec/serializers/test_suite_entity_spec.rb b/spec/serializers/test_suite_entity_spec.rb
index 6a9653954f3..bd88d235013 100644
--- a/spec/serializers/test_suite_entity_spec.rb
+++ b/spec/serializers/test_suite_entity_spec.rb
@@ -3,27 +3,65 @@
require 'spec_helper'
describe TestSuiteEntity do
- let(:pipeline) { create(:ci_pipeline, :with_test_reports) }
- let(:entity) { described_class.new(pipeline.test_reports.test_suites.each_value.first) }
+ let(:pipeline) { create(:ci_pipeline, :with_test_reports) }
+ let(:test_suite) { pipeline.test_reports.test_suites.each_value.first }
+ let(:entity) { described_class.new(test_suite) }
describe '#as_json' do
subject(:as_json) { entity.as_json }
it 'contains the suite name' do
- expect(as_json).to include(:name)
+ expect(as_json[:name]).to be_present
end
it 'contains the total time' do
- expect(as_json).to include(:total_time)
+ expect(as_json[:total_time]).to be_present
end
it 'contains the counts' do
- expect(as_json).to include(:total_count, :success_count, :failed_count, :skipped_count, :error_count)
+ expect(as_json[:total_count]).to eq(4)
+ expect(as_json[:success_count]).to eq(2)
+ expect(as_json[:failed_count]).to eq(2)
+ expect(as_json[:skipped_count]).to eq(0)
+ expect(as_json[:error_count]).to eq(0)
end
it 'contains the test cases' do
- expect(as_json).to include(:test_cases)
expect(as_json[:test_cases].count).to eq(4)
end
+
+ it 'contains an empty error message' do
+ expect(as_json[:suite_error]).to be_nil
+ end
+
+ context 'with a suite error' do
+ before do
+ test_suite.set_suite_error('a really bad error')
+ end
+
+ it 'contains the suite name' do
+ expect(as_json[:name]).to be_present
+ end
+
+ it 'contains the total time' do
+ expect(as_json[:total_time]).to be_present
+ end
+
+ it 'returns all the counts as 0' do
+ expect(as_json[:total_count]).to eq(0)
+ expect(as_json[:success_count]).to eq(0)
+ expect(as_json[:failed_count]).to eq(0)
+ expect(as_json[:skipped_count]).to eq(0)
+ expect(as_json[:error_count]).to eq(0)
+ end
+
+ it 'returns no test cases' do
+ expect(as_json[:test_cases]).to be_empty
+ end
+
+ it 'returns a suite error' do
+ expect(as_json[:suite_error]).to eq('a really bad error')
+ end
+ end
end
end