Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-02 03:08:11 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-02 03:08:11 +0300
commit93dcf45d441bc884b167f4338380c8c888e9b86f (patch)
treef55e8c1d39013380d1ff7d2a4e3cca537a35192a /spec
parent0e68afab211a172b862a7acc774e1eda5da8e471 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/usage_data.rb3
-rw-r--r--spec/features/projects/services/prometheus_external_alerts_spec.rb48
-rw-r--r--spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap2
-rw-r--r--spec/frontend/prometheus_alerts/components/reset_key_spec.js105
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb1
-rw-r--r--spec/models/user_spec.rb26
-rw-r--r--spec/requests/api/pipelines_spec.rb16
-rw-r--r--spec/serializers/prometheus_alert_entity_spec.rb1
-rw-r--r--spec/services/users/update_service_spec.rb9
-rw-r--r--spec/support/helpers/usage_data_helpers.rb1
-rw-r--r--spec/support/shared_contexts/navbar_structure_context.rb12
11 files changed, 181 insertions, 43 deletions
diff --git a/spec/factories/usage_data.rb b/spec/factories/usage_data.rb
index 9560e076ae4..da69a0fb844 100644
--- a/spec/factories/usage_data.rb
+++ b/spec/factories/usage_data.rb
@@ -26,6 +26,9 @@ FactoryBot.define do
create_list(:issue, 2, project: projects[0], author: User.alert_bot)
create_list(:issue, 2, project: projects[1], author: User.alert_bot)
create_list(:issue, 4, project: projects[0])
+ create(:prometheus_alert, project: projects[0])
+ create(:prometheus_alert, project: projects[0])
+ create(:prometheus_alert, project: projects[1])
create(:zoom_meeting, project: projects[0], issue: projects[0].issues[0], issue_status: :added)
create_list(:zoom_meeting, 2, project: projects[0], issue: projects[0].issues[1], issue_status: :removed)
create(:zoom_meeting, project: projects[0], issue: projects[0].issues[2], issue_status: :added)
diff --git a/spec/features/projects/services/prometheus_external_alerts_spec.rb b/spec/features/projects/services/prometheus_external_alerts_spec.rb
new file mode 100644
index 00000000000..e33b2d9a75e
--- /dev/null
+++ b/spec/features/projects/services/prometheus_external_alerts_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Prometheus external alerts', :js do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+
+ let(:alerts_section_selector) { '.js-prometheus-alerts' }
+ let(:alerts_section) { page.find(alerts_section_selector) }
+
+ before do
+ sign_in(user)
+ project.add_maintainer(user)
+
+ visit_edit_service
+ end
+
+ context 'with manual configuration' do
+ before do
+ create(:prometheus_service, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true)
+ end
+
+ it 'shows the Alerts section' do
+ visit_edit_service
+
+ expect(alerts_section).to have_content('Alerts')
+ expect(alerts_section).to have_content('Receive alerts from manually configured Prometheus servers.')
+ expect(alerts_section).to have_content('URL')
+ expect(alerts_section).to have_content('Authorization key')
+ end
+ end
+
+ context 'with no configuration' do
+ it 'does not show the Alerts section' do
+ wait_for_requests
+
+ expect(page).not_to have_css(alerts_section_selector)
+ end
+ end
+
+ private
+
+ def visit_edit_service
+ visit(project_settings_integrations_path(project))
+ click_link('Prometheus')
+ end
+end
diff --git a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap
index b8bda533072..c61ac0fb175 100644
--- a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap
+++ b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap
@@ -19,6 +19,7 @@ exports[`Dashboard template matches the default snapshot 1`] = `
>
<dashboards-dropdown-stub
class="mb-0 d-flex"
+ data-qa-selector="dashboards_filter_dropdown"
defaultbranch="master"
id="monitor-dashboards-dropdown"
selecteddashboard="[object Object]"
@@ -74,6 +75,7 @@ exports[`Dashboard template matches the default snapshot 1`] = `
<gl-form-group-stub
class="col-sm-auto col-md-auto col-lg-auto"
+ data-qa-selector="show_last_dropdown"
label="Show last"
label-for="monitor-time-window-dropdown"
label-size="sm"
diff --git a/spec/frontend/prometheus_alerts/components/reset_key_spec.js b/spec/frontend/prometheus_alerts/components/reset_key_spec.js
new file mode 100644
index 00000000000..df52baafa29
--- /dev/null
+++ b/spec/frontend/prometheus_alerts/components/reset_key_spec.js
@@ -0,0 +1,105 @@
+import { shallowMount } from '@vue/test-utils';
+import MockAdapter from 'axios-mock-adapter';
+import ResetKey from '~/prometheus_alerts/components/reset_key.vue';
+import { GlModal } from '@gitlab/ui';
+import waitForPromises from 'helpers/wait_for_promises';
+import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
+import axios from '~/lib/utils/axios_utils';
+
+describe('ResetKey', () => {
+ let mock;
+ let vm;
+
+ const propsData = {
+ initialAuthorizationKey: 'abcd1234',
+ changeKeyUrl: '/updateKeyUrl',
+ notifyUrl: '/root/autodevops-deploy/prometheus/alerts/notify.json',
+ learnMoreUrl: '/learnMore',
+ };
+
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+ setFixtures('<div class="flash-container"></div><div id="reset-key"></div>');
+ });
+
+ afterEach(() => {
+ mock.restore();
+ vm.destroy();
+ });
+
+ describe('authorization key exists', () => {
+ beforeEach(() => {
+ propsData.initialAuthorizationKey = 'abcd1234';
+ vm = shallowMount(ResetKey, {
+ propsData,
+ });
+ });
+
+ it('shows fields and buttons', () => {
+ expect(vm.find('#notify-url').attributes('value')).toEqual(propsData.notifyUrl);
+ expect(vm.find('#authorization-key').attributes('value')).toEqual(
+ propsData.initialAuthorizationKey,
+ );
+
+ expect(vm.findAll(ClipboardButton).length).toBe(2);
+ expect(vm.find('.js-reset-auth-key').text()).toEqual('Reset key');
+ });
+
+ it('reset updates key', () => {
+ mock.onPost(propsData.changeKeyUrl).replyOnce(200, { token: 'newToken' });
+
+ vm.find(GlModal).vm.$emit('ok');
+
+ return vm.vm
+ .$nextTick()
+ .then(waitForPromises)
+ .then(() => {
+ expect(vm.vm.authorizationKey).toEqual('newToken');
+ expect(vm.find('#authorization-key').attributes('value')).toEqual('newToken');
+ });
+ });
+
+ it('reset key failure shows error', () => {
+ mock.onPost(propsData.changeKeyUrl).replyOnce(500);
+
+ vm.find(GlModal).vm.$emit('ok');
+
+ return vm.vm
+ .$nextTick()
+ .then(waitForPromises)
+ .then(() => {
+ expect(vm.find('#authorization-key').attributes('value')).toEqual(
+ propsData.initialAuthorizationKey,
+ );
+
+ expect(document.querySelector('.flash-container').innerText.trim()).toEqual(
+ 'Failed to reset key. Please try again.',
+ );
+ });
+ });
+ });
+
+ describe('authorization key has not been set', () => {
+ beforeEach(() => {
+ propsData.initialAuthorizationKey = '';
+ vm = shallowMount(ResetKey, {
+ propsData,
+ });
+ });
+
+ it('shows Generate Key button', () => {
+ expect(vm.find('.js-reset-auth-key').text()).toEqual('Generate key');
+ expect(vm.find('#authorization-key').attributes('value')).toEqual('');
+ });
+
+ it('Generate key button triggers key change', () => {
+ mock.onPost(propsData.changeKeyUrl).replyOnce(200, { token: 'newToken' });
+
+ vm.find('.js-reset-auth-key').vm.$emit('click');
+
+ return waitForPromises().then(() => {
+ expect(vm.find('#authorization-key').attributes('value')).toEqual('newToken');
+ });
+ });
+ });
+});
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index eca69d755cc..c29a4dd9e00 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -51,6 +51,7 @@ describe Gitlab::UsageData, :aggregate_failures do
expect(count_data[:projects_with_repositories_enabled]).to eq(3)
expect(count_data[:projects_with_error_tracking_enabled]).to eq(1)
expect(count_data[:projects_with_alerts_service_enabled]).to eq(1)
+ expect(count_data[:projects_with_prometheus_alerts]).to eq(2)
expect(count_data[:issues_created_from_gitlab_error_tracking_ui]).to eq(1)
expect(count_data[:issues_with_associated_zoom_link]).to eq(2)
expect(count_data[:issues_using_zoom_quick_actions]).to eq(3)
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index b21841ad034..61c871ead92 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -4263,30 +4263,6 @@ describe User, :do_not_mock_admin_mode do
end
describe '#read_only_attribute?' do
- context 'when LDAP server is enabled' do
- before do
- allow(Gitlab::Auth::Ldap::Config).to receive(:enabled?).and_return(true)
- end
-
- %i[name email location].each do |attribute|
- it "is true for #{attribute}" do
- expect(subject.read_only_attribute?(attribute)).to be_truthy
- end
- end
-
- context 'and ldap_readonly_attributes feature is disabled' do
- before do
- stub_feature_flags(ldap_readonly_attributes: false)
- end
-
- %i[name email location].each do |attribute|
- it "is false" do
- expect(subject.read_only_attribute?(attribute)).to be_falsey
- end
- end
- end
- end
-
context 'when synced attributes metadata is present' do
it 'delegates to synced_attributes_metadata' do
subject.build_user_synced_attributes_metadata
@@ -4297,7 +4273,7 @@ describe User, :do_not_mock_admin_mode do
end
end
- context 'when synced attributes metadata is present' do
+ context 'when synced attributes metadata is not present' do
it 'is false for any attribute' do
expect(subject.read_only_attribute?(:email)).to be_falsey
end
diff --git a/spec/requests/api/pipelines_spec.rb b/spec/requests/api/pipelines_spec.rb
index a8f21f64a72..f43fa5b4185 100644
--- a/spec/requests/api/pipelines_spec.rb
+++ b/spec/requests/api/pipelines_spec.rb
@@ -3,11 +3,15 @@
require 'spec_helper'
describe API::Pipelines do
- let(:user) { create(:user) }
- let(:non_member) { create(:user) }
- let(:project) { create(:project, :repository, creator: user) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:non_member) { create(:user) }
- let!(:pipeline) do
+ # We need to reload as the shared example 'pipelines visibility table' is changing project
+ let_it_be(:project, reload: true) do
+ create(:project, :repository, creator: user)
+ end
+
+ let_it_be(:pipeline) do
create(:ci_empty_pipeline, project: project, sha: project.commit.id,
ref: project.default_branch, user: user)
end
@@ -26,7 +30,7 @@ describe API::Pipelines do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
- expect(json_response.first['sha']).to match /\A\h{40}\z/
+ expect(json_response.first['sha']).to match(/\A\h{40}\z/)
expect(json_response.first['id']).to eq pipeline.id
expect(json_response.first['web_url']).to be_present
expect(json_response.first.keys).to contain_exactly(*%w[id sha ref status web_url created_at updated_at])
@@ -438,7 +442,7 @@ describe API::Pipelines do
get api("/projects/#{project.id}/pipelines/#{pipeline.id}", user)
expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['sha']).to match /\A\h{40}\z/
+ expect(json_response['sha']).to match(/\A\h{40}\z/)
end
it 'returns 404 when it does not exist' do
diff --git a/spec/serializers/prometheus_alert_entity_spec.rb b/spec/serializers/prometheus_alert_entity_spec.rb
index 5121c62a0e0..2b6d8b62c4d 100644
--- a/spec/serializers/prometheus_alert_entity_spec.rb
+++ b/spec/serializers/prometheus_alert_entity_spec.rb
@@ -13,7 +13,6 @@ describe PrometheusAlertEntity do
context 'when user can read prometheus alerts' do
before do
prometheus_alert.project.add_maintainer(user)
- stub_licensed_features(prometheus_alerts: true)
end
it 'exposes prometheus_alert attributes' do
diff --git a/spec/services/users/update_service_spec.rb b/spec/services/users/update_service_spec.rb
index bd54ca97431..8e13e7d9c0c 100644
--- a/spec/services/users/update_service_spec.rb
+++ b/spec/services/users/update_service_spec.rb
@@ -55,15 +55,6 @@ describe Users::UpdateService do
expect(result[:message]).to eq("Emoji is not included in the list")
end
- it 'ignores read-only attributes' do
- allow(user).to receive(:read_only_attribute?).with(:name).and_return(true)
-
- expect do
- update_user(user, name: 'changed' + user.name)
- user.reload
- end.not_to change { user.name }
- end
-
it 'updates user detail with provided attributes' do
result = update_user(user, job_title: 'Backend Engineer')
diff --git a/spec/support/helpers/usage_data_helpers.rb b/spec/support/helpers/usage_data_helpers.rb
index 0fa1c40bd67..4d63cf12575 100644
--- a/spec/support/helpers/usage_data_helpers.rb
+++ b/spec/support/helpers/usage_data_helpers.rb
@@ -92,6 +92,7 @@ module UsageDataHelpers
projects_with_repositories_enabled
projects_with_error_tracking_enabled
projects_with_alerts_service_enabled
+ projects_with_prometheus_alerts
pages_domains
protected_branches
releases
diff --git a/spec/support/shared_contexts/navbar_structure_context.rb b/spec/support/shared_contexts/navbar_structure_context.rb
index c7df54f9501..2a98855a83f 100644
--- a/spec/support/shared_contexts/navbar_structure_context.rb
+++ b/spec/support/shared_contexts/navbar_structure_context.rb
@@ -121,8 +121,16 @@ RSpec.shared_context 'group navbar structure' do
_('Projects'),
_('CI / CD'),
_('Webhooks'),
- _('Audit Events'),
- _('Usage Quotas')
+ _('Audit Events')
+ ]
+ }
+ end
+
+ let(:administration_nav_item) do
+ {
+ nav_item: _('Administration'),
+ nav_sub_items: [
+ s_('UsageQuota|Usage Quotas')
]
}
end