diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
commit | 71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch) | |
tree | 6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /spec/serializers | |
parent | a7253423e3403b8c08f8a161e5937e1488f5f407 (diff) |
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'spec/serializers')
10 files changed, 162 insertions, 20 deletions
diff --git a/spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb b/spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb index 8b45e8a64fc..7c53acbf168 100644 --- a/spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb +++ b/spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Analytics::CycleAnalytics::StageEntity do - let(:stage) { build(:cycle_analytics_project_stage, start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged) } + let(:stage) { build(:cycle_analytics_stage, start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged) } subject(:entity_json) { described_class.new(Analytics::CycleAnalytics::StagePresenter.new(stage)).as_json } diff --git a/spec/serializers/ci/pipeline_entity_spec.rb b/spec/serializers/ci/pipeline_entity_spec.rb index ae992e478a6..4df542e3c98 100644 --- a/spec/serializers/ci/pipeline_entity_spec.rb +++ b/spec/serializers/ci/pipeline_entity_spec.rb @@ -36,11 +36,10 @@ RSpec.describe Ci::PipelineEntity do expect(subject).to include :details expect(subject[:details]) - .to include :duration, :finished_at, :name, :event_type_name + .to include :duration, :finished_at, :event_type_name expect(subject[:details][:status]).to include :icon, :favicon, :text, :label, :tooltip expect(subject[:details][:event_type_name]).to eq('Merged result pipeline') - expect(subject[:details][:name]).to eq('Merged result pipeline') end it 'contains flags' do diff --git a/spec/serializers/codequality_degradation_entity_spec.rb b/spec/serializers/codequality_degradation_entity_spec.rb index 0390e232fd5..32269e5475b 100644 --- a/spec/serializers/codequality_degradation_entity_spec.rb +++ b/spec/serializers/codequality_degradation_entity_spec.rb @@ -18,6 +18,7 @@ RSpec.describe CodequalityDegradationEntity do expect(subject[:file_path]).to eq("file_a.rb") expect(subject[:line]).to eq(10) expect(subject[:web_url]).to eq("http://localhost/root/test-project/-/blob/f572d396fae9206628714fb2ce00f72e94f2258f/file_a.rb#L10") + expect(subject[:engine_name]).to eq('structure') end end @@ -30,6 +31,7 @@ RSpec.describe CodequalityDegradationEntity do expect(subject[:file_path]).to eq("file_b.rb") expect(subject[:line]).to eq(10) expect(subject[:web_url]).to eq("http://localhost/root/test-project/-/blob/f572d396fae9206628714fb2ce00f72e94f2258f/file_b.rb#L10") + expect(subject[:engine_name]).to eq('rubocop') end end @@ -46,6 +48,7 @@ RSpec.describe CodequalityDegradationEntity do expect(subject[:file_path]).to eq("file_b.rb") expect(subject[:line]).to eq(10) expect(subject[:web_url]).to eq("http://localhost/root/test-project/-/blob/f572d396fae9206628714fb2ce00f72e94f2258f/file_b.rb#L10") + expect(subject[:engine_name]).to eq('rubocop') end end end diff --git a/spec/serializers/import/github_realtime_repo_entity_spec.rb b/spec/serializers/import/github_realtime_repo_entity_spec.rb new file mode 100644 index 00000000000..7f137366be2 --- /dev/null +++ b/spec/serializers/import/github_realtime_repo_entity_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Import::GithubRealtimeRepoEntity, feature_category: :importers do + subject(:entity) { described_class.new(project) } + + let(:import_state) { instance_double(ProjectImportState, failed?: false, in_progress?: true) } + let(:import_failures) { [instance_double(ImportFailure, exception_message: 'test error')] } + let(:project) do + instance_double( + Project, + id: 100500, + import_status: 'importing', + import_state: import_state, + import_failures: import_failures, + import_checksums: {} + ) + end + + it 'exposes correct attributes' do + data = entity.as_json + + expect(data.keys).to contain_exactly(:id, :import_status, :stats) + expect(data[:id]).to eq project.id + expect(data[:import_status]).to eq project.import_status + end + + context 'when import stats is failed' do + let(:import_state) { instance_double(ProjectImportState, failed?: true, in_progress?: false) } + + it 'includes import_error' do + data = entity.as_json + + expect(data.keys).to contain_exactly(:id, :import_status, :stats, :import_error) + expect(data[:import_error]).to eq 'test error' + end + end +end diff --git a/spec/serializers/import/github_realtime_repo_serializer_spec.rb b/spec/serializers/import/github_realtime_repo_serializer_spec.rb new file mode 100644 index 00000000000..b656132e332 --- /dev/null +++ b/spec/serializers/import/github_realtime_repo_serializer_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Import::GithubRealtimeRepoSerializer, feature_category: :importers do + subject(:serializer) { described_class.new } + + it '.entity_class' do + expect(described_class.entity_class).to eq(Import::GithubRealtimeRepoEntity) + end + + describe '#represent' do + let(:import_state) { instance_double(ProjectImportState, failed?: false, in_progress?: true) } + let(:project) do + instance_double( + Project, + id: 100500, + import_status: 'importing', + import_state: import_state + ) + end + + let(:expected_data) do + { + id: project.id, + import_status: 'importing', + stats: { fetched: {}, imported: {} } + }.deep_stringify_keys + end + + context 'when a single object is being serialized' do + let(:resource) { project } + + it 'serializes organization object' do + expect(serializer.represent(resource).as_json).to eq expected_data + end + end + + context 'when multiple objects are being serialized' do + let(:count) { 3 } + let(:resource) { Array.new(count, project) } + + it 'serializes array of organizations' do + expect(serializer.represent(resource).as_json).to all(eq(expected_data)) + end + end + end +end diff --git a/spec/serializers/integrations/field_entity_spec.rb b/spec/serializers/integrations/field_entity_spec.rb index 4212a1ee6a2..1ca1545c11a 100644 --- a/spec/serializers/integrations/field_entity_spec.rb +++ b/spec/serializers/integrations/field_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::FieldEntity do +RSpec.describe Integrations::FieldEntity, feature_category: :integrations do let(:request) { EntityRequest.new(integration: integration) } subject { described_class.new(field, request: request, integration: integration).as_json } @@ -23,9 +23,9 @@ RSpec.describe Integrations::FieldEntity do section: 'connection', type: 'text', name: 'username', - title: 'Username or Email', + title: 'Username or email', placeholder: nil, - help: 'Use a username for server version and an email for cloud version.', + help: 'Username for the server version or an email for the cloud version', required: true, choices: nil, value: 'jira_username', diff --git a/spec/serializers/issue_entity_spec.rb b/spec/serializers/issue_entity_spec.rb index 9d53d8bb235..06d8523b2e7 100644 --- a/spec/serializers/issue_entity_spec.rb +++ b/spec/serializers/issue_entity_spec.rb @@ -65,7 +65,7 @@ RSpec.describe IssueEntity do before do project.add_developer(member) public_project.add_developer(member) - Issues::MoveService.new(project: public_project, current_user: member).execute(issue, project) + Issues::MoveService.new(container: public_project, current_user: member).execute(issue, project) end context 'when user cannot read target project' do @@ -97,7 +97,7 @@ RSpec.describe IssueEntity do before do Issues::DuplicateService - .new(project: project, current_user: member) + .new(container: project, current_user: member) .execute(issue, new_issue) end @@ -164,21 +164,57 @@ RSpec.describe IssueEntity do it_behaves_like 'issuable entity current_user properties' context 'when issue has email participants' do + let(:obfuscated_email) { 'an*****@e*****.c**' } + let(:email) { 'any@email.com' } + before do - resource.issue_email_participants.create!(email: 'any@email.com') + resource.issue_email_participants.create!(email: email) end - context 'when issue is confidential' do - it 'returns email participants' do - resource.update!(confidential: true) + context 'with anonymous user' do + it 'returns obfuscated email participants email' do + request = double('request', current_user: nil) - expect(subject[:issue_email_participants]).to match_array([{ email: "any@email.com" }]) + response = described_class.new(resource, request: request).as_json + expect(response[:issue_email_participants]).to eq([{ email: obfuscated_email }]) end end - context 'when issue is not confidential' do - it 'returns empty array' do - expect(subject[:issue_email_participants]).to be_empty + context 'with signed in user' do + context 'when user has no role in project' do + it 'returns obfuscated email participants email' do + expect(subject[:issue_email_participants]).to eq([{ email: obfuscated_email }]) + end + end + + context 'when user has guest role in project' do + let(:member) { create(:user) } + + before do + project.add_guest(member) + end + + it 'returns obfuscated email participants email' do + request = double('request', current_user: member) + + response = described_class.new(resource, request: request).as_json + expect(response[:issue_email_participants]).to eq([{ email: obfuscated_email }]) + end + end + + context 'when user has (at least) reporter role in project' do + let(:member) { create(:user) } + + before do + project.add_reporter(member) + end + + it 'returns full email participants email' do + request = double('request', current_user: member) + + response = described_class.new(resource, request: request).as_json + expect(response[:issue_email_participants]).to eq([{ email: email }]) + end end end end diff --git a/spec/serializers/merge_requests/pipeline_entity_spec.rb b/spec/serializers/merge_requests/pipeline_entity_spec.rb index 414ce6653bc..acffa1e87a6 100644 --- a/spec/serializers/merge_requests/pipeline_entity_spec.rb +++ b/spec/serializers/merge_requests/pipeline_entity_spec.rb @@ -33,12 +33,11 @@ RSpec.describe MergeRequests::PipelineEntity do ) expect(subject[:commit]).to include(:short_id, :commit_path) expect(subject[:ref]).to include(:branch) - expect(subject[:details]).to include(:artifacts, :name, :event_type_name, :status, :stages, :finished_at) + expect(subject[:details]).to include(:artifacts, :event_type_name, :status, :stages, :finished_at) expect(subject[:details][:status]).to include(:icon, :favicon, :text, :label, :tooltip) expect(subject[:flags]).to include(:merge_request_pipeline) expect(subject[:details][:event_type_name]).to eq('Merged result pipeline') - expect(subject[:details][:name]).to eq('Merged result pipeline') end it 'returns presented coverage' do diff --git a/spec/serializers/pipeline_details_entity_spec.rb b/spec/serializers/pipeline_details_entity_spec.rb index 764d55e8b4a..de05d2afd2b 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(:commit_status, pipeline: pipeline) + create(:ci_build, pipeline: pipeline) end it 'contains stages' do @@ -182,6 +182,7 @@ RSpec.describe PipelineDetailsEntity do expect(source_jobs[cross_project_pipeline.id][:name]).to eq('cross-project') expect(source_jobs[child_pipeline.id][:name]).to eq('child') + expect(source_jobs[child_pipeline.id][:retried]).to eq false end end end diff --git a/spec/serializers/project_import_entity_spec.rb b/spec/serializers/project_import_entity_spec.rb index 94af9f1cbd8..6d292d18ae7 100644 --- a/spec/serializers/project_import_entity_spec.rb +++ b/spec/serializers/project_import_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ProjectImportEntity do +RSpec.describe ProjectImportEntity, feature_category: :importers do include ImportHelper let_it_be(:project) { create(:project, import_status: :started, import_source: 'namespace/project') } @@ -10,6 +10,10 @@ RSpec.describe ProjectImportEntity do let(:provider_url) { 'https://provider.com' } let(:entity) { described_class.represent(project, provider_url: provider_url) } + before do + create(:import_failure, project: project) + end + describe '#as_json' do subject { entity.as_json } @@ -18,6 +22,19 @@ RSpec.describe ProjectImportEntity do expect(subject[:import_status]).to eq(project.import_status) expect(subject[:human_import_status_name]).to eq(project.human_import_status_name) expect(subject[:provider_link]).to eq(provider_project_link_url(provider_url, project[:import_source])) + expect(subject[:import_error]).to eq(nil) + end + + context 'when import is failed' do + let!(:last_import_failure) { create(:import_failure, project: project, exception_message: 'LAST ERROR') } + + before do + project.import_state.fail_op! + end + + it 'includes only the last import failure' do + expect(subject[:import_error]).to eq(last_import_failure.exception_message) + end end end end |