diff options
Diffstat (limited to 'spec/serializers')
-rw-r--r-- | spec/serializers/base_discussion_entity_spec.rb | 69 | ||||
-rw-r--r-- | spec/serializers/diff_file_entity_spec.rb | 11 | ||||
-rw-r--r-- | spec/serializers/diffs_entity_spec.rb | 50 | ||||
-rw-r--r-- | spec/serializers/discussion_entity_spec.rb | 4 | ||||
-rw-r--r-- | spec/serializers/environment_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/merge_request_widget_entity_spec.rb | 27 | ||||
-rw-r--r-- | spec/serializers/move_to_project_entity_spec.rb | 6 | ||||
-rw-r--r-- | spec/serializers/paginated_diff_entity_spec.rb | 46 | ||||
-rw-r--r-- | spec/serializers/test_case_entity_spec.rb | 13 | ||||
-rw-r--r-- | spec/serializers/test_suite_comparer_entity_spec.rb | 104 |
10 files changed, 203 insertions, 129 deletions
diff --git a/spec/serializers/base_discussion_entity_spec.rb b/spec/serializers/base_discussion_entity_spec.rb new file mode 100644 index 00000000000..5f483da4113 --- /dev/null +++ b/spec/serializers/base_discussion_entity_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BaseDiscussionEntity do + let_it_be(:user) { create(:user) } + let_it_be(:note) { create(:discussion_note_on_merge_request) } + + let(:request) { double('request', note_entity: ProjectNoteEntity) } + let(:controller) { double('controller') } + let(:entity) { described_class.new(discussion, request: request, context: controller) } + let(:discussion) { note.discussion } + + subject { entity.as_json } + + before do + allow(controller).to receive(:render_to_string) + allow(request).to receive(:current_user).and_return(user) + allow(request).to receive(:noteable).and_return(note.noteable) + end + + it 'exposes correct attributes' do + expect(subject.keys.sort).to include( + :commit_id, + :confidential, + :diff_discussion, + :discussion_path, + :expanded, + :for_commit, + :id, + :individual_note, + :resolvable, + :resolve_path, + :resolve_with_issue_path + ) + 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 } + + it 'exposes correct attributes' do + expect(subject.keys.sort).to include( + :commit_id, + :diff_discussion, + :discussion_path, + :expanded, + :for_commit, + :id, + :individual_note + ) + end + end + + context 'when diff file is present' do + let(:note) { create(:diff_note_on_merge_request) } + + it 'exposes diff file attributes' do + expect(subject.keys.sort).to include( + :active, + :diff_file, + :line_code, + :position, + :truncated_diff_lines + ) + end + end +end diff --git a/spec/serializers/diff_file_entity_spec.rb b/spec/serializers/diff_file_entity_spec.rb index bebe2e2dfb5..1b8456e5c49 100644 --- a/spec/serializers/diff_file_entity_spec.rb +++ b/spec/serializers/diff_file_entity_spec.rb @@ -69,4 +69,15 @@ RSpec.describe DiffFileEntity do end end end + + describe '#is_fully_expanded' do + context 'file with a conflict' do + let(:options) { { conflicts: { diff_file.new_path => double(diff_lines_for_serializer: []) } } } + + it 'returns false' do + expect(diff_file).not_to receive(:fully_expanded?) + expect(subject[:is_fully_expanded]).to eq(false) + end + end + end end diff --git a/spec/serializers/diffs_entity_spec.rb b/spec/serializers/diffs_entity_spec.rb index 5928a1c24b3..7569493573b 100644 --- a/spec/serializers/diffs_entity_spec.rb +++ b/spec/serializers/diffs_entity_spec.rb @@ -8,9 +8,12 @@ RSpec.describe DiffsEntity do let(:request) { EntityRequest.new(project: project, current_user: user) } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let(:merge_request_diffs) { merge_request.merge_request_diffs } + let(:options) do + { request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs } + end let(:entity) do - described_class.new(merge_request_diffs.first.diffs, request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs) + described_class.new(merge_request_diffs.first.diffs, options) end context 'as json' do @@ -68,5 +71,50 @@ RSpec.describe DiffsEntity do end end end + + context 'when there are conflicts' do + let(:diff_files) { merge_request_diffs.first.diffs.diff_files } + let(:diff_file_with_conflict) { diff_files.to_a.last } + let(:diff_file_without_conflict) { diff_files.to_a[-2] } + + let(:resolvable_conflicts) { true } + let(:conflict_file) { double(our_path: diff_file_with_conflict.new_path) } + let(:conflicts) { double(conflicts: double(files: [conflict_file]), can_be_resolved_in_ui?: resolvable_conflicts) } + + let(:merge_ref_head_diff) { true } + let(:options) { super().merge(merge_ref_head_diff: merge_ref_head_diff) } + + before do + allow(MergeRequests::Conflicts::ListService).to receive(:new).and_return(conflicts) + end + + it 'conflicts are highlighted' do + expect(conflict_file).to receive(:diff_lines_for_serializer) + expect(diff_file_with_conflict).not_to receive(:diff_lines_for_serializer) + expect(diff_file_without_conflict).to receive(:diff_lines_for_serializer).twice # for highlighted_diff_lines and is_fully_expanded + + subject + end + + context 'merge ref head diff is not chosen to be displayed' do + let(:merge_ref_head_diff) { false } + + it 'conflicts are not calculated' do + expect(MergeRequests::Conflicts::ListService).not_to receive(:new) + end + end + + context 'when conflicts cannot be resolved' do + let(:resolvable_conflicts) { false } + + it 'conflicts are not highlighted' do + expect(conflict_file).not_to receive(:diff_lines_for_serializer) + expect(diff_file_with_conflict).to receive(:diff_lines_for_serializer).twice # for highlighted_diff_lines and is_fully_expanded + expect(diff_file_without_conflict).to receive(:diff_lines_for_serializer).twice # for highlighted_diff_lines and is_fully_expanded + + subject + end + end + end end end diff --git a/spec/serializers/discussion_entity_spec.rb b/spec/serializers/discussion_entity_spec.rb index e1734d5290f..0645d19da5b 100644 --- a/spec/serializers/discussion_entity_spec.rb +++ b/spec/serializers/discussion_entity_spec.rb @@ -39,6 +39,10 @@ RSpec.describe DiscussionEntity do ) end + it 'does not include base discussion in the notes' do + expect(subject[:notes].first.keys).not_to include(:base_discussion) + end + it 'resolved_by matches note_user_entity schema' do Notes::ResolveService.new(note.project, user).execute(note) diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb index c90f771335e..f5d6706a844 100644 --- a/spec/serializers/environment_entity_spec.rb +++ b/spec/serializers/environment_entity_spec.rb @@ -25,7 +25,7 @@ RSpec.describe EnvironmentEntity do end it 'exposes core elements of environment' do - expect(subject).to include(:id, :name, :state, :environment_path) + expect(subject).to include(:id, :global_id, :name, :state, :environment_path) end it 'exposes folder path' do diff --git a/spec/serializers/merge_request_widget_entity_spec.rb b/spec/serializers/merge_request_widget_entity_spec.rb index 5cad35eaedf..3f7d5542ae8 100644 --- a/spec/serializers/merge_request_widget_entity_spec.rb +++ b/spec/serializers/merge_request_widget_entity_spec.rb @@ -106,29 +106,16 @@ RSpec.describe MergeRequestWidgetEntity do 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 be_present - expect(subject[:codeclimate][:base_path]).to be_present + 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_report, project: project) } - context 'with merge_base_pipelines enabled' do - 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 - - context 'with merge_base_pipelines disabled' do - before do - stub_feature_flags(merge_base_pipelines: false) - end - - it 'returns URLs from the head_pipeline and 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/#{generic_job_id}/artifacts/download?file_type=codequality") - end + 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 @@ -333,6 +320,10 @@ RSpec.describe MergeRequestWidgetEntity do end context 'when suggest pipeline feature is not enabled' do + before do + stub_feature_flags(suggest_pipeline: false) + end + it 'provides no valid value for user callout path' do expect(subject[:user_callouts_path]).to be_nil end diff --git a/spec/serializers/move_to_project_entity_spec.rb b/spec/serializers/move_to_project_entity_spec.rb index a14bc3ae622..fad49ceb067 100644 --- a/spec/serializers/move_to_project_entity_spec.rb +++ b/spec/serializers/move_to_project_entity_spec.rb @@ -12,8 +12,12 @@ RSpec.describe MoveToProjectEntity do expect(subject[:id]).to eq(project.id) end - it 'includes the full path' do + it 'includes the human-readable full path' do expect(subject[:name_with_namespace]).to eq(project.name_with_namespace) end + + it 'includes the full path' do + expect(subject[:full_path]).to eq(project.full_path) + end end end diff --git a/spec/serializers/paginated_diff_entity_spec.rb b/spec/serializers/paginated_diff_entity_spec.rb index 821ed34d3ec..551b392c9e9 100644 --- a/spec/serializers/paginated_diff_entity_spec.rb +++ b/spec/serializers/paginated_diff_entity_spec.rb @@ -31,4 +31,50 @@ RSpec.describe PaginatedDiffEntity do total_pages: 7 ) end + + context 'when there are conflicts' do + let(:diff_batch) { merge_request.merge_request_diff.diffs_in_batch(7, 3, diff_options: nil) } + let(:diff_files) { diff_batch.diff_files.to_a } + let(:diff_file_with_conflict) { diff_files.last } + let(:diff_file_without_conflict) { diff_files.first } + + let(:resolvable_conflicts) { true } + let(:conflict_file) { double(our_path: diff_file_with_conflict.new_path) } + let(:conflicts) { double(conflicts: double(files: [conflict_file]), can_be_resolved_in_ui?: resolvable_conflicts) } + + let(:merge_ref_head_diff) { true } + let(:options) { super().merge(merge_ref_head_diff: merge_ref_head_diff) } + + before do + allow(MergeRequests::Conflicts::ListService).to receive(:new).and_return(conflicts) + end + + it 'conflicts are highlighted' do + expect(conflict_file).to receive(:diff_lines_for_serializer) + expect(diff_file_with_conflict).not_to receive(:diff_lines_for_serializer) + expect(diff_file_without_conflict).to receive(:diff_lines_for_serializer).twice # for highlighted_diff_lines and is_fully_expanded + + subject + end + + context 'merge ref head diff is not chosen to be displayed' do + let(:merge_ref_head_diff) { false } + + it 'conflicts are not calculated' do + expect(MergeRequests::Conflicts::ListService).not_to receive(:new) + end + end + + context 'when conflicts cannot be resolved' do + let(:resolvable_conflicts) { false } + + it 'conflicts are not highlighted' do + expect(conflict_file).not_to receive(:diff_lines_for_serializer) + expect(diff_file_with_conflict).to receive(:diff_lines_for_serializer).twice # for highlighted_diff_lines and is_fully_expanded + expect(diff_file_without_conflict).to receive(:diff_lines_for_serializer).twice # for highlighted_diff_lines and is_fully_expanded + + subject + end + end + end end diff --git a/spec/serializers/test_case_entity_spec.rb b/spec/serializers/test_case_entity_spec.rb index 45e63e3feec..e2b0f722f41 100644 --- a/spec/serializers/test_case_entity_spec.rb +++ b/spec/serializers/test_case_entity_spec.rb @@ -27,12 +27,17 @@ RSpec.describe TestCaseEntity do context 'when test case is failed' do let(:test_case) { create_test_case_rspec_failed } + before do + test_case.set_recent_failures(3, 'master') + end + it 'contains correct test case details' do expect(subject[:status]).to eq('failed') expect(subject[:name]).to eq('Test#sum when a is 1 and b is 3 returns summary') expect(subject[:classname]).to eq('spec.test_spec') expect(subject[:file]).to eq('./spec/test_spec.rb') expect(subject[:execution_time]).to eq(2.22) + expect(subject[:recent_failures]).to eq({ count: 3, base_branch: 'master' }) end end @@ -42,7 +47,7 @@ RSpec.describe TestCaseEntity do end context 'when attachment is present' do - let(:test_case) { build(:test_case, :failed_with_attachment, job: job) } + let(:test_case) { build(:report_test_case, :failed_with_attachment, job: job) } it 'returns the attachment_url' do expect(subject).to include(:attachment_url) @@ -50,7 +55,7 @@ RSpec.describe TestCaseEntity do end context 'when attachment is not present' do - let(:test_case) { build(:test_case, job: job) } + let(:test_case) { build(:report_test_case, job: job) } it 'returns a nil attachment_url' do expect(subject[:attachment_url]).to be_nil @@ -64,7 +69,7 @@ RSpec.describe TestCaseEntity do end context 'when attachment is present' do - let(:test_case) { build(:test_case, :failed_with_attachment, job: job) } + let(:test_case) { build(:report_test_case, :failed_with_attachment, job: job) } it 'returns no attachment_url' do expect(subject).not_to include(:attachment_url) @@ -72,7 +77,7 @@ RSpec.describe TestCaseEntity do end context 'when attachment is not present' do - let(:test_case) { build(:test_case, job: job) } + let(:test_case) { build(:report_test_case, job: job) } it 'returns no attachment_url' do expect(subject).not_to include(:attachment_url) diff --git a/spec/serializers/test_suite_comparer_entity_spec.rb b/spec/serializers/test_suite_comparer_entity_spec.rb index 882991a6208..a63f5683779 100644 --- a/spec/serializers/test_suite_comparer_entity_spec.rb +++ b/spec/serializers/test_suite_comparer_entity_spec.rb @@ -100,109 +100,5 @@ RSpec.describe TestSuiteComparerEntity do expect(subject[:existing_failures]).to be_empty end end - - context 'limits amount of tests returned' do - before do - stub_const('TestSuiteComparerEntity::DEFAULT_MAX_TESTS', 2) - stub_const('TestSuiteComparerEntity::DEFAULT_MIN_TESTS', 1) - end - - context 'prefers new over existing and resolved' do - before do - 3.times { add_new_failure } - 3.times { add_new_error } - 3.times { add_existing_failure } - 3.times { add_existing_error } - 3.times { add_resolved_failure } - 3.times { add_resolved_error } - end - - it 'returns 2 of each new category, and 1 of each resolved and existing' do - expect(subject[:summary]).to include(total: 18, resolved: 6, failed: 6, errored: 6) - expect(subject[:new_failures].count).to eq(2) - expect(subject[:new_errors].count).to eq(2) - expect(subject[:existing_failures].count).to eq(1) - expect(subject[:existing_errors].count).to eq(1) - expect(subject[:resolved_failures].count).to eq(1) - expect(subject[:resolved_errors].count).to eq(1) - end - end - - context 'prefers existing over resolved' do - before do - 3.times { add_existing_failure } - 3.times { add_existing_error } - 3.times { add_resolved_failure } - 3.times { add_resolved_error } - end - - it 'returns 2 of each existing category, and 1 of each resolved' do - expect(subject[:summary]).to include(total: 12, resolved: 6, failed: 3, errored: 3) - expect(subject[:new_failures].count).to eq(0) - expect(subject[:new_errors].count).to eq(0) - expect(subject[:existing_failures].count).to eq(2) - expect(subject[:existing_errors].count).to eq(2) - expect(subject[:resolved_failures].count).to eq(1) - expect(subject[:resolved_errors].count).to eq(1) - end - end - - context 'limits amount of resolved' do - before do - 3.times { add_resolved_failure } - 3.times { add_resolved_error } - end - - it 'returns 2 of each resolved category' do - expect(subject[:summary]).to include(total: 6, resolved: 6, failed: 0, errored: 0) - expect(subject[:new_failures].count).to eq(0) - expect(subject[:new_errors].count).to eq(0) - expect(subject[:existing_failures].count).to eq(0) - expect(subject[:existing_errors].count).to eq(0) - expect(subject[:resolved_failures].count).to eq(2) - expect(subject[:resolved_errors].count).to eq(2) - end - end - - private - - def add_new_failure - failed_case = create_test_case_rspec_failed(SecureRandom.hex) - head_suite.add_test_case(failed_case) - end - - def add_new_error - error_case = create_test_case_rspec_error(SecureRandom.hex) - head_suite.add_test_case(error_case) - end - - def add_existing_failure - failed_case = create_test_case_rspec_failed(SecureRandom.hex) - base_suite.add_test_case(failed_case) - head_suite.add_test_case(failed_case) - end - - def add_existing_error - error_case = create_test_case_rspec_error(SecureRandom.hex) - base_suite.add_test_case(error_case) - head_suite.add_test_case(error_case) - end - - def add_resolved_failure - case_name = SecureRandom.hex - failed_case = create_test_case_java_failed(case_name) - success_case = create_test_case_java_success(case_name) - base_suite.add_test_case(failed_case) - head_suite.add_test_case(success_case) - end - - def add_resolved_error - case_name = SecureRandom.hex - error_case = create_test_case_java_error(case_name) - success_case = create_test_case_java_success(case_name) - base_suite.add_test_case(error_case) - head_suite.add_test_case(success_case) - end - end end end |