summaryrefslogtreecommitdiff
path: root/spec/serializers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/serializers
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
downloadgitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/build_artifact_entity_spec.rb9
-rw-r--r--spec/serializers/ci/dag_job_entity_spec.rb13
-rw-r--r--spec/serializers/ci/dag_pipeline_entity_spec.rb49
-rw-r--r--spec/serializers/ci/daily_build_group_report_result_entity_spec.rb26
-rw-r--r--spec/serializers/ci/daily_build_group_report_result_serializer_spec.rb38
-rw-r--r--spec/serializers/cluster_serializer_spec.rb1
-rw-r--r--spec/serializers/commit_entity_spec.rb6
-rw-r--r--spec/serializers/container_repository_entity_spec.rb4
-rw-r--r--spec/serializers/diffs_entity_spec.rb10
-rw-r--r--spec/serializers/evidences/evidence_entity_spec.rb60
-rw-r--r--spec/serializers/import/bitbucket_provider_repo_entity_spec.rb34
-rw-r--r--spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb36
-rw-r--r--spec/serializers/import/fogbugz_provider_repo_entity_spec.rb27
-rw-r--r--spec/serializers/import/githubish_provider_repo_entity_spec.rb27
-rw-r--r--spec/serializers/import/gitlab_provider_repo_entity_spec.rb27
-rw-r--r--spec/serializers/import/provider_repo_serializer_spec.rb29
-rw-r--r--spec/serializers/merge_request_widget_entity_spec.rb2
-rw-r--r--spec/serializers/paginated_diff_entity_spec.rb10
-rw-r--r--spec/serializers/pipeline_details_entity_spec.rb39
-rw-r--r--spec/serializers/pipeline_serializer_spec.rb4
-rw-r--r--spec/serializers/provider_repo_entity_spec.rb24
-rw-r--r--spec/serializers/provider_repo_serializer_spec.rb9
-rw-r--r--spec/serializers/service_field_entity_spec.rb99
-rw-r--r--spec/serializers/web_ide_terminal_entity_spec.rb27
-rw-r--r--spec/serializers/web_ide_terminal_serializer_spec.rb27
25 files changed, 537 insertions, 100 deletions
diff --git a/spec/serializers/build_artifact_entity_spec.rb b/spec/serializers/build_artifact_entity_spec.rb
index c8995cbc5a2..afa2aa3d254 100644
--- a/spec/serializers/build_artifact_entity_spec.rb
+++ b/spec/serializers/build_artifact_entity_spec.rb
@@ -3,17 +3,18 @@
require 'spec_helper'
describe BuildArtifactEntity do
- let(:job) { create(:ci_build, :artifacts, name: 'test:job', artifacts_expire_at: 1.hour.from_now) }
+ let(:job) { create(:ci_build) }
+ let(:artifact) { create(:ci_job_artifact, :codequality, expire_at: 1.hour.from_now, job: job) }
let(:entity) do
- described_class.new(job, request: double)
+ described_class.new(artifact, request: double)
end
describe '#as_json' do
subject { entity.as_json }
it 'contains job name' do
- expect(subject[:name]).to eq 'test:job'
+ expect(subject[:name]).to eq "test:codequality"
end
it 'exposes information about expiration of artifacts' do
@@ -22,7 +23,7 @@ describe BuildArtifactEntity do
it 'contains paths to the artifacts' do
expect(subject[:path])
- .to include "jobs/#{job.id}/artifacts/download"
+ .to include "jobs/#{job.id}/artifacts/download?file_type=codequality"
expect(subject[:keep_path])
.to include "jobs/#{job.id}/artifacts/keep"
diff --git a/spec/serializers/ci/dag_job_entity_spec.rb b/spec/serializers/ci/dag_job_entity_spec.rb
index 19b849c3879..eaaf39d6bfc 100644
--- a/spec/serializers/ci/dag_job_entity_spec.rb
+++ b/spec/serializers/ci/dag_job_entity_spec.rb
@@ -16,14 +16,23 @@ describe Ci::DagJobEntity do
end
context 'when job is stage scheduled' do
+ it 'contains the name scheduling_type' do
+ expect(subject[:scheduling_type]).to eq 'stage'
+ end
+
it 'does not expose needs' do
expect(subject).not_to include(:needs)
end
end
context 'when job is dag scheduled' do
+ let(:job) { create(:ci_build, scheduling_type: 'dag') }
+
+ it 'contains the name scheduling_type' do
+ expect(subject[:scheduling_type]).to eq 'dag'
+ end
+
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
@@ -32,8 +41,6 @@ describe Ci::DagJobEntity do
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
diff --git a/spec/serializers/ci/dag_pipeline_entity_spec.rb b/spec/serializers/ci/dag_pipeline_entity_spec.rb
index 4645451e146..fab8798effc 100644
--- a/spec/serializers/ci/dag_pipeline_entity_spec.rb
+++ b/spec/serializers/ci/dag_pipeline_entity_spec.rb
@@ -32,13 +32,14 @@ describe Ci::DagPipelineEntity do
end
end
- context 'when pipeline has parallel jobs and DAG needs' do
+ context 'when pipeline has parallel jobs, DAG needs and GenericCommitStatus' 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_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!(:commit_status) { create(:generic_commit_status, 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) }
@@ -75,22 +76,52 @@ describe Ci::DagPipelineEntity do
{
name: 'build',
groups: [
- { name: 'build 1', size: 1, jobs: [{ name: 'build 1' }] },
- { name: 'build 2', size: 1, jobs: [{ name: 'build 2' }] }
+ {
+ name: 'build 1', size: 1, jobs: [
+ { name: 'build 1', scheduling_type: 'stage' }
+ ]
+ },
+ {
+ name: 'build 2', size: 1, jobs: [
+ { name: 'build 2', scheduling_type: 'stage' }
+ ]
+ },
+ {
+ name: 'generic', size: 1, jobs: [
+ { name: 'generic', scheduling_type: nil }
+ ]
+ }
]
},
{
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: 'jest', size: 1, jobs: [
+ { name: 'jest', scheduling_type: 'dag', needs: ['build 1'] }
+ ]
+ },
+ {
+ name: 'rspec', size: 2, jobs: [
+ { name: 'rspec 1/2', scheduling_type: 'stage' },
+ { name: 'rspec 2/2', scheduling_type: 'stage' }
+ ]
+ }
]
},
{
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'] }] }
+ {
+ name: 'deploy_js', size: 1, jobs: [
+ { name: 'deploy_js', scheduling_type: 'dag', needs: ['jest'] }
+ ]
+ },
+ {
+ name: 'deploy_ruby', size: 1, jobs: [
+ { name: 'deploy_ruby', scheduling_type: 'dag', needs: ['rspec 1/2', 'rspec 2/2'] }
+ ]
+ }
]
}
]
diff --git a/spec/serializers/ci/daily_build_group_report_result_entity_spec.rb b/spec/serializers/ci/daily_build_group_report_result_entity_spec.rb
new file mode 100644
index 00000000000..cc35b3bc8b8
--- /dev/null
+++ b/spec/serializers/ci/daily_build_group_report_result_entity_spec.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Ci::DailyBuildGroupReportResultEntity do
+ let(:report_result) { double(date: '2020-05-20', group_name: 'rspec', data: { 'coverage' => 79.1 }) }
+ let(:entity) { described_class.new(report_result, param_type: param_type) }
+ let(:param_type) { 'coverage' }
+
+ describe '#as_json' do
+ subject { entity.as_json }
+
+ it { is_expected.to include(:date) }
+
+ it { is_expected.not_to include(:group_name) }
+
+ it { is_expected.to include(:coverage) }
+
+ context 'when given param_type is not allowed' do
+ let(:param_type) { 'something_else' }
+
+ it { is_expected.not_to include(:coverage) }
+ it { is_expected.not_to include(:something_else) }
+ end
+ end
+end
diff --git a/spec/serializers/ci/daily_build_group_report_result_serializer_spec.rb b/spec/serializers/ci/daily_build_group_report_result_serializer_spec.rb
new file mode 100644
index 00000000000..4a781971ae0
--- /dev/null
+++ b/spec/serializers/ci/daily_build_group_report_result_serializer_spec.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Ci::DailyBuildGroupReportResultSerializer do
+ let(:report_result) do
+ [
+ double(date: '2020-05-20', group_name: 'rspec', data: { 'coverage' => 79.1 }),
+ double(date: '2020-05-20', group_name: 'karma', data: { 'coverage' => 90.1 }),
+ double(date: '2020-05-19', group_name: 'rspec', data: { 'coverage' => 77.1 }),
+ double(date: '2020-05-19', group_name: 'karma', data: { 'coverage' => 89.1 })
+ ]
+ end
+ let(:serializer) { described_class.new.represent(report_result, param_type: 'coverage') }
+
+ describe '#to_json' do
+ let(:json) { Gitlab::Json.parse(serializer.to_json) }
+
+ it 'returns an array of group results' do
+ expect(json).to eq([
+ {
+ 'group_name' => 'rspec',
+ 'data' => [
+ { 'date' => '2020-05-20', 'coverage' => 79.1 },
+ { 'date' => '2020-05-19', 'coverage' => 77.1 }
+ ]
+ },
+ {
+ 'group_name' => 'karma',
+ 'data' => [
+ { 'date' => '2020-05-20', 'coverage' => 90.1 },
+ { 'date' => '2020-05-19', 'coverage' => 89.1 }
+ ]
+ }
+ ])
+ end
+ end
+end
diff --git a/spec/serializers/cluster_serializer_spec.rb b/spec/serializers/cluster_serializer_spec.rb
index 39551649ff0..b7d7307d40b 100644
--- a/spec/serializers/cluster_serializer_spec.rb
+++ b/spec/serializers/cluster_serializer_spec.rb
@@ -16,6 +16,7 @@ describe ClusterSerializer do
:name,
:nodes,
:path,
+ :provider_type,
:status)
end
end
diff --git a/spec/serializers/commit_entity_spec.rb b/spec/serializers/commit_entity_spec.rb
index 03e1c89a5e6..6abe8504b93 100644
--- a/spec/serializers/commit_entity_spec.rb
+++ b/spec/serializers/commit_entity_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
describe CommitEntity do
- SIGNATURE_HTML = 'TEST'.freeze
+ let(:signature_html) { 'TEST' }
let(:entity) do
described_class.new(commit, request: request)
@@ -16,7 +16,7 @@ describe CommitEntity do
before do
render = double('render')
- allow(render).to receive(:call).and_return(SIGNATURE_HTML)
+ allow(render).to receive(:call).and_return(signature_html)
allow(request).to receive(:project).and_return(project)
allow(request).to receive(:render).and_return(render)
@@ -83,7 +83,7 @@ describe CommitEntity do
it 'exposes "signature_html"' do
expect(request.render).to receive(:call)
- expect(subject.fetch(:signature_html)).to be SIGNATURE_HTML
+ expect(subject.fetch(:signature_html)).to be signature_html
end
end
diff --git a/spec/serializers/container_repository_entity_spec.rb b/spec/serializers/container_repository_entity_spec.rb
index 96c80331f41..1f85c6e6a46 100644
--- a/spec/serializers/container_repository_entity_spec.rb
+++ b/spec/serializers/container_repository_entity_spec.rb
@@ -13,12 +13,14 @@ describe ContainerRepositoryEntity do
before do
stub_container_registry_config(enabled: true)
+ stub_container_registry_tags(repository: :any,
+ tags: %w[stable latest])
allow(request).to receive(:project).and_return(project)
allow(request).to receive(:current_user).and_return(user)
end
it 'exposes required informations' do
- expect(subject).to include(:id, :path, :location, :tags_path)
+ expect(subject).to include(:id, :path, :location, :tags_path, :tags_count)
end
context 'when project is not preset in the request' do
diff --git a/spec/serializers/diffs_entity_spec.rb b/spec/serializers/diffs_entity_spec.rb
index 482f9e76c62..435d8a6aff2 100644
--- a/spec/serializers/diffs_entity_spec.rb
+++ b/spec/serializers/diffs_entity_spec.rb
@@ -68,5 +68,15 @@ describe DiffsEntity do
end
end
end
+
+ context 'when code_navigation feature flag is disabled' do
+ it 'does not include code navigation properties' do
+ stub_feature_flags(code_navigation: false)
+
+ expect(Gitlab::CodeNavigationPath).not_to receive(:new)
+
+ expect(subject).not_to include(:definition_path_prefix)
+ end
+ end
end
end
diff --git a/spec/serializers/evidences/evidence_entity_spec.rb b/spec/serializers/evidences/evidence_entity_spec.rb
index 531708e3be6..fa13bd21edd 100644
--- a/spec/serializers/evidences/evidence_entity_spec.rb
+++ b/spec/serializers/evidences/evidence_entity_spec.rb
@@ -3,12 +3,66 @@
require 'spec_helper'
describe Evidences::EvidenceEntity do
- let(:evidence) { build(:evidence) }
- let(:entity) { described_class.new(evidence) }
+ let_it_be(:project) { create(:project) }
+ let(:release) { create(:release, project: project) }
+ let(:evidence) { build(:evidence, release: release) }
+ let(:schema_file) { 'evidences/evidence' }
- subject { entity.as_json }
+ subject { described_class.new(evidence).as_json }
it 'exposes the expected fields' do
expect(subject.keys).to contain_exactly(:release)
end
+
+ context 'when a release is associated to a milestone' do
+ let(:milestone) { create(:milestone, project: project) }
+ let(:release) { create(:release, project: project, milestones: [milestone]) }
+
+ context 'when a milestone has no issue associated with it' do
+ it 'creates a valid JSON object' do
+ expect(subject[:release][:milestones].first[:issues]).to be_empty
+ expect(subject.to_json).to match_schema(schema_file)
+ end
+ end
+
+ context 'when a milestone has no description' do
+ let(:milestone) { create(:milestone, project: project, description: nil) }
+
+ it 'creates a valid JSON object' do
+ expect(subject[:release][:milestones].first[:description]).to be_nil
+ expect(subject.to_json).to match_schema(schema_file)
+ end
+ end
+
+ context 'when a milestone has no due_date' do
+ let(:milestone) { create(:milestone, project: project, due_date: nil) }
+
+ it 'creates a valid JSON object' do
+ expect(subject[:release][:milestones].first[:due_date]).to be_nil
+ expect(subject.to_json).to match_schema(schema_file)
+ end
+ end
+
+ context 'when a milestone has an issue' do
+ context 'when the issue has no description' do
+ let(:issue) { create(:issue, project: project, description: nil, state: 'closed') }
+
+ before do
+ milestone.issues << issue
+ end
+
+ it 'creates a valid JSON object' do
+ expect(subject[:release][:milestones].first[:issues].first[:title]).to be_present
+ expect(subject.to_json).to match_schema(schema_file)
+ end
+ end
+ end
+ end
+
+ context 'when a release is not associated to any milestone' do
+ it 'creates a valid JSON object' do
+ expect(subject[:release][:milestones]).to be_empty
+ expect(subject.to_json).to match_schema(schema_file)
+ end
+ end
end
diff --git a/spec/serializers/import/bitbucket_provider_repo_entity_spec.rb b/spec/serializers/import/bitbucket_provider_repo_entity_spec.rb
new file mode 100644
index 00000000000..ed3ef26db65
--- /dev/null
+++ b/spec/serializers/import/bitbucket_provider_repo_entity_spec.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Import::BitbucketProviderRepoEntity do
+ let(:repo_data) do
+ {
+ 'name' => 'repo_name',
+ 'full_name' => 'owner/repo_name',
+ 'links' => {
+ 'clone' => [
+ {
+ 'href' => 'https://bitbucket.org/owner/repo_name',
+ 'name' => 'https'
+ }
+ ]
+ }
+ }
+ end
+ let(:repo) { Bitbucket::Representation::Repo.new(repo_data) }
+
+ subject { described_class.new(repo).as_json }
+
+ it_behaves_like 'exposes required fields for import entity' do
+ let(:expected_values) do
+ {
+ id: 'owner/repo_name',
+ full_name: 'owner/repo_name',
+ sanitized_name: 'repo_name',
+ provider_link: 'https://bitbucket.org/owner/repo_name'
+ }
+ end
+ end
+end
diff --git a/spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb b/spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb
new file mode 100644
index 00000000000..9891809cc67
--- /dev/null
+++ b/spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Import::BitbucketServerProviderRepoEntity do
+ let(:repo_data) do
+ {
+ 'name' => 'test',
+ 'project' => {
+ 'name' => 'demo'
+ },
+ 'links' => {
+ 'self' => [
+ {
+ 'href' => 'http://local.bitbucket.server/demo/test.git',
+ 'name' => 'http'
+ }
+ ]
+ }
+ }
+ end
+ let(:repo) { BitbucketServer::Representation::Repo.new(repo_data) }
+
+ subject { described_class.new(repo).as_json }
+
+ it_behaves_like 'exposes required fields for import entity' do
+ let(:expected_values) do
+ {
+ id: 'demo/test',
+ full_name: 'demo/test',
+ sanitized_name: 'test',
+ provider_link: 'http://local.bitbucket.server/demo/test.git'
+ }
+ end
+ end
+end
diff --git a/spec/serializers/import/fogbugz_provider_repo_entity_spec.rb b/spec/serializers/import/fogbugz_provider_repo_entity_spec.rb
new file mode 100644
index 00000000000..b9029b67aab
--- /dev/null
+++ b/spec/serializers/import/fogbugz_provider_repo_entity_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Import::FogbugzProviderRepoEntity do
+ let(:provider_url) { 'https://demo.fogbugz.com/' }
+ let(:repo_data) do
+ {
+ 'ixProject' => 'foo',
+ 'sProject' => 'demo'
+ }
+ end
+ let(:repo) { Gitlab::FogbugzImport::Repository.new(repo_data) }
+
+ subject { described_class.represent(repo, { provider_url: provider_url }).as_json }
+
+ it_behaves_like 'exposes required fields for import entity' do
+ let(:expected_values) do
+ {
+ id: 'foo',
+ full_name: 'demo',
+ sanitized_name: 'demo',
+ provider_link: 'https://demo.fogbugz.com/demo'
+ }
+ end
+ end
+end
diff --git a/spec/serializers/import/githubish_provider_repo_entity_spec.rb b/spec/serializers/import/githubish_provider_repo_entity_spec.rb
new file mode 100644
index 00000000000..c6a07b2d64a
--- /dev/null
+++ b/spec/serializers/import/githubish_provider_repo_entity_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Import::GithubishProviderRepoEntity do
+ let(:provider_url) { 'https://github.com/' }
+ let(:repo) do
+ {
+ id: 1,
+ full_name: 'full/name',
+ name: 'name'
+ }
+ end
+
+ subject { described_class.represent(repo, { provider_url: provider_url }).as_json }
+
+ it_behaves_like 'exposes required fields for import entity' do
+ let(:expected_values) do
+ {
+ id: 1,
+ full_name: 'full/name',
+ sanitized_name: 'name',
+ provider_link: 'https://github.com/full/name'
+ }
+ end
+ end
+end
diff --git a/spec/serializers/import/gitlab_provider_repo_entity_spec.rb b/spec/serializers/import/gitlab_provider_repo_entity_spec.rb
new file mode 100644
index 00000000000..3f862c16fe2
--- /dev/null
+++ b/spec/serializers/import/gitlab_provider_repo_entity_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Import::GitlabProviderRepoEntity do
+ let(:repo_data) do
+ {
+ 'id' => 1,
+ 'path_with_namespace' => 'demo/test',
+ 'path' => 'test',
+ 'web_url' => 'https://gitlab.com/demo/test'
+ }
+ end
+
+ subject { described_class.new(repo_data).as_json }
+
+ it_behaves_like 'exposes required fields for import entity' do
+ let(:expected_values) do
+ {
+ id: 1,
+ full_name: 'demo/test',
+ sanitized_name: 'test',
+ provider_link: 'https://gitlab.com/demo/test'
+ }
+ end
+ end
+end
diff --git a/spec/serializers/import/provider_repo_serializer_spec.rb b/spec/serializers/import/provider_repo_serializer_spec.rb
new file mode 100644
index 00000000000..9bf55e6c65d
--- /dev/null
+++ b/spec/serializers/import/provider_repo_serializer_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Import::ProviderRepoSerializer do
+ using RSpec::Parameterized::TableSyntax
+
+ describe '#represent' do
+ where(:provider, :class_name) do
+ :github | 'Import::GithubishProviderRepoEntity'
+ :gitea | 'Import::GithubishProviderRepoEntity'
+ :bitbucket | 'Import::BitbucketProviderRepoEntity'
+ :bitbucket_server | 'Import::BitbucketServerProviderRepoEntity'
+ :fogbugz | 'Import::FogbugzProviderRepoEntity'
+ end
+
+ with_them do
+ it 'uses correct entity class' do
+ opts = { provider: provider }
+ expect(class_name.constantize).to receive(:represent)
+ described_class.new.represent({}, opts)
+ end
+ end
+
+ it 'raises an error if invalid provider supplied' do
+ expect { described_class.new.represent({}, { provider: :invalid })}.to raise_error { NotImplementedError }
+ end
+ end
+end
diff --git a/spec/serializers/merge_request_widget_entity_spec.rb b/spec/serializers/merge_request_widget_entity_spec.rb
index 40a0f09d1f3..039fb311bfc 100644
--- a/spec/serializers/merge_request_widget_entity_spec.rb
+++ b/spec/serializers/merge_request_widget_entity_spec.rb
@@ -178,7 +178,7 @@ describe MergeRequestWidgetEntity do
project.add_maintainer(user)
expect(subject[:new_project_pipeline_path])
- .to eq("/#{resource.project.full_path}/pipelines/new")
+ .to eq("/#{resource.project.full_path}/-/pipelines/new")
end
describe 'when source project is deleted' do
diff --git a/spec/serializers/paginated_diff_entity_spec.rb b/spec/serializers/paginated_diff_entity_spec.rb
index 77569aaa4bc..a6b83cb4286 100644
--- a/spec/serializers/paginated_diff_entity_spec.rb
+++ b/spec/serializers/paginated_diff_entity_spec.rb
@@ -30,4 +30,14 @@ describe PaginatedDiffEntity do
total_pages: 7
)
end
+
+ context 'when code_navigation feature flag is disabled' do
+ it 'does not execute Gitlab::CodeNavigationPath' do
+ stub_feature_flags(code_navigation: false)
+
+ expect(Gitlab::CodeNavigationPath).not_to receive(:new)
+
+ subject
+ end
+ end
end
diff --git a/spec/serializers/pipeline_details_entity_spec.rb b/spec/serializers/pipeline_details_entity_spec.rb
index a154bcac635..849dab102c2 100644
--- a/spec/serializers/pipeline_details_entity_spec.rb
+++ b/spec/serializers/pipeline_details_entity_spec.rb
@@ -173,44 +173,5 @@ describe PipelineDetailsEntity do
expect(subject[:triggered].first[:project]).not_to be_nil
end
end
-
- context 'when pipeline has expiring archive artifacts' do
- let(:pipeline) { create(:ci_empty_pipeline) }
- let!(:build_1) { create(:ci_build, :artifacts, pipeline: pipeline, artifacts_expire_at: 2.days.from_now, name: 'build_1') }
- let!(:build_2) { create(:ci_build, :artifacts, pipeline: pipeline, artifacts_expire_at: 2.days.from_now, name: 'build_2') }
- let!(:build_3) { create(:ci_build, :artifacts, pipeline: pipeline, artifacts_expire_at: 2.days.from_now, name: 'build_3') }
-
- let(:names) { subject[:details][:artifacts].map { |a| a[:name] } }
-
- context 'and preload_job_artifacts_archive is not defined in the options' do
- it 'defaults to true and eager loads the job_artifacts_archive' do
- recorder = ActiveRecord::QueryRecorder.new do
- expect(names).to match_array(%w[build_1 build_2 build_3])
- end
-
- expected_queries = Gitlab.ee? ? 42 : 29
-
- # This makes only one query to fetch all job artifacts
- expect(recorder.count).to eq(expected_queries)
- end
- end
-
- context 'and preload_job_artifacts_archive is set to false' do
- let(:entity) do
- described_class.represent(pipeline, request: request, preload_job_artifacts_archive: false)
- end
-
- it 'does not eager load the job_artifacts_archive' do
- recorder = ActiveRecord::QueryRecorder.new do
- expect(names).to match_array(%w[build_1 build_2 build_3])
- end
-
- expected_queries = Gitlab.ee? ? 44 : 31
-
- # This makes one query for each job artifact
- expect(recorder.count).to eq(expected_queries)
- end
- end
- end
end
end
diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb
index 4e4cc9c35e6..c8f25423f85 100644
--- a/spec/serializers/pipeline_serializer_spec.rb
+++ b/spec/serializers/pipeline_serializer_spec.rb
@@ -10,10 +10,6 @@ describe PipelineSerializer do
described_class.new(current_user: user, project: project)
end
- before do
- stub_feature_flags(ci_pipeline_persisted_stages: true)
- end
-
subject { serializer.represent(resource) }
describe '#represent' do
diff --git a/spec/serializers/provider_repo_entity_spec.rb b/spec/serializers/provider_repo_entity_spec.rb
deleted file mode 100644
index 9a1160d16d5..00000000000
--- a/spec/serializers/provider_repo_entity_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-describe ProviderRepoEntity do
- include ImportHelper
-
- let(:provider_repo) { { id: 1, full_name: 'full/name', name: 'name', owner: { login: 'owner' } } }
- let(:provider) { :github }
- let(:provider_url) { 'https://github.com' }
- let(:entity) { described_class.represent(provider_repo, provider: provider, provider_url: provider_url) }
-
- describe '#as_json' do
- subject { entity.as_json }
-
- it 'includes required fields' do
- expect(subject[:id]).to eq(provider_repo[:id])
- expect(subject[:full_name]).to eq(provider_repo[:full_name])
- expect(subject[:owner_name]).to eq(provider_repo[:owner][:login])
- expect(subject[:sanitized_name]).to eq(sanitize_project_name(provider_repo[:name]))
- expect(subject[:provider_link]).to eq(provider_project_link_url(provider_url, provider_repo[:full_name]))
- end
- end
-end
diff --git a/spec/serializers/provider_repo_serializer_spec.rb b/spec/serializers/provider_repo_serializer_spec.rb
deleted file mode 100644
index f2be30c36d9..00000000000
--- a/spec/serializers/provider_repo_serializer_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-describe ProviderRepoSerializer do
- it 'represents ProviderRepoEntity entities' do
- expect(described_class.entity_class).to eq(ProviderRepoEntity)
- end
-end
diff --git a/spec/serializers/service_field_entity_spec.rb b/spec/serializers/service_field_entity_spec.rb
new file mode 100644
index 00000000000..277890d143a
--- /dev/null
+++ b/spec/serializers/service_field_entity_spec.rb
@@ -0,0 +1,99 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe ServiceFieldEntity do
+ let(:request) { double('request') }
+
+ subject { described_class.new(field, request: request, service: service).as_json }
+
+ before do
+ allow(request).to receive(:service).and_return(service)
+ end
+
+ describe '#as_json' do
+ context 'Jira Service' do
+ let(:service) { create(:jira_service) }
+
+ context 'field with type text' do
+ let(:field) { service.global_fields.find { |field| field[:name] == 'username' } }
+
+ it 'exposes correct attributes' do
+ expected_hash = {
+ type: 'text',
+ name: 'username',
+ title: 'Username or Email',
+ placeholder: 'Use a username for server version and an email for cloud version',
+ required: true,
+ choices: nil,
+ help: nil,
+ value: 'jira_username'
+ }
+
+ is_expected.to eq(expected_hash)
+ end
+ end
+
+ context 'field with type password' do
+ let(:field) { service.global_fields.find { |field| field[:name] == 'password' } }
+
+ it 'exposes correct attributes but hides password' do
+ expected_hash = {
+ type: 'password',
+ name: 'password',
+ title: 'Password or API token',
+ placeholder: 'Use a password for server version and an API token for cloud version',
+ required: true,
+ choices: nil,
+ help: nil,
+ value: 'true'
+ }
+
+ is_expected.to eq(expected_hash)
+ end
+ end
+ end
+
+ context 'EmailsOnPush Service' do
+ let(:service) { create(:emails_on_push_service) }
+
+ context 'field with type checkbox' do
+ let(:field) { service.global_fields.find { |field| field[:name] == 'send_from_committer_email' } }
+
+ it 'exposes correct attributes' do
+ expected_hash = {
+ type: 'checkbox',
+ name: 'send_from_committer_email',
+ title: 'Send from committer',
+ placeholder: nil,
+ required: nil,
+ choices: nil,
+ value: true
+ }
+
+ is_expected.to include(expected_hash)
+ expect(subject[:help]).to include("Send notifications from the committer's email address if the domain is part of the domain GitLab is running on")
+ end
+ end
+
+ context 'field with type select' do
+ let(:field) { service.global_fields.find { |field| field[:name] == 'branches_to_be_notified' } }
+
+ it 'exposes correct attributes' do
+ expected_hash = {
+ type: 'select',
+ name: 'branches_to_be_notified',
+ title: nil,
+ placeholder: nil,
+ required: nil,
+ choices: [['All branches', 'all'], ['Default branch', 'default'], ['Protected branches', 'protected'], ['Default branch and protected branches', 'default_and_protected']],
+ help: nil,
+ value: nil
+ }
+
+ is_expected.to eq(expected_hash)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/serializers/web_ide_terminal_entity_spec.rb b/spec/serializers/web_ide_terminal_entity_spec.rb
new file mode 100644
index 00000000000..e163afa14ed
--- /dev/null
+++ b/spec/serializers/web_ide_terminal_entity_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe WebIdeTerminalEntity do
+ let(:build) { create(:ci_build) }
+ let(:entity) { described_class.new(WebIdeTerminal.new(build)) }
+
+ subject { entity.as_json }
+
+ it { is_expected.to have_key(:id) }
+ it { is_expected.to have_key(:status) }
+ it { is_expected.to have_key(:show_path) }
+ it { is_expected.to have_key(:cancel_path) }
+ it { is_expected.to have_key(:retry_path) }
+ it { is_expected.to have_key(:terminal_path) }
+ it { is_expected.to have_key(:services) }
+ it { is_expected.to have_key(:proxy_websocket_path) }
+
+ context 'when feature flag build_service_proxy is disabled' do
+ before do
+ stub_feature_flags(build_service_proxy: false)
+ end
+
+ it { is_expected.not_to have_key(:proxy_websocket_path) }
+ end
+end
diff --git a/spec/serializers/web_ide_terminal_serializer_spec.rb b/spec/serializers/web_ide_terminal_serializer_spec.rb
new file mode 100644
index 00000000000..01133deaf84
--- /dev/null
+++ b/spec/serializers/web_ide_terminal_serializer_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe WebIdeTerminalSerializer do
+ let(:build) { create(:ci_build) }
+
+ subject { described_class.new.represent(WebIdeTerminal.new(build)) }
+
+ it 'represents WebIdeTerminalEntity entities' do
+ expect(described_class.entity_class).to eq(WebIdeTerminalEntity)
+ end
+
+ it 'accepts WebIdeTerminal as a resource' do
+ expect(subject[:id]).to eq build.id
+ end
+
+ context 'when resource is a build' do
+ subject { described_class.new.represent(build) }
+
+ it 'transforms it into a WebIdeTerminal resource' do
+ expect(WebIdeTerminal).to receive(:new)
+
+ subject
+ end
+ end
+end