diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-13 00:09:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-13 00:09:19 +0300 |
commit | 458209640c39594084bda2b57d77a08bce6efc36 (patch) | |
tree | 9fcb3e77cce65baca1d3af3ab350072621d84716 /spec | |
parent | f4182abcb628e20978f011376811bbf8e644eff5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin/dashboard_controller_spec.rb | 12 | ||||
-rw-r--r-- | spec/controllers/admin/users_controller_spec.rb | 9 | ||||
-rw-r--r-- | spec/frontend/reports/components/grouped_test_reports_app_spec.js | 79 | ||||
-rw-r--r-- | spec/frontend/reports/mock_data/recent_failures_report.json | 46 | ||||
-rw-r--r-- | spec/frontend/reports/store/mutations_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/reports/store/utils_spec.js | 48 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/all_models.yml | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/wrapper_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_spec.rb | 5 | ||||
-rw-r--r-- | spec/mailers/devise_mailer_spec.rb | 30 | ||||
-rw-r--r-- | spec/services/users/approve_service_spec.rb | 5 |
11 files changed, 239 insertions, 4 deletions
diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb index 283d82a3ab8..bfbd2ca946f 100644 --- a/spec/controllers/admin/dashboard_controller_spec.rb +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -4,12 +4,20 @@ require 'spec_helper' RSpec.describe Admin::DashboardController do describe '#index' do + before do + sign_in(create(:admin)) + end + + it 'retrieves Redis versions' do + get :index + + expect(assigns[:redis_versions].length).to eq(1) + end + context 'with pending_delete projects' do render_views it 'does not retrieve projects that are pending deletion' do - sign_in(create(:admin)) - project = create(:project) pending_delete_project = create(:project, pending_delete: true) diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 5f550bb8464..d0d1fa6a6bc 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -116,6 +116,11 @@ RSpec.describe Admin::UsersController do expect(user).to be_active expect(flash[:notice]).to eq('Successfully approved') end + + it 'emails the user on approval' do + expect(DeviseMailer).to receive(:user_admin_approval).with(user).and_call_original + expect { subject }.to have_enqueued_mail(DeviseMailer, :user_admin_approval) + end end context 'when unsuccessful' do @@ -133,6 +138,10 @@ RSpec.describe Admin::UsersController do user.reload expect(user).not_to be_active end + + it 'does not email the pending user' do + expect { subject }.not_to have_enqueued_mail(DeviseMailer, :user_admin_approval) + end end end diff --git a/spec/frontend/reports/components/grouped_test_reports_app_spec.js b/spec/frontend/reports/components/grouped_test_reports_app_spec.js index 14c984ce32f..ae2718db17f 100644 --- a/spec/frontend/reports/components/grouped_test_reports_app_spec.js +++ b/spec/frontend/reports/components/grouped_test_reports_app_spec.js @@ -7,6 +7,7 @@ import { getStoreConfig } from '~/reports/store'; import { failedReport } from '../mock_data/mock_data'; import successTestReports from '../mock_data/no_failures_report.json'; import newFailedTestReports from '../mock_data/new_failures_report.json'; +import recentFailuresTestReports from '../mock_data/recent_failures_report.json'; import newErrorsTestReports from '../mock_data/new_errors_report.json'; import mixedResultsTestReports from '../mock_data/new_and_fixed_failures_report.json'; import resolvedFailures from '../mock_data/resolved_failures.json'; @@ -21,7 +22,7 @@ describe('Grouped test reports app', () => { let wrapper; let mockStore; - const mountComponent = ({ props = { pipelinePath } } = {}) => { + const mountComponent = ({ props = { pipelinePath }, testFailureHistory = false } = {}) => { wrapper = mount(Component, { store: mockStore, localVue, @@ -30,6 +31,11 @@ describe('Grouped test reports app', () => { pipelinePath, ...props, }, + provide: { + glFeatures: { + testFailureHistory, + }, + }, }); }; @@ -234,6 +240,77 @@ describe('Grouped test reports app', () => { }); }); + describe('recent failures counts', () => { + describe('with recent failures counts', () => { + beforeEach(() => { + setReports(recentFailuresTestReports); + }); + + describe('with feature flag enabled', () => { + beforeEach(() => { + mountComponent({ testFailureHistory: true }); + }); + + it('renders the recently failed tests summary', () => { + expect(findHeader().text()).toContain( + '2 out of 3 failed tests have failed more than once in the last 14 days', + ); + }); + + it('renders the recently failed count on the test suite', () => { + expect(findSummaryDescription().text()).toContain( + '1 out of 2 failed tests has failed more than once in the last 14 days', + ); + }); + + it('renders the recent failures count on the test case', () => { + expect(findIssueDescription().text()).toContain('Failed 8 times in the last 14 days'); + }); + }); + + describe('with feature flag disabled', () => { + beforeEach(() => { + mountComponent({ testFailureHistory: false }); + }); + + it('does not render the recently failed tests summary', () => { + expect(findHeader().text()).not.toContain('failed more than once in the last 14 days'); + }); + + it('does not render the recently failed count on the test suite', () => { + expect(findSummaryDescription().text()).not.toContain( + 'failed more than once in the last 14 days', + ); + }); + + it('renders the recent failures count on the test case', () => { + expect(findIssueDescription().text()).not.toContain('in the last 14 days'); + }); + }); + }); + + describe('without recent failures counts', () => { + beforeEach(() => { + setReports(mixedResultsTestReports); + mountComponent(); + }); + + it('does not render the recently failed tests summary', () => { + expect(findHeader().text()).not.toContain('failed more than once in the last 14 days'); + }); + + it('does not render the recently failed count on the test suite', () => { + expect(findSummaryDescription().text()).not.toContain( + 'failed more than once in the last 14 days', + ); + }); + + it('does not render the recent failures count on the test case', () => { + expect(findIssueDescription().text()).not.toContain('in the last 14 days'); + }); + }); + }); + describe('with a report that failed to load', () => { beforeEach(() => { setReports(failedReport); diff --git a/spec/frontend/reports/mock_data/recent_failures_report.json b/spec/frontend/reports/mock_data/recent_failures_report.json new file mode 100644 index 00000000000..a47bc30a8e5 --- /dev/null +++ b/spec/frontend/reports/mock_data/recent_failures_report.json @@ -0,0 +1,46 @@ +{ + "summary": { "total": 11, "resolved": 0, "errored": 0, "failed": 3, "recentlyFailed": 2 }, + "suites": [ + { + "name": "rspec:pg", + "summary": { "total": 8, "resolved": 0, "errored": 0, "failed": 2, "recentlyFailed": 1 }, + "new_failures": [ + { + "result": "failure", + "name": "Test#sum when a is 1 and b is 2 returns summary", + "execution_time": 0.009411, + "system_output": "Failure/Error: is_expected.to eq(3)\n\n expected: 3\n got: -1\n\n (compared using ==)\n./spec/test_spec.rb:12:in `block (4 levels) in <top (required)>'", + "recent_failures": 8 + }, + { + "result": "failure", + "name": "Test#sum when a is 100 and b is 200 returns summary", + "execution_time": 0.000162, + "system_output": "Failure/Error: is_expected.to eq(300)\n\n expected: 300\n got: -100\n\n (compared using ==)\n./spec/test_spec.rb:21:in `block (4 levels) in <top (required)>'" + } + ], + "resolved_failures": [], + "existing_failures": [], + "new_errors": [], + "resolved_errors": [], + "existing_errors": [] + }, + { + "name": "java ant", + "summary": { "total": 3, "resolved": 0, "errored": 0, "failed": 1, "recentlyFailed": 1 }, + "new_failures": [ + { + "result": "failure", + "name": "Test#sum when a is 100 and b is 200 returns summary", + "execution_time": 0.000562, + "recent_failures": 3 + } + ], + "resolved_failures": [], + "existing_failures": [], + "new_errors": [], + "resolved_errors": [], + "existing_errors": [] + } + ] +} diff --git a/spec/frontend/reports/store/mutations_spec.js b/spec/frontend/reports/store/mutations_spec.js index 9446cd454ab..82a399c876d 100644 --- a/spec/frontend/reports/store/mutations_spec.js +++ b/spec/frontend/reports/store/mutations_spec.js @@ -46,6 +46,7 @@ describe('Reports Store Mutations', () => { name: 'StringHelper#concatenate when a is git and b is lab returns summary', execution_time: 0.0092435, system_output: "Failure/Error: is_expected.to eq('gitlab')", + recent_failures: 4, }, ], resolved_failures: [ @@ -82,6 +83,7 @@ describe('Reports Store Mutations', () => { expect(stateCopy.summary.total).toEqual(mockedResponse.summary.total); expect(stateCopy.summary.resolved).toEqual(mockedResponse.summary.resolved); expect(stateCopy.summary.failed).toEqual(mockedResponse.summary.failed); + expect(stateCopy.summary.recentlyFailed).toEqual(1); }); it('should set reports', () => { diff --git a/spec/frontend/reports/store/utils_spec.js b/spec/frontend/reports/store/utils_spec.js index 9ae456658dc..8977268115e 100644 --- a/spec/frontend/reports/store/utils_spec.js +++ b/spec/frontend/reports/store/utils_spec.js @@ -168,6 +168,54 @@ describe('Reports store utils', () => { }); }); + describe('recentFailuresTextBuilder', () => { + it.each` + recentlyFailed | failed | expected + ${0} | ${1} | ${''} + ${1} | ${1} | ${'1 out of 1 failed test has failed more than once in the last 14 days'} + ${1} | ${2} | ${'1 out of 2 failed tests has failed more than once in the last 14 days'} + ${2} | ${3} | ${'2 out of 3 failed tests have failed more than once in the last 14 days'} + `( + 'should render summary for $recentlyFailed out of $failed failures', + ({ recentlyFailed, failed, expected }) => { + const result = utils.recentFailuresTextBuilder({ recentlyFailed, failed }); + + expect(result).toBe(expected); + }, + ); + }); + + describe('countRecentlyFailedTests', () => { + it('counts tests with more than one recent failure in a report', () => { + const report = { + new_failures: [{ recent_failures: 2 }], + existing_failures: [{ recent_failures: 1 }], + resolved_failures: [{ recent_failures: 20 }, { recent_failures: 5 }], + }; + const result = utils.countRecentlyFailedTests(report); + + expect(result).toBe(3); + }); + + it('counts tests with more than one recent failure in an array of reports', () => { + const reports = [ + { + new_failures: [{ recent_failures: 2 }], + existing_failures: [{ recent_failures: 20 }, { recent_failures: 5 }], + resolved_failures: [{ recent_failures: 2 }], + }, + { + new_failures: [{ recent_failures: 8 }, { recent_failures: 14 }], + existing_failures: [{ recent_failures: 1 }], + resolved_failures: [{ recent_failures: 7 }, { recent_failures: 5 }], + }, + ]; + const result = utils.countRecentlyFailedTests(reports); + + expect(result).toBe(8); + }); + }); + describe('statusIcon', () => { describe('with failed status', () => { it('returns ICON_WARNING', () => { diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 068eda01fcc..3ef948ea851 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -243,6 +243,7 @@ ci_pipelines: - vulnerability_findings - pipeline_config - security_scans +- security_findings - daily_build_group_report_results - latest_builds - daily_report_results diff --git a/spec/lib/gitlab/redis/wrapper_spec.rb b/spec/lib/gitlab/redis/wrapper_spec.rb index 283853ee863..ec233c022ee 100644 --- a/spec/lib/gitlab/redis/wrapper_spec.rb +++ b/spec/lib/gitlab/redis/wrapper_spec.rb @@ -26,6 +26,12 @@ RSpec.describe Gitlab::Redis::Wrapper do end end + describe '.version' do + it 'returns a version' do + expect(described_class.version).to be_present + end + end + describe '.instrumentation_class' do it 'raises a NotImplementedError' do expect(described_class).to receive(:instrumentation_class).and_call_original diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 0cf3ca4fc47..e03ce8137c5 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -1085,6 +1085,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do let(:user1) { build(:user, id: 1) } let(:user2) { build(:user, id: 2) } let(:user3) { build(:user, id: 3) } + let(:user4) { build(:user, id: 4) } before do counter = Gitlab::UsageDataCounters::TrackUniqueEvents @@ -1099,6 +1100,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do counter.track_event(event_action: :pushed, event_target: project, author_id: 4, time: time - 3.days) counter.track_event(event_action: :created, event_target: wiki, author_id: 3) counter.track_event(event_action: :created, event_target: design, author_id: 3) + counter.track_event(event_action: :created, event_target: design, author_id: 4) counter = Gitlab::UsageDataCounters::EditorUniqueCounter @@ -1118,9 +1120,10 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do it 'returns the distinct count of user actions within the specified time period' do expect(described_class.action_monthly_active_users(time_period)).to eq( { - action_monthly_active_users_design_management: 1, + action_monthly_active_users_design_management: 2, action_monthly_active_users_project_repo: 3, action_monthly_active_users_wiki_repo: 1, + action_monthly_active_users_git_write: 4, action_monthly_active_users_web_ide_edit: 2, action_monthly_active_users_sfe_edit: 2, action_monthly_active_users_snippet_editor_edit: 2, diff --git a/spec/mailers/devise_mailer_spec.rb b/spec/mailers/devise_mailer_spec.rb index 2ee15308400..c9dfee8255d 100644 --- a/spec/mailers/devise_mailer_spec.rb +++ b/spec/mailers/devise_mailer_spec.rb @@ -64,4 +64,34 @@ RSpec.describe DeviseMailer do is_expected.to have_body_text /#{Gitlab.config.gitlab.url}/ end end + + describe '#user_admin_approval' do + subject { described_class.user_admin_approval(user) } + + let_it_be(:user) { create(:user) } + + it_behaves_like 'an email sent from GitLab' + it_behaves_like 'it should not have Gmail Actions links' + it_behaves_like 'a user cannot unsubscribe through footer link' + + it 'is sent to the user' do + is_expected.to deliver_to user.email + end + + it 'has the correct subject' do + is_expected.to have_subject 'Welcome to GitLab!' + end + + it 'greets the user' do + is_expected.to have_body_text /Hi #{user.name}!/ + end + + it 'includes the correct content' do + is_expected.to have_body_text /Your GitLab account request has been approved!/ + end + + it 'includes a link to GitLab' do + is_expected.to have_link(Gitlab.config.gitlab.url) + end + end end diff --git a/spec/services/users/approve_service_spec.rb b/spec/services/users/approve_service_spec.rb index c60e4c3b75e..55b2c83f4a8 100644 --- a/spec/services/users/approve_service_spec.rb +++ b/spec/services/users/approve_service_spec.rb @@ -61,6 +61,11 @@ RSpec.describe Users::ApproveService do expect(user.reload).to be_active end + it 'emails the user on approval' do + expect(DeviseMailer).to receive(:user_admin_approval).with(user).and_call_original + expect { subject }.to have_enqueued_mail(DeviseMailer, :user_admin_approval) + end + context 'email confirmation status' do context 'user is unconfirmed' do let(:user) { create(:user, :blocked_pending_approval, :unconfirmed) } |