summaryrefslogtreecommitdiff
path: root/spec/serializers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
commit36a59d088eca61b834191dacea009677a96c052f (patch)
treee4f33972dab5d8ef79e3944a9f403035fceea43f /spec/serializers
parenta1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff)
downloadgitlab-ce-36a59d088eca61b834191dacea009677a96c052f.tar.gz
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/build_details_entity_spec.rb47
-rw-r--r--spec/serializers/ci/job_entity_spec.rb16
-rw-r--r--spec/serializers/cluster_entity_spec.rb16
-rw-r--r--spec/serializers/discussion_entity_spec.rb18
-rw-r--r--spec/serializers/environment_entity_spec.rb12
-rw-r--r--spec/serializers/issue_board_entity_spec.rb16
-rw-r--r--spec/serializers/issue_entity_spec.rb13
-rw-r--r--spec/serializers/issue_sidebar_basic_entity_spec.rb32
-rw-r--r--spec/serializers/linked_project_issue_entity_spec.rb22
-rw-r--r--spec/serializers/merge_request_user_entity_spec.rb4
-rw-r--r--spec/serializers/release_serializer_spec.rb4
11 files changed, 183 insertions, 17 deletions
diff --git a/spec/serializers/build_details_entity_spec.rb b/spec/serializers/build_details_entity_spec.rb
index da2734feb51..dd8238456aa 100644
--- a/spec/serializers/build_details_entity_spec.rb
+++ b/spec/serializers/build_details_entity_spec.rb
@@ -127,21 +127,48 @@ RSpec.describe BuildDetailsEntity do
end
context 'when the build has failed due to a missing dependency' do
- let!(:test1) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test1', stage_idx: 0) }
- let!(:test2) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test2', stage_idx: 1) }
- let!(:build) { create(:ci_build, :pending, pipeline: pipeline, stage_idx: 2, options: { dependencies: %w(test1 test2) }) }
let(:message) { subject[:callout_message] }
- before do
- build.pipeline.unlocked!
- build.drop!(:missing_dependency_failure)
+ context 'when the dependency is in the same pipeline' do
+ let!(:test1) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test1', stage_idx: 0) }
+ let!(:test2) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test2', stage_idx: 1) }
+ let!(:build) { create(:ci_build, :pending, pipeline: pipeline, stage_idx: 2, options: { dependencies: %w(test1 test2) }) }
+
+ before do
+ build.pipeline.unlocked!
+ build.drop!(:missing_dependency_failure)
+ end
+
+ it { is_expected.to include(failure_reason: 'missing_dependency_failure') }
+
+ it 'includes the failing dependencies in the callout message' do
+ expect(message).to include('test1')
+ expect(message).to include('test2')
+ end
+
+ it 'includes message for list of invalid dependencies' do
+ expect(message).to include('could not retrieve the needed artifacts:')
+ end
end
- it { is_expected.to include(failure_reason: 'missing_dependency_failure') }
+ context 'when dependency is not found' do
+ let!(:build) { create(:ci_build, :pending, pipeline: pipeline, stage_idx: 2, options: { dependencies: %w(test1 test2) }) }
+
+ before do
+ build.pipeline.unlocked!
+ build.drop!(:missing_dependency_failure)
+ end
- it 'includes the failing dependencies in the callout message' do
- expect(message).to include('test1')
- expect(message).to include('test2')
+ it { is_expected.to include(failure_reason: 'missing_dependency_failure') }
+
+ it 'excludes the failing dependencies in the callout message' do
+ expect(message).not_to include('test1')
+ expect(message).not_to include('test2')
+ end
+
+ it 'includes the correct punctuation in the message' do
+ expect(message).to include('could not retrieve the needed artifacts.')
+ end
end
end
diff --git a/spec/serializers/ci/job_entity_spec.rb b/spec/serializers/ci/job_entity_spec.rb
index ba68b9a6c16..05b9e38444c 100644
--- a/spec/serializers/ci/job_entity_spec.rb
+++ b/spec/serializers/ci/job_entity_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Ci::JobEntity do
let(:user) { create(:user) }
- let(:job) { create(:ci_build) }
+ let(:job) { create(:ci_build, :running) }
let(:project) { job.project }
let(:request) { double('request') }
@@ -21,6 +21,11 @@ RSpec.describe Ci::JobEntity do
subject { entity.as_json }
+ it 'contains started' do
+ expect(subject).to include(:started)
+ expect(subject[:started]).to eq(true)
+ end
+
it 'contains complete to indicate if a pipeline is completed' do
expect(subject).to include(:complete)
end
@@ -128,6 +133,15 @@ RSpec.describe Ci::JobEntity do
end
end
+ context 'when job is running' do
+ let_it_be(:job) { create(:ci_build, :running) }
+
+ it 'contains started_at' do
+ expect(subject[:started]).to be_truthy
+ expect(subject[:started_at]).to eq(job.started_at)
+ end
+ end
+
context 'when job is generic commit status' do
let(:job) { create(:generic_commit_status, target_url: 'http://google.com') }
diff --git a/spec/serializers/cluster_entity_spec.rb b/spec/serializers/cluster_entity_spec.rb
index ee1388024ea..514828e3c69 100644
--- a/spec/serializers/cluster_entity_spec.rb
+++ b/spec/serializers/cluster_entity_spec.rb
@@ -77,6 +77,14 @@ RSpec.describe ClusterEntity do
expect(subject[:gitlab_managed_apps_logs_path]).to eq(log_explorer_path)
end
+
+ context 'when feature is disabled' do
+ before do
+ stub_feature_flags(monitor_logging: false)
+ end
+
+ specify { is_expected.not_to include(:gitlab_managed_apps_logs_path) }
+ end
end
context 'enable_advanced_logs_querying' do
@@ -98,6 +106,14 @@ RSpec.describe ClusterEntity do
expect(subject[:enable_advanced_logs_querying]).to be true
end
end
+
+ context 'when feature is disabled' do
+ before do
+ stub_feature_flags(monitor_logging: false)
+ end
+
+ specify { is_expected.not_to include(:enable_advanced_logs_querying) }
+ end
end
end
end
diff --git a/spec/serializers/discussion_entity_spec.rb b/spec/serializers/discussion_entity_spec.rb
index 0645d19da5b..0fe10ed2c6d 100644
--- a/spec/serializers/discussion_entity_spec.rb
+++ b/spec/serializers/discussion_entity_spec.rb
@@ -5,8 +5,11 @@ require 'spec_helper'
RSpec.describe DiscussionEntity do
include RepoHelpers
- let(:user) { create(:user) }
- let(:note) { create(:discussion_note_on_merge_request) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:group) { create(:group) }
+ let_it_be(:project) { create(:project, namespace: group) }
+
+ let(:note) { create(:discussion_note_on_merge_request, project: project) }
let(:discussion) { note.discussion }
let(:request) { double('request', note_entity: ProjectNoteEntity) }
let(:controller) { double('controller') }
@@ -50,10 +53,15 @@ RSpec.describe DiscussionEntity do
.to match_schema('entities/note_user_entity')
end
+ it 'exposes the url for custom award emoji' do
+ custom_emoji = create(:custom_emoji, group: group)
+ create(:award_emoji, awardable: note, name: custom_emoji.name)
+
+ expect(subject[:notes].last[:award_emoji].first.keys).to include(:url)
+ end
+
context 'when is LegacyDiffDiscussion' do
- let(:project) { create(:project) }
- let(:merge_request) { create(:merge_request, source_project: project) }
- let(:discussion) { create(:legacy_diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion }
+ let(:discussion) { create(:legacy_diff_note_on_merge_request, noteable: note.noteable, project: project).to_discussion }
it 'exposes correct attributes' do
expect(subject.keys.sort).to include(
diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb
index a59107ad309..9b6a293da16 100644
--- a/spec/serializers/environment_entity_spec.rb
+++ b/spec/serializers/environment_entity_spec.rb
@@ -166,6 +166,18 @@ RSpec.describe EnvironmentEntity do
expect(subject[:logs_api_path]).to eq(elasticsearch_project_logs_path(project, environment_name: environment.name, format: :json))
end
+
+ context 'with feature flag disabled' do
+ before do
+ stub_feature_flags(monitor_logging: false)
+ end
+
+ 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
end
end
diff --git a/spec/serializers/issue_board_entity_spec.rb b/spec/serializers/issue_board_entity_spec.rb
index 30423ceba6d..b8e2bfeaa3d 100644
--- a/spec/serializers/issue_board_entity_spec.rb
+++ b/spec/serializers/issue_board_entity_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe IssueBoardEntity do
+ include Gitlab::Routing.url_helpers
+
let_it_be(:project) { create(:project) }
let_it_be(:resource) { create(:issue, project: project) }
let_it_be(:user) { create(:user) }
@@ -40,4 +42,18 @@ RSpec.describe IssueBoardEntity do
expect(subject).to include(labels: array_including(hash_including(:id, :title, :color, :description, :text_color, :priority)))
end
+
+ describe 'real_path' do
+ it 'has an issue path' do
+ expect(subject[:real_path]).to eq(project_issue_path(project, resource.iid))
+ end
+
+ context 'when issue is of type task' do
+ let(:resource) { create(:issue, :task, project: project) }
+
+ it 'has a work item path' do
+ expect(subject[:real_path]).to eq(project_work_items_path(project, resource.id))
+ end
+ end
+ end
end
diff --git a/spec/serializers/issue_entity_spec.rb b/spec/serializers/issue_entity_spec.rb
index 76f8cf644c6..6ccb3dbc657 100644
--- a/spec/serializers/issue_entity_spec.rb
+++ b/spec/serializers/issue_entity_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe IssueEntity do
+ include Gitlab::Routing.url_helpers
+
let(:project) { create(:project) }
let(:resource) { create(:issue, project: project) }
let(:user) { create(:user) }
@@ -11,6 +13,17 @@ RSpec.describe IssueEntity do
subject { described_class.new(resource, request: request).as_json }
+ describe 'web_url' do
+ context 'when issue is of type task' do
+ let(:resource) { create(:issue, :task, project: project) }
+
+ # This was already a path and not a url when the work items change was introduced
+ it 'has a work item path' do
+ expect(subject[:web_url]).to eq(project_work_items_path(project, resource.id))
+ end
+ 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 716c97f72af..564ffb1aea9 100644
--- a/spec/serializers/issue_sidebar_basic_entity_spec.rb
+++ b/spec/serializers/issue_sidebar_basic_entity_spec.rb
@@ -94,5 +94,37 @@ RSpec.describe IssueSidebarBasicEntity do
expect(entity[:show_crm_contacts]).to be(expected)
end
end
+
+ context 'in subgroup' do
+ let(:subgroup_project) { create(:project, :repository, group: subgroup) }
+ let(:subgroup_issue) { create(:issue, project: subgroup_project) }
+ let(:serializer) { IssueSerializer.new(current_user: user, project: subgroup_project) }
+
+ subject(:entity) { serializer.represent(subgroup_issue, serializer: 'sidebar') }
+
+ before do
+ subgroup_project.root_ancestor.add_reporter(user)
+ end
+
+ context 'with crm enabled' do
+ let(:subgroup) { create(:group, :crm_enabled, parent: group) }
+
+ it 'is true' do
+ allow(CustomerRelations::Contact).to receive(:exists_for_group?).with(group).and_return(true)
+
+ expect(entity[:show_crm_contacts]).to be_truthy
+ end
+ end
+
+ context 'with crm disabled' do
+ let(:subgroup) { create(:group, parent: group) }
+
+ it 'is false' do
+ allow(CustomerRelations::Contact).to receive(:exists_for_group?).with(group).and_return(true)
+
+ expect(entity[:show_crm_contacts]).to be_falsy
+ 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 864b5c45599..b28b00bd8e1 100644
--- a/spec/serializers/linked_project_issue_entity_spec.rb
+++ b/spec/serializers/linked_project_issue_entity_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe LinkedProjectIssueEntity do
+ include Gitlab::Routing.url_helpers
+
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:issue_link) { create(:issue_link) }
@@ -17,7 +19,25 @@ RSpec.describe LinkedProjectIssueEntity do
issue_link.target.project.add_developer(user)
end
+ subject(:serialized_entity) { entity.as_json }
+
describe 'issue_link_type' do
- it { expect(entity.as_json).to include(link_type: 'relates_to') }
+ it { is_expected.to include(link_type: 'relates_to') }
+ 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))
+ 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 items path' do
+ expect(serialized_entity).to include(path: project_work_items_path(related_issue.project, related_issue.id))
+ end
+ end
end
end
diff --git a/spec/serializers/merge_request_user_entity_spec.rb b/spec/serializers/merge_request_user_entity_spec.rb
index 72d1b0c0dd2..7877356ff0f 100644
--- a/spec/serializers/merge_request_user_entity_spec.rb
+++ b/spec/serializers/merge_request_user_entity_spec.rb
@@ -58,6 +58,10 @@ RSpec.describe MergeRequestUserEntity do
end
context 'attention_requested' do
+ before do
+ merge_request.find_assignee(user).update!(state: :attention_requested)
+ end
+
it { is_expected.to include(attention_requested: true ) }
end
diff --git a/spec/serializers/release_serializer_spec.rb b/spec/serializers/release_serializer_spec.rb
index 518d281f370..b31172c3a50 100644
--- a/spec/serializers/release_serializer_spec.rb
+++ b/spec/serializers/release_serializer_spec.rb
@@ -19,6 +19,10 @@ RSpec.describe ReleaseSerializer do
it 'serializes the label object' do
expect(subject[:tag]).to eq resource.tag
end
+
+ it 'does not expose git-sha as sensitive information' do
+ expect(subject[:sha]).to be_nil
+ end
end
context 'when multiple objects are being serialized' do