diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/serializers | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/serializers')
14 files changed, 111 insertions, 27 deletions
diff --git a/spec/serializers/access_token_entity_base_spec.rb b/spec/serializers/access_token_entity_base_spec.rb new file mode 100644 index 00000000000..e14a07a346a --- /dev/null +++ b/spec/serializers/access_token_entity_base_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe AccessTokenEntityBase do + let_it_be(:user) { create(:user) } + let_it_be(:token) { create(:personal_access_token, user: user, expires_at: nil) } + + subject(:json) { described_class.new(token).as_json } + + it 'has the correct attributes' do + expect(json).to( + include( + id: token.id, + name: token.name, + revoked: false, + created_at: token.created_at, + scopes: token.scopes, + expires_at: nil, + expired: false, + expires_soon: false + )) + + expect(json).not_to include(:token) + end +end diff --git a/spec/serializers/ci/dag_pipeline_entity_spec.rb b/spec/serializers/ci/dag_pipeline_entity_spec.rb index 548fd247743..a8ac76d800f 100644 --- a/spec/serializers/ci/dag_pipeline_entity_spec.rb +++ b/spec/serializers/ci/dag_pipeline_entity_spec.rb @@ -5,7 +5,8 @@ require 'spec_helper' RSpec.describe Ci::DagPipelineEntity do let_it_be(:request) { double(:request) } - let(:pipeline) { create(:ci_pipeline) } + let_it_be(:pipeline) { create(:ci_pipeline) } + let(:entity) { described_class.new(pipeline, request: request) } describe '#as_json' do @@ -28,9 +29,13 @@ RSpec.describe Ci::DagPipelineEntity do 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) } + let_it_be(:build_stage) { create(:ci_stage, name: 'build', pipeline: pipeline) } + let_it_be(:test_stage) { create(:ci_stage, name: 'test', pipeline: pipeline) } + let_it_be(:deploy_stage) { create(:ci_stage, name: 'deploy', pipeline: pipeline) } + + let!(:build_job) { create(:ci_build, ci_stage: build_stage, pipeline: pipeline) } + let!(:test_job) { create(:ci_build, ci_stage: test_stage, pipeline: pipeline) } + let!(:deploy_job) { create(:ci_build, ci_stage: deploy_stage, pipeline: pipeline) } it 'contains 3 stages' do stages = subject[:stages] @@ -47,28 +52,31 @@ RSpec.describe Ci::DagPipelineEntity do let!(:stage_test) { create(:ci_stage, name: 'test', position: 2, pipeline: pipeline) } let!(:stage_deploy) { create(:ci_stage, 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!(:commit_status) { create(:generic_commit_status, stage: 'build', pipeline: pipeline) } + let!(:job_build_1) { create(:ci_build, name: 'build 1', ci_stage: stage_build, pipeline: pipeline) } + let!(:job_build_2) { create(:ci_build, name: 'build 2', ci_stage: stage_build, pipeline: pipeline) } + let!(:commit_status) { create(:generic_commit_status, ci_stage: 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_rspec_1) { create(:ci_build, name: 'rspec 1/2', ci_stage: stage_test, pipeline: pipeline) } + let!(:job_rspec_2) { create(:ci_build, name: 'rspec 2/2', ci_stage: 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, name: 'jest', ci_stage: 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, name: 'deploy_ruby', ci_stage: 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, name: 'deploy_js', ci_stage: stage_deploy, scheduling_type: 'dag', pipeline: pipeline) + .tap do |job| create(:ci_build_need, name: 'jest', build: job) end end diff --git a/spec/serializers/ci/lint/job_entity_spec.rb b/spec/serializers/ci/lint/job_entity_spec.rb index 2ef86cfd004..e1477612ad5 100644 --- a/spec/serializers/ci/lint/job_entity_spec.rb +++ b/spec/serializers/ci/lint/job_entity_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Ci::Lint::JobEntity, :aggregate_failures do stage: 'test', before_script: ['bundle install', 'bundle exec rake db:create'], script: ["rake spec"], - after_script: ["rake spec"], + after_script: ["rake spec"], tag_list: %w[ruby postgres], environment: { name: 'hello', url: 'world' }, when: 'on_success', diff --git a/spec/serializers/cluster_entity_spec.rb b/spec/serializers/cluster_entity_spec.rb index 7c4c146575d..2de27deeffe 100644 --- a/spec/serializers/cluster_entity_spec.rb +++ b/spec/serializers/cluster_entity_spec.rb @@ -45,7 +45,7 @@ RSpec.describe ClusterEntity do context 'when no application has been installed' do let(:cluster) { create(:cluster, :instance) } - subject { described_class.new(cluster, request: request).as_json[:applications]} + subject { described_class.new(cluster, request: request).as_json[:applications] } it 'contains helm as not_installable' do expect(subject).not_to be_empty diff --git a/spec/serializers/container_repository_entity_spec.rb b/spec/serializers/container_repository_entity_spec.rb index 9ea00bc79e1..00e6a26d0be 100644 --- a/spec/serializers/container_repository_entity_spec.rb +++ b/spec/serializers/container_repository_entity_spec.rb @@ -14,8 +14,7 @@ RSpec.describe ContainerRepositoryEntity do before do stub_container_registry_config(enabled: true) - stub_container_registry_tags(repository: :any, - tags: %w[stable latest]) + 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 diff --git a/spec/serializers/deployment_entity_spec.rb b/spec/serializers/deployment_entity_spec.rb index a017f7523e9..433ce344680 100644 --- a/spec/serializers/deployment_entity_spec.rb +++ b/spec/serializers/deployment_entity_spec.rb @@ -61,8 +61,7 @@ RSpec.describe DeploymentEntity do context 'when the pipeline has another manual action' do let!(:other_build) do - create(:ci_build, :manual, name: 'another deploy', - pipeline: pipeline, environment: build.environment) + create(:ci_build, :manual, name: 'another deploy', pipeline: pipeline, environment: build.environment) end let!(:other_deployment) { create(:deployment, deployable: build) } diff --git a/spec/serializers/group_access_token_entity_spec.rb b/spec/serializers/group_access_token_entity_spec.rb index 39b587c7df7..05609dc3c7a 100644 --- a/spec/serializers/group_access_token_entity_spec.rb +++ b/spec/serializers/group_access_token_entity_spec.rb @@ -27,7 +27,7 @@ RSpec.describe GroupAccessTokenEntity do scopes: token.scopes, user_id: token.user_id, revoke_path: expected_revoke_path, - access_level: ::Gitlab::Access::DEVELOPER + role: 'Developer' )) expect(json).not_to include(:token) @@ -48,7 +48,7 @@ RSpec.describe GroupAccessTokenEntity do scopes: token.scopes, user_id: token.user_id, revoke_path: expected_revoke_path, - access_level: nil + role: nil )) expect(json).not_to include(:token) diff --git a/spec/serializers/impersonation_access_token_entity_spec.rb b/spec/serializers/impersonation_access_token_entity_spec.rb new file mode 100644 index 00000000000..e8517779c0d --- /dev/null +++ b/spec/serializers/impersonation_access_token_entity_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe ImpersonationAccessTokenEntity do + let_it_be(:user) { create(:user) } + let_it_be(:token) { create(:personal_access_token, :impersonation, user: user) } + + subject(:json) { described_class.new(token).as_json } + + it 'has the correct attributes' do + expected_revoke_path = Gitlab::Routing.url_helpers + .revoke_admin_user_impersonation_token_path( + { user_id: user, id: token }) + + expect(json).to( + include( + id: token.id, + name: token.name, + scopes: token.scopes, + user_id: token.user_id, + revoke_path: expected_revoke_path + )) + + expect(json).not_to include(:token) + end +end diff --git a/spec/serializers/impersonation_access_token_serializer_spec.rb b/spec/serializers/impersonation_access_token_serializer_spec.rb new file mode 100644 index 00000000000..0c8cebb94b1 --- /dev/null +++ b/spec/serializers/impersonation_access_token_serializer_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe ImpersonationAccessTokenSerializer do + subject(:serializer) { described_class.new } + + describe '#represent' do + it 'can render a single token' do + token = create(:personal_access_token) + + expect(serializer.represent(token)).to be_kind_of(Hash) + end + + it 'can render a collection of tokens' do + tokens = create_list(:personal_access_token, 2) + + expect(serializer.represent(tokens)).to be_kind_of(Array) + end + end +end diff --git a/spec/serializers/import/provider_repo_serializer_spec.rb b/spec/serializers/import/provider_repo_serializer_spec.rb index 430bad151d3..905685c75e3 100644 --- a/spec/serializers/import/provider_repo_serializer_spec.rb +++ b/spec/serializers/import/provider_repo_serializer_spec.rb @@ -23,7 +23,7 @@ RSpec.describe Import::ProviderRepoSerializer do end it 'raises an error if invalid provider supplied' do - expect { described_class.new.represent({}, { provider: :invalid })}.to raise_error { NotImplementedError } + expect { described_class.new.represent({}, { provider: :invalid }) }.to raise_error { NotImplementedError } end end end diff --git a/spec/serializers/member_user_entity_spec.rb b/spec/serializers/member_user_entity_spec.rb index 4dd6848c47b..638347738f2 100644 --- a/spec/serializers/member_user_entity_spec.rb +++ b/spec/serializers/member_user_entity_spec.rb @@ -27,6 +27,12 @@ RSpec.describe MemberUserEntity do expect(entity_hash[:blocked]).to be(true) end + it 'correctly exposes `is_bot`' do + allow(user).to receive(:bot?).and_return(true) + + expect(entity_hash[:is_bot]).to be(true) + end + it 'does not expose `two_factor_enabled` by default' do expect(entity_hash[:two_factor_enabled]).to be(nil) end diff --git a/spec/serializers/merge_request_metrics_helper_spec.rb b/spec/serializers/merge_request_metrics_helper_spec.rb index 8f683df1faa..ec764bf7853 100644 --- a/spec/serializers/merge_request_metrics_helper_spec.rb +++ b/spec/serializers/merge_request_metrics_helper_spec.rb @@ -57,9 +57,9 @@ RSpec.describe MergeRequestMetricsHelper do expect(MergeRequest::Metrics).to receive(:new) .with(latest_closed_at: closed_event&.updated_at, - latest_closed_by: closed_event&.author, - merged_at: merge_event&.updated_at, - merged_by: merge_event&.author) + latest_closed_by: closed_event&.author, + merged_at: merge_event&.updated_at, + merged_by: merge_event&.author) .and_call_original subject diff --git a/spec/serializers/pipeline_details_entity_spec.rb b/spec/serializers/pipeline_details_entity_spec.rb index 67f8860ed4a..ca38721cc7f 100644 --- a/spec/serializers/pipeline_details_entity_spec.rb +++ b/spec/serializers/pipeline_details_entity_spec.rb @@ -104,7 +104,7 @@ RSpec.describe PipelineDetailsEntity do let(:pipeline) { create(:ci_empty_pipeline) } before do - create(:generic_commit_status, pipeline: pipeline) + create(:commit_status, pipeline: pipeline) end it 'contains stages' do diff --git a/spec/serializers/project_access_token_entity_spec.rb b/spec/serializers/project_access_token_entity_spec.rb index 616aa45e9d5..4b5b4d4d77d 100644 --- a/spec/serializers/project_access_token_entity_spec.rb +++ b/spec/serializers/project_access_token_entity_spec.rb @@ -28,7 +28,7 @@ RSpec.describe ProjectAccessTokenEntity do scopes: token.scopes, user_id: token.user_id, revoke_path: expected_revoke_path, - access_level: ::Gitlab::Access::DEVELOPER + role: 'Developer' )) expect(json).not_to include(:token) @@ -52,7 +52,7 @@ RSpec.describe ProjectAccessTokenEntity do scopes: token.scopes, user_id: token.user_id, revoke_path: expected_revoke_path, - access_level: nil + role: nil )) expect(json).not_to include(:token) |