diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-19 18:06:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-19 18:06:24 +0300 |
commit | 88542a5e9613c8442a982e65ad5cf13eb33bc541 (patch) | |
tree | 11a65d86e623b443b8a2976cc93cff360e2da8a2 /spec | |
parent | b570d73ecd31e2ca9cf8c2f1adb056edf2869477 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
13 files changed, 182 insertions, 127 deletions
diff --git a/spec/controllers/projects/error_tracking_controller_spec.rb b/spec/controllers/projects/error_tracking_controller_spec.rb index 8155d6ddafe..88365e264f4 100644 --- a/spec/controllers/projects/error_tracking_controller_spec.rb +++ b/spec/controllers/projects/error_tracking_controller_spec.rb @@ -48,15 +48,22 @@ describe Projects::ErrorTrackingController do describe 'format json' do let(:list_issues_service) { spy(:list_issues_service) } let(:external_url) { 'http://example.com' } - - before do - expect(ErrorTracking::ListIssuesService) - .to receive(:new).with(project, user) - .and_return(list_issues_service) + let(:search_term) do + ActionController::Parameters.new( + search_term: 'something' + ).permit! end context 'no data' do + let(:search_term) do + ActionController::Parameters.new({}).permit! + end + before do + expect(ErrorTracking::ListIssuesService) + .to receive(:new).with(project, user, search_term) + .and_return(list_issues_service) + expect(list_issues_service).to receive(:execute) .and_return(status: :error, http_status: :no_content) end @@ -68,59 +75,95 @@ describe Projects::ErrorTrackingController do end end - context 'service result is successful' do + context 'with a search_term param' do before do - expect(list_issues_service).to receive(:execute) - .and_return(status: :success, issues: [error]) - expect(list_issues_service).to receive(:external_url) - .and_return(external_url) + expect(ErrorTracking::ListIssuesService) + .to receive(:new).with(project, user, search_term) + .and_return(list_issues_service) end - let(:error) { build(:error_tracking_error) } + context 'service result is successful' do + before do + expect(list_issues_service).to receive(:execute) + .and_return(status: :success, issues: [error]) + expect(list_issues_service).to receive(:external_url) + .and_return(external_url) + end - it 'returns a list of errors' do - get :index, params: project_params(format: :json) + let(:error) { build(:error_tracking_error) } - expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('error_tracking/index') - expect(json_response['external_url']).to eq(external_url) - expect(json_response['errors']).to eq([error].as_json) + it 'returns a list of errors' do + get :index, params: project_params(format: :json, search_term: 'something') + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('error_tracking/index') + expect(json_response['external_url']).to eq(external_url) + expect(json_response['errors']).to eq([error].as_json) + end end end - context 'service result is erroneous' do - let(:error_message) { 'error message' } + context 'without a search_term param' do + before do + expect(ErrorTracking::ListIssuesService) + .to receive(:new).with(project, user, {}) + .and_return(list_issues_service) + end - context 'without http_status' do + context 'service result is successful' do before do expect(list_issues_service).to receive(:execute) - .and_return(status: :error, message: error_message) + .and_return(status: :success, issues: [error]) + expect(list_issues_service).to receive(:external_url) + .and_return(external_url) end - it 'returns 400 with message' do + let(:error) { build(:error_tracking_error) } + + it 'returns a list of errors' do get :index, params: project_params(format: :json) - expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['message']).to eq(error_message) + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('error_tracking/index') + expect(json_response['external_url']).to eq(external_url) + expect(json_response['errors']).to eq([error].as_json) end end - context 'with explicit http_status' do - let(:http_status) { :no_content } + context 'service result is erroneous' do + let(:error_message) { 'error message' } - before do - expect(list_issues_service).to receive(:execute).and_return( - status: :error, - message: error_message, - http_status: http_status - ) + context 'without http_status' do + before do + expect(list_issues_service).to receive(:execute) + .and_return(status: :error, message: error_message) + end + + it 'returns 400 with message' do + get :index, params: project_params(format: :json) + + expect(response).to have_gitlab_http_status(:bad_request) + expect(json_response['message']).to eq(error_message) + end end - it 'returns http_status with message' do - get :index, params: project_params(format: :json) + context 'with explicit http_status' do + let(:http_status) { :no_content } - expect(response).to have_gitlab_http_status(http_status) - expect(json_response['message']).to eq(error_message) + before do + expect(list_issues_service).to receive(:execute).and_return( + status: :error, + message: error_message, + http_status: http_status + ) + end + + it 'returns http_status with message' do + get :index, params: project_params(format: :json) + + expect(response).to have_gitlab_http_status(http_status) + expect(json_response['message']).to eq(error_message) + end end end end diff --git a/spec/fixtures/lib/gitlab/import_export/complex/project.json b/spec/fixtures/lib/gitlab/import_export/complex/project.json index 31805a54f2f..8dc91b05f4d 100644 --- a/spec/fixtures/lib/gitlab/import_export/complex/project.json +++ b/spec/fixtures/lib/gitlab/import_export/complex/project.json @@ -7209,15 +7209,15 @@ } ], "project_feature": { - "builds_access_level": 0, + "builds_access_level": 10, "created_at": "2014-12-26T09:26:45.000Z", "id": 2, - "issues_access_level": 0, - "merge_requests_access_level": 20, + "issues_access_level": 10, + "merge_requests_access_level": 10, "project_id": 4, - "snippets_access_level": 20, + "snippets_access_level": 10, "updated_at": "2016-09-23T11:58:28.000Z", - "wiki_access_level": 20 + "wiki_access_level": 10 }, "custom_attributes": [ { @@ -7257,6 +7257,9 @@ "image_url": "http://www.example.com" } ], + "ci_cd_settings": { + "group_runners_enabled": false + }, "boards": [ { "id": 29, diff --git a/spec/frontend/error_tracking/components/error_tracking_list_spec.js b/spec/frontend/error_tracking/components/error_tracking_list_spec.js index 1bbf23cc602..4edc2a647c3 100644 --- a/spec/frontend/error_tracking/components/error_tracking_list_spec.js +++ b/spec/frontend/error_tracking/components/error_tracking_list_spec.js @@ -1,7 +1,14 @@ import { createLocalVue, shallowMount } from '@vue/test-utils'; import Vuex from 'vuex'; import ErrorTrackingList from '~/error_tracking/components/error_tracking_list.vue'; -import { GlButton, GlEmptyState, GlLoadingIcon, GlTable, GlLink } from '@gitlab/ui'; +import { + GlButton, + GlEmptyState, + GlLoadingIcon, + GlTable, + GlLink, + GlSearchBoxByClick, +} from '@gitlab/ui'; const localVue = createLocalVue(); localVue.use(Vuex); @@ -34,8 +41,8 @@ describe('ErrorTrackingList', () => { beforeEach(() => { actions = { - getSentryData: () => {}, - startPolling: () => {}, + getErrorList: () => {}, + startPolling: jest.fn(), restartPolling: jest.fn().mockName('restartPolling'), }; @@ -63,13 +70,13 @@ describe('ErrorTrackingList', () => { describe('loading', () => { beforeEach(() => { + store.state.list.loading = true; mountComponent(); }); it('shows spinner', () => { expect(wrapper.find(GlLoadingIcon).exists()).toBeTruthy(); expect(wrapper.find(GlTable).exists()).toBeFalsy(); - expect(wrapper.find(GlButton).exists()).toBeFalsy(); }); }); @@ -85,6 +92,20 @@ describe('ErrorTrackingList', () => { expect(wrapper.find(GlTable).exists()).toBeTruthy(); expect(wrapper.find(GlButton).exists()).toBeTruthy(); }); + + describe('filtering', () => { + it('shows search box', () => { + expect(wrapper.find(GlSearchBoxByClick).exists()).toBeTruthy(); + }); + + it('makes network request on submit', () => { + expect(actions.startPolling).toHaveBeenCalledTimes(1); + + wrapper.find(GlSearchBoxByClick).vm.$emit('submit'); + + expect(actions.startPolling).toHaveBeenCalledTimes(2); + }); + }); }); describe('no results', () => { diff --git a/spec/frontend/error_tracking/store/list/actions_spec.js b/spec/frontend/error_tracking/store/list/actions_spec.js new file mode 100644 index 00000000000..dba1b31b9f3 --- /dev/null +++ b/spec/frontend/error_tracking/store/list/actions_spec.js @@ -0,0 +1,29 @@ +import axios from '~/lib/utils/axios_utils'; +import MockAdapter from 'axios-mock-adapter'; +import * as actions from '~/error_tracking/store/list/actions'; +import * as types from '~/error_tracking/store/list/mutation_types'; + +describe('error tracking actions', () => { + let mock; + + beforeEach(() => { + mock = new MockAdapter(axios); + }); + + afterEach(() => { + mock.restore(); + }); + + describe('startPolling', () => { + it('commits SET_LOADING', () => { + mock.onGet().reply(200); + const endpoint = '/errors'; + const commit = jest.fn(); + const state = {}; + + actions.startPolling({ commit, state }, endpoint); + + expect(commit).toHaveBeenCalledWith(types.SET_LOADING, true); + }); + }); +}); diff --git a/spec/frontend/error_tracking/store/list/getters_spec.js b/spec/frontend/error_tracking/store/list/getters_spec.js deleted file mode 100644 index 3cd7fa37d44..00000000000 --- a/spec/frontend/error_tracking/store/list/getters_spec.js +++ /dev/null @@ -1,33 +0,0 @@ -import * as getters from '~/error_tracking/store/list/getters'; - -describe('Error Tracking getters', () => { - let state; - - const mockErrors = [ - { title: 'ActiveModel::MissingAttributeError: missing attribute: encrypted_password' }, - { title: 'Grape::Exceptions::MethodNotAllowed: Grape::Exceptions::MethodNotAllowed' }, - { title: 'NoMethodError: undefined method `sanitize_http_headers=' }, - { title: 'NoMethodError: undefined method `pry' }, - ]; - - beforeEach(() => { - state = { - errors: mockErrors, - }; - }); - - describe('search results', () => { - it('should return errors filtered by words in title matching the query', () => { - const filteredErrors = getters.filterErrorsByTitle(state)('NoMethod'); - - expect(filteredErrors).not.toContainEqual(mockErrors[0]); - expect(filteredErrors.length).toBe(2); - }); - - it('should not return results if there is no matching query', () => { - const filteredErrors = getters.filterErrorsByTitle(state)('GitLab'); - - expect(filteredErrors.length).toBe(0); - }); - }); -}); diff --git a/spec/frontend/vue_shared/components/markdown/header_spec.js b/spec/frontend/vue_shared/components/markdown/header_spec.js index 48f2ee86619..1c4247fb5f0 100644 --- a/spec/frontend/vue_shared/components/markdown/header_spec.js +++ b/spec/frontend/vue_shared/components/markdown/header_spec.js @@ -5,7 +5,7 @@ import headerComponent from '~/vue_shared/components/markdown/header.vue'; describe('Markdown field header component', () => { let vm; - beforeEach(done => { + beforeEach(() => { const Component = Vue.extend(headerComponent); vm = new Component({ @@ -13,8 +13,6 @@ describe('Markdown field header component', () => { previewMarkdown: false, }, }).$mount(); - - Vue.nextTick(done); }); it('renders markdown header buttons', () => { @@ -42,13 +40,11 @@ describe('Markdown field header component', () => { expect(vm.$el.querySelector('li:nth-child(1)').classList.contains('active')).toBeTruthy(); }); - it('renders `preview` link as active when previewMarkdown is true', done => { + it('renders `preview` link as active when previewMarkdown is true', () => { vm.previewMarkdown = true; Vue.nextTick(() => { expect(vm.$el.querySelector('li:nth-child(2)').classList.contains('active')).toBeTruthy(); - - done(); }); }); diff --git a/spec/frontend/vue_shared/components/markdown/suggestion_diff_header_spec.js b/spec/frontend/vue_shared/components/markdown/suggestion_diff_header_spec.js index 6716e5cd794..9e0b98ecef9 100644 --- a/spec/frontend/vue_shared/components/markdown/suggestion_diff_header_spec.js +++ b/spec/frontend/vue_shared/components/markdown/suggestion_diff_header_spec.js @@ -64,12 +64,10 @@ describe('Suggestion Diff component', () => { }); describe('when apply suggestion is clicked', () => { - beforeEach(done => { + beforeEach(() => { createComponent(); findApplyButton().vm.$emit('click'); - - wrapper.vm.$nextTick(done); }); it('emits apply', () => { @@ -88,19 +86,15 @@ describe('Suggestion Diff component', () => { expect(wrapper.text()).toContain('Applying suggestion'); }); - it('when callback of apply is called, hides loading', done => { + it('when callback of apply is called, hides loading', () => { const [callback] = wrapper.emitted().apply[0]; callback(); - wrapper.vm - .$nextTick() - .then(() => { - expect(findApplyButton().exists()).toBe(true); - expect(findLoading().exists()).toBe(false); - }) - .then(done) - .catch(done.fail); + return wrapper.vm.$nextTick().then(() => { + expect(findApplyButton().exists()).toBe(true); + expect(findLoading().exists()).toBe(false); + }); }); }); }); diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index 459b1eed1a7..64a648ca1f8 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -48,11 +48,11 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do it 'restore correct project features' do project = Project.find_by_path('project') - expect(project.project_feature.issues_access_level).to eq(ProjectFeature::DISABLED) - expect(project.project_feature.builds_access_level).to eq(ProjectFeature::ENABLED) - expect(project.project_feature.snippets_access_level).to eq(ProjectFeature::ENABLED) - expect(project.project_feature.wiki_access_level).to eq(ProjectFeature::ENABLED) - expect(project.project_feature.merge_requests_access_level).to eq(ProjectFeature::ENABLED) + expect(project.project_feature.issues_access_level).to eq(ProjectFeature::PRIVATE) + expect(project.project_feature.builds_access_level).to eq(ProjectFeature::PRIVATE) + expect(project.project_feature.snippets_access_level).to eq(ProjectFeature::PRIVATE) + expect(project.project_feature.wiki_access_level).to eq(ProjectFeature::PRIVATE) + expect(project.project_feature.merge_requests_access_level).to eq(ProjectFeature::PRIVATE) end it 'has the project description' do @@ -220,6 +220,10 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do expect(award_emoji.map(&:name)).to contain_exactly('thumbsup', 'coffee') end + it 'restores `ci_cd_settings` : `group_runners_enabled` setting' do + expect(@project.ci_cd_settings.group_runners_enabled?).to eq(false) + end + it 'restores the correct service' do expect(CustomIssueTrackerService.first).not_to be_nil end diff --git a/spec/lib/sentry/client_spec.rb b/spec/lib/sentry/client_spec.rb index 8101664d34f..b46fa485f82 100644 --- a/spec/lib/sentry/client_spec.rb +++ b/spec/lib/sentry/client_spec.rb @@ -88,12 +88,13 @@ describe Sentry::Client do describe '#list_issues' do let(:issue_status) { 'unresolved' } let(:limit) { 20 } + let(:search_term) { '' } let(:sentry_api_response) { issues_sample_response } let(:sentry_request_url) { sentry_url + '/issues/?limit=20&query=is:unresolved' } let!(:sentry_api_request) { stub_sentry_request(sentry_request_url, body: sentry_api_response) } - subject { client.list_issues(issue_status: issue_status, limit: limit) } + subject { client.list_issues(issue_status: issue_status, limit: limit, search_term: search_term) } it_behaves_like 'calls sentry api' @@ -202,6 +203,16 @@ describe Sentry::Client do end it_behaves_like 'maps exceptions' + + context 'when search term is present' do + let(:search_term) { 'NoMethodError'} + let(:sentry_request_url) { "#{sentry_url}/issues/?limit=20&query=is:unresolved NoMethodError" } + + it_behaves_like 'calls sentry api' + + it_behaves_like 'has correct return type', Gitlab::ErrorTracking::Error + it_behaves_like 'has correct length', 1 + end end describe '#list_projects' do diff --git a/spec/services/error_tracking/list_issues_service_spec.rb b/spec/services/error_tracking/list_issues_service_spec.rb index 5b73bc91478..8e2abe8e07d 100644 --- a/spec/services/error_tracking/list_issues_service_spec.rb +++ b/spec/services/error_tracking/list_issues_service_spec.rb @@ -5,6 +5,14 @@ require 'spec_helper' describe ErrorTracking::ListIssuesService do set(:user) { create(:user) } set(:project) { create(:project) } + let(:params) { { search_term: 'something' } } + let(:list_sentry_issues_args) do + { + issue_status: 'unresolved', + limit: 20, + search_term: params[:search_term] + } + end let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project' } let(:token) { 'test-token' } @@ -14,7 +22,7 @@ describe ErrorTracking::ListIssuesService do create(:project_error_tracking_setting, api_url: sentry_url, token: token, project: project) end - subject { described_class.new(project, user) } + subject { described_class.new(project, user, params) } before do expect(project).to receive(:error_tracking_setting).at_least(:once).and_return(error_tracking_setting) @@ -29,7 +37,9 @@ describe ErrorTracking::ListIssuesService do before do expect(error_tracking_setting) - .to receive(:list_sentry_issues).and_return(issues: issues) + .to receive(:list_sentry_issues) + .with(list_sentry_issues_args) + .and_return(issues: issues) end it 'returns the issues' do diff --git a/spec/services/merge_requests/merge_service_spec.rb b/spec/services/merge_requests/merge_service_spec.rb index c938dd1cb0b..1bdea973685 100644 --- a/spec/services/merge_requests/merge_service_spec.rb +++ b/spec/services/merge_requests/merge_service_spec.rb @@ -104,14 +104,6 @@ describe MergeRequests::MergeService do .to change { merge_request.merge_error } .from(nil).to(merge_error) end - - it 'merges the MR when the feature is disabled' do - stub_feature_flags(validate_merge_sha: false) - - service.execute(merge_request) - - expect(merge_request).to be_merged - end end context 'closes related issues' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d7533f99683..2afe80f455e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,7 +18,6 @@ rspec_profiling_is_configured = ENV['RSPEC_PROFILING_POSTGRES_URL'].present? || ENV['RSPEC_PROFILING'] branch_can_be_profiled = - ENV['GITLAB_DATABASE'] == 'postgresql' && (ENV['CI_COMMIT_REF_NAME'] == 'master' || ENV['CI_COMMIT_REF_NAME'] =~ /rspec-profile/) diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index f0dd6c52b74..6f385d6e019 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -1,21 +1,7 @@ # frozen_string_literal: true -require 'database_cleaner/active_record/deletion' require_relative 'db_cleaner' -module FakeInformationSchema - # Work around a bug in DatabaseCleaner when using the deletion strategy: - # https://github.com/DatabaseCleaner/database_cleaner/issues/347 - # - # On MySQL, if the information schema is said to exist, we use an inaccurate - # row count leading to some tables not being cleaned when they should - def information_schema_exists?(_connection) - false - end -end - -DatabaseCleaner::ActiveRecord::Deletion.prepend(FakeInformationSchema) - RSpec.configure do |config| include DbCleaner |