diff options
Diffstat (limited to 'spec/serializers')
15 files changed, 230 insertions, 94 deletions
diff --git a/spec/serializers/analytics_issue_entity_spec.rb b/spec/serializers/analytics_issue_entity_spec.rb index bc5cab638cd..ca1e0705d77 100644 --- a/spec/serializers/analytics_issue_entity_spec.rb +++ b/spec/serializers/analytics_issue_entity_spec.rb @@ -11,6 +11,7 @@ RSpec.describe AnalyticsIssueEntity do iid: "1", id: "1", created_at: "2016-11-12 15:04:02.948604", + end_event_timestamp: "2022-05-24 14:33:01.529701", author: user, project_path: project.path, namespace_path: project.namespace.route.path @@ -40,10 +41,34 @@ RSpec.describe AnalyticsIssueEntity do expect(subject).to include(:namespace_full_path) end + it 'contains the end event timestamp' do + expect(entity.as_json[:end_event_timestamp]).to match(/ ago$/) + end + it 'does not contain sensitive information' do expect(subject).not_to include(/token/) expect(subject).not_to include(/variables/) end + + context 'when end_event_timestamp is nil' do + let(:entity_hash) do + { + total_time: "172802.724419", + title: "Eos voluptatem inventore in sed.", + iid: "1", + id: "1", + created_at: "2016-11-12 15:04:02.948604", + end_event_timestamp: nil, + author: user, + project_path: project.path, + namespace_path: project.namespace.route.path + } + end + + it 'contains a nil end_event_timestamp' do + expect(entity.as_json[:end_event_timestamp]).to be_nil + end + end end context 'without subgroup' do diff --git a/spec/serializers/deploy_key_entity_spec.rb b/spec/serializers/deploy_keys/basic_deploy_key_entity_spec.rb index e8d9701be67..c39eb14e339 100644 --- a/spec/serializers/deploy_key_entity_spec.rb +++ b/spec/serializers/deploy_keys/basic_deploy_key_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DeployKeyEntity do +RSpec.describe DeployKeys::BasicDeployKeyEntity do include RequestAwareEntity let(:user) { create(:user) } @@ -18,7 +18,7 @@ RSpec.describe DeployKeyEntity do project_private.deploy_keys << deploy_key end - describe 'returns deploy keys with projects a user can read' do + describe 'returns deploy keys' do let(:expected_result) do { id: deploy_key.id, @@ -30,19 +30,7 @@ RSpec.describe DeployKeyEntity do almost_orphaned: false, created_at: deploy_key.created_at, updated_at: deploy_key.updated_at, - can_edit: false, - deploy_keys_projects: [ - { - can_push: false, - project: - { - id: project.id, - name: project.name, - full_path: project_path(project), - full_name: project.full_name - } - } - ] + can_edit: false } end diff --git a/spec/serializers/deploy_keys/deploy_key_entity_spec.rb b/spec/serializers/deploy_keys/deploy_key_entity_spec.rb new file mode 100644 index 00000000000..e989aa8656c --- /dev/null +++ b/spec/serializers/deploy_keys/deploy_key_entity_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe DeployKeys::DeployKeyEntity do + include RequestAwareEntity + + let(:user) { create(:user) } + let(:project) { create(:project, :internal)} + let(:project_private) { create(:project, :private)} + let(:deploy_key) { create(:deploy_key) } + let(:options) { { user: user } } + + let(:entity) { described_class.new(deploy_key, options) } + + before do + project.deploy_keys << deploy_key + project_private.deploy_keys << deploy_key + end + + describe 'returns deploy keys with projects a user can read' do + let(:expected_result) do + { + id: deploy_key.id, + user_id: deploy_key.user_id, + title: deploy_key.title, + fingerprint: deploy_key.fingerprint, + fingerprint_sha256: deploy_key.fingerprint_sha256, + destroyed_when_orphaned: true, + almost_orphaned: false, + created_at: deploy_key.created_at, + updated_at: deploy_key.updated_at, + can_edit: false, + deploy_keys_projects: [ + { + can_push: false, + project: + { + id: project.id, + name: project.name, + full_path: project_path(project), + full_name: project.full_name + } + } + ] + } + end + + it { expect(entity.as_json).to eq(expected_result) } + end +end diff --git a/spec/serializers/deployment_entity_spec.rb b/spec/serializers/deployment_entity_spec.rb index 500d5718bf1..a017f7523e9 100644 --- a/spec/serializers/deployment_entity_spec.rb +++ b/spec/serializers/deployment_entity_spec.rb @@ -60,12 +60,16 @@ RSpec.describe DeploymentEntity do end context 'when the pipeline has another manual action' do - let(:other_build) { create(:ci_build, :manual, name: 'another deploy', pipeline: pipeline) } - let!(:other_deployment) { create(:deployment, deployable: other_build) } + let!(:other_build) do + create(:ci_build, :manual, name: 'another deploy', + pipeline: pipeline, environment: build.environment) + end + + let!(:other_deployment) { create(:deployment, deployable: build) } it 'returns another manual action' do - expect(subject[:manual_actions].count).to eq(1) - expect(subject[:manual_actions].first[:name]).to eq('another deploy') + expect(subject[:manual_actions].count).to eq(2) + expect(subject[:manual_actions].pluck(:name)).to match_array(['test', 'another deploy']) end context 'when user is a reporter' do diff --git a/spec/serializers/diff_file_entity_spec.rb b/spec/serializers/diff_file_entity_spec.rb index ebfb21c4311..48099cb1fdf 100644 --- a/spec/serializers/diff_file_entity_spec.rb +++ b/spec/serializers/diff_file_entity_spec.rb @@ -91,5 +91,38 @@ RSpec.describe DiffFileEntity do end end + describe '#highlighted_diff_lines' do + context 'file without a conflict' do + let(:options) { { conflicts: {} } } + + it 'calls diff_lines_for_serializer on diff_file' do + # #diff_lines_for_serializer gets called in #fully_expanded? as well so we expect twice + expect(diff_file).to receive(:diff_lines_for_serializer).twice.and_return([]) + expect(subject[:highlighted_diff_lines]).to eq([]) + end + end + + context 'file with a conflict' do + let(:conflict_file) { instance_double(Gitlab::Conflict::File, conflict_type: :both_modified) } + let(:options) { { conflicts: { diff_file.new_path => conflict_file } } } + + it 'calls diff_lines_for_serializer on matching conflict file' do + expect(conflict_file).to receive(:diff_lines_for_serializer).and_return([]) + expect(subject[:highlighted_diff_lines]).to eq([]) + end + + context 'when Gitlab::Git::Conflict::Parser::UnmergeableFile gets raised' do + before do + allow(conflict_file).to receive(:diff_lines_for_serializer).and_raise(Gitlab::Git::Conflict::Parser::UnmergeableFile) + end + + it 'falls back to diff_file diff_lines_for_serializer' do + expect(diff_file).to receive(:diff_lines_for_serializer).and_return([]) + expect(subject[:highlighted_diff_lines]).to eq([]) + end + end + end + end + it_behaves_like 'diff file with conflict_type' end diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb index fe6278084f9..05644dad151 100644 --- a/spec/serializers/environment_serializer_spec.rb +++ b/spec/serializers/environment_serializer_spec.rb @@ -212,7 +212,10 @@ RSpec.describe EnvironmentSerializer do upcoming_deployment = nil create(:environment, project: project).tap do |environment| create(:deployment, :success, environment: environment, project: project) - last_deployment = create(:deployment, :success, environment: environment, project: project) + + create(:ci_build, :success, project: project).tap do |build| + last_deployment = create(:deployment, :success, environment: environment, project: project, deployable: build) + end create(:deployment, :running, environment: environment, project: project) upcoming_deployment = create(:deployment, :running, environment: environment, project: project) @@ -227,8 +230,22 @@ RSpec.describe EnvironmentSerializer do def create_environment_with_associations(project) create(:environment, project: project).tap do |environment| - create(:deployment, :success, environment: environment, project: project) - create(:deployment, :running, environment: environment, project: project) + create(:ci_pipeline, project: project).tap do |pipeline| + create(:ci_build, :manual, project: project, pipeline: pipeline, name: 'stop-action', + environment: environment.name) + + create(:ci_build, :scheduled, project: project, pipeline: pipeline, + environment: environment.name).tap do |scheduled_build| + create(:deployment, :running, environment: environment, project: project, + deployable: scheduled_build) + end + + create(:ci_build, :success, :manual, project: project, pipeline: pipeline, + environment: environment.name).tap do |manual_build| + create(:deployment, :success, environment: environment, project: project, + deployable: manual_build, on_stop: 'stop-action') + end + end end end end diff --git a/spec/serializers/service_event_entity_spec.rb b/spec/serializers/integrations/event_entity_spec.rb index db82e84fcf8..07281248f5b 100644 --- a/spec/serializers/service_event_entity_spec.rb +++ b/spec/serializers/integrations/event_entity_spec.rb @@ -2,17 +2,17 @@ require 'spec_helper' -RSpec.describe ServiceEventEntity do - let(:request) { double('request') } +RSpec.describe Integrations::EventEntity do + let(:request) { EntityRequest.new(integration: integration) } - subject { described_class.new(event, request: request, service: integration).as_json } + subject { described_class.new(event, request: request, integration: integration).as_json } before do - allow(request).to receive(:service).and_return(integration) + allow(request).to receive(:integration).and_return(integration) end describe '#as_json' do - context 'integration without fields' do + context 'with integration without fields' do let(:integration) { create(:emails_on_push_integration, push_events: true) } let(:event) { 'push' } @@ -24,7 +24,7 @@ RSpec.describe ServiceEventEntity do end end - context 'integration with fields' do + context 'with integration with fields' do let(:integration) { create(:integrations_slack, note_events: false, note_channel: 'note-channel') } let(:event) { 'note' } diff --git a/spec/serializers/service_field_entity_spec.rb b/spec/serializers/integrations/field_entity_spec.rb index 3a574c522b0..e75dc051f5e 100644 --- a/spec/serializers/service_field_entity_spec.rb +++ b/spec/serializers/integrations/field_entity_spec.rb @@ -2,20 +2,20 @@ require 'spec_helper' -RSpec.describe ServiceFieldEntity do - let(:request) { double('request') } +RSpec.describe Integrations::FieldEntity do + let(:request) { EntityRequest.new(integration: integration) } - subject { described_class.new(field, request: request, service: integration).as_json } + subject { described_class.new(field, request: request, integration: integration).as_json } before do - allow(request).to receive(:service).and_return(integration) + allow(request).to receive(:integration).and_return(integration) end describe '#as_json' do - context 'Jira Service' do + context 'with Jira integration' do let(:integration) { create(:jira_integration) } - context 'field with type text' do + context 'with field with type text' do let(:field) { integration_field('username') } it 'exposes correct attributes' do @@ -36,7 +36,7 @@ RSpec.describe ServiceFieldEntity do end end - context 'field with type password' do + context 'with field with type password' do let(:field) { integration_field('password') } it 'exposes correct attributes but hides password' do @@ -58,10 +58,10 @@ RSpec.describe ServiceFieldEntity do end end - context 'EmailsOnPush Service' do + context 'with EmailsOnPush integration' do let(:integration) { create(:emails_on_push_integration, send_from_committer_email: '1') } - context 'field with type checkbox' do + context 'with field with type checkbox' do let(:field) { integration_field('send_from_committer_email') } it 'exposes correct attributes and casts value to Boolean' do @@ -78,11 +78,14 @@ RSpec.describe ServiceFieldEntity do } is_expected.to include(expected_hash) - expect(subject[:help]).to include("Send notifications from the committer's email address if the domain matches the domain used by your GitLab instance") + expect(subject[:help]).to include( + "Send notifications from the committer's email address if the domain " \ + "matches the domain used by your GitLab instance" + ) end end - context 'field with type select' do + context 'with field with type select' do let(:field) { integration_field('branches_to_be_notified') } it 'exposes correct attributes' do @@ -93,7 +96,12 @@ RSpec.describe ServiceFieldEntity do title: 'Branches for which notifications are to be sent', placeholder: nil, required: nil, - choices: [['All branches', 'all'], ['Default branch', 'default'], ['Protected branches', 'protected'], ['Default branch and protected branches', 'default_and_protected']], + choices: [ + ['All branches', 'all'], + ['Default branch', 'default'], + ['Protected branches', 'protected'], + ['Default branch and protected branches', 'default_and_protected'] + ], help: nil, value: nil, checkbox_label: nil diff --git a/spec/serializers/issue_board_entity_spec.rb b/spec/serializers/issue_board_entity_spec.rb index b8e2bfeaa3d..7a6a496912f 100644 --- a/spec/serializers/issue_board_entity_spec.rb +++ b/spec/serializers/issue_board_entity_spec.rb @@ -43,6 +43,12 @@ RSpec.describe IssueBoardEntity do expect(subject).to include(labels: array_including(hash_including(:id, :title, :color, :description, :text_color, :priority))) end + describe 'type' do + it 'has an issue type' do + expect(subject[:type]).to eq('ISSUE') + end + end + describe 'real_path' do it 'has an issue path' do expect(subject[:real_path]).to eq(project_issue_path(project, resource.iid)) diff --git a/spec/serializers/issue_entity_spec.rb b/spec/serializers/issue_entity_spec.rb index 6ccb3dbc657..9525ed02314 100644 --- a/spec/serializers/issue_entity_spec.rb +++ b/spec/serializers/issue_entity_spec.rb @@ -24,6 +24,12 @@ RSpec.describe IssueEntity do end end + describe 'type' do + it 'has an issue type' do + expect(subject[:type]).to eq('ISSUE') + end + end + it 'has Issuable attributes' do expect(subject).to include(:id, :iid, :author_id, :description, :lock_version, :milestone_id, :title, :updated_by_id, :created_at, :updated_at, :milestone, :labels) diff --git a/spec/serializers/issue_sidebar_basic_entity_spec.rb b/spec/serializers/issue_sidebar_basic_entity_spec.rb index 564ffb1aea9..64a271e359a 100644 --- a/spec/serializers/issue_sidebar_basic_entity_spec.rb +++ b/spec/serializers/issue_sidebar_basic_entity_spec.rb @@ -59,16 +59,6 @@ RSpec.describe IssueSidebarBasicEntity do expect(entity[:current_user][:can_update_escalation_status]).to be(false) end end - - context 'with :incident_escalations feature flag disabled' do - before do - stub_feature_flags(incident_escalations: false) - end - - it 'is not present' do - expect(entity[:current_user]).not_to include(:can_update_escalation_status) - end - end end end end diff --git a/spec/serializers/linked_project_issue_entity_spec.rb b/spec/serializers/linked_project_issue_entity_spec.rb index b28b00bd8e1..c4646754f16 100644 --- a/spec/serializers/linked_project_issue_entity_spec.rb +++ b/spec/serializers/linked_project_issue_entity_spec.rb @@ -25,6 +25,22 @@ RSpec.describe LinkedProjectIssueEntity do it { is_expected.to include(link_type: 'relates_to') } end + describe 'type' do + it 'returns the issue type' do + expect(serialized_entity).to include(type: 'ISSUE') + end + + context 'when related issue is a task' do + before do + related_issue.update!(issue_type: :task, work_item_type: WorkItems::Type.default_by_type(:task)) + end + + it 'returns a work item issue type' do + expect(serialized_entity).to include(type: 'TASK') + end + end + end + describe 'path' do it 'returns an issue path' do expect(serialized_entity).to include(path: project_issue_path(related_issue.project, related_issue.iid)) diff --git a/spec/serializers/merge_request_poll_widget_entity_spec.rb b/spec/serializers/merge_request_poll_widget_entity_spec.rb index 581efd331ef..409585e52f1 100644 --- a/spec/serializers/merge_request_poll_widget_entity_spec.rb +++ b/spec/serializers/merge_request_poll_widget_entity_spec.rb @@ -182,4 +182,40 @@ RSpec.describe MergeRequestPollWidgetEntity do end end end + + describe '#mergeable_discussions_state?' do + context 'when change_response_code_merge_status is true' do + before do + stub_feature_flags(change_response_code_merge_status: true) + end + + it 'returns mergeable discussions state' do + expect(subject[:mergeable_discussions_state]).to eq(true) + end + end + + context 'when change_response_code_merge_status is false' do + context 'when merge request is in a mergeable state' do + before do + stub_feature_flags(change_response_code_merge_status: false) + allow(resource).to receive(:mergeable_discussions_state?).and_return(true) + end + + it 'returns mergeable discussions state' do + expect(subject[:mergeable_discussions_state]).to eq(true) + end + end + + context 'when merge request is not in a mergeable state' do + before do + stub_feature_flags(change_response_code_merge_status: false) + allow(resource).to receive(:mergeable_state?).and_return(false) + end + + it 'returns mergeable discussions state' do + expect(subject[:mergeable_discussions_state]).to eq(false) + end + end + end + end end diff --git a/spec/serializers/merge_request_widget_entity_spec.rb b/spec/serializers/merge_request_widget_entity_spec.rb index f0779f1c57c..292f1c395f5 100644 --- a/spec/serializers/merge_request_widget_entity_spec.rb +++ b/spec/serializers/merge_request_widget_entity_spec.rb @@ -77,46 +77,6 @@ RSpec.describe MergeRequestWidgetEntity do .to eq("/#{resource.project.full_path}/-/merge_requests/#{resource.iid}.diff") end - describe 'codequality report artifacts', :request_store do - let(:merge_base_pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) } - - before do - project.add_developer(user) - - allow(resource).to receive_messages( - merge_base_pipeline: merge_base_pipeline, - base_pipeline: pipeline, - head_pipeline: pipeline - ) - end - - context 'with report artifacts' do - let(:pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) } - let(:generic_job_id) { pipeline.builds.first.id } - let(:merge_base_job_id) { merge_base_pipeline.builds.first.id } - - it 'has head_path and base_path entries' do - expect(subject[:codeclimate][:head_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality") - expect(subject[:codeclimate][:base_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality") - end - - context 'on pipelines for merged results' do - let(:pipeline) { create(:ci_pipeline, :merged_result_pipeline, :with_codequality_reports, project: project) } - - it 'returns URLs from the head_pipeline and merge_base_pipeline' do - expect(subject[:codeclimate][:head_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality") - expect(subject[:codeclimate][:base_path]).to include("/jobs/#{merge_base_job_id}/artifacts/download?file_type=codequality") - end - end - end - - context 'without artifacts' do - it 'does not have data entry' do - expect(subject).not_to include(:codeclimate) - end - end - end - describe 'merge_request_add_ci_config_path' do let!(:project_auto_devops) { create(:project_auto_devops, :disabled, project: project) } diff --git a/spec/serializers/prometheus_alert_entity_spec.rb b/spec/serializers/prometheus_alert_entity_spec.rb index ae8c97401f8..91a1e3377c2 100644 --- a/spec/serializers/prometheus_alert_entity_spec.rb +++ b/spec/serializers/prometheus_alert_entity_spec.rb @@ -18,9 +18,5 @@ RSpec.describe PrometheusAlertEntity do it 'exposes prometheus_alert attributes' do expect(subject).to include(:id, :title, :query, :operator, :threshold, :runbook_url) end - - it 'exposes alert_path' do - expect(subject).to include(:alert_path) - end end end |