diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-30 15:09:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-30 15:09:45 +0300 |
commit | 04edf6545802ed0515e221038b63fc96ad3e6d54 (patch) | |
tree | d0eed6d065f7f5a7dcfc8f6bd7a1cebd4aae0167 /spec | |
parent | ada214dc52b53bd9eb3a79c279506f91c547f721 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/channels/application_cable/connection_spec.rb | 47 | ||||
-rw-r--r-- | spec/channels/issues_channel_spec.rb | 36 | ||||
-rw-r--r-- | spec/features/security/project/internal_access_spec.rb | 6 | ||||
-rw-r--r-- | spec/features/security/project/private_access_spec.rb | 2 | ||||
-rw-r--r-- | spec/features/security/project/public_access_spec.rb | 10 | ||||
-rw-r--r-- | spec/features/users/signup_spec.rb | 4 | ||||
-rw-r--r-- | spec/frontend/alert_management/components/alert_management_list_spec.js | 25 | ||||
-rw-r--r-- | spec/frontend/alert_management/mocks/alerts.json | 29 | ||||
-rw-r--r-- | spec/frontend/diffs/store/mutations_spec.js | 30 | ||||
-rw-r--r-- | spec/helpers/projects/alert_management_helper_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/quality/test_level_spec.rb | 4 | ||||
-rw-r--r-- | spec/services/issues/update_service_spec.rb | 28 |
12 files changed, 201 insertions, 29 deletions
diff --git a/spec/channels/application_cable/connection_spec.rb b/spec/channels/application_cable/connection_spec.rb new file mode 100644 index 00000000000..f3d67133528 --- /dev/null +++ b/spec/channels/application_cable/connection_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ApplicationCable::Connection, :clean_gitlab_redis_shared_state do + let(:session_id) { Rack::Session::SessionId.new('6919a6f1bb119dd7396fadc38fd18d0d') } + + before do + Gitlab::Redis::SharedState.with do |redis| + redis.set("session:gitlab:#{session_id.private_id}", Marshal.dump(session_hash)) + end + + cookies[Gitlab::Application.config.session_options[:key]] = session_id.public_id + end + + context 'when user is logged in' do + let(:user) { create(:user) } + let(:session_hash) { { 'warden.user.user.key' => [[user.id], user.encrypted_password[0, 29]] } } + + it 'sets current_user' do + connect + + expect(connection.current_user).to eq(user) + end + + context 'with a stale password' do + let(:partial_password_hash) { build(:user, password: 'some_old_password').encrypted_password[0, 29] } + let(:session_hash) { { 'warden.user.user.key' => [[user.id], partial_password_hash] } } + + it 'sets current_user to nil' do + connect + + expect(connection.current_user).to be_nil + end + end + end + + context 'when user is not logged in' do + let(:session_hash) { {} } + + it 'sets current_user to nil' do + connect + + expect(connection.current_user).to be_nil + end + end +end diff --git a/spec/channels/issues_channel_spec.rb b/spec/channels/issues_channel_spec.rb new file mode 100644 index 00000000000..1c88cc73456 --- /dev/null +++ b/spec/channels/issues_channel_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe IssuesChannel do + let_it_be(:issue) { create(:issue) } + + it 'rejects when project path is invalid' do + subscribe(project_path: 'invalid_project_path', iid: issue.iid) + + expect(subscription).to be_rejected + end + + it 'rejects when iid is invalid' do + subscribe(project_path: issue.project.full_path, iid: non_existing_record_iid) + + expect(subscription).to be_rejected + end + + it 'rejects when the user does not have access' do + stub_connection current_user: nil + + subscribe(project_path: issue.project.full_path, iid: issue.iid) + + expect(subscription).to be_rejected + end + + it 'subscribes to a stream when the user has access' do + stub_connection current_user: issue.author + + subscribe(project_path: issue.project.full_path, iid: issue.iid) + + expect(subscription).to be_confirmed + expect(subscription).to have_stream_for(issue) + end +end diff --git a/spec/features/security/project/internal_access_spec.rb b/spec/features/security/project/internal_access_spec.rb index 45b57b5cb1b..f29aa8de928 100644 --- a/spec/features/security/project/internal_access_spec.rb +++ b/spec/features/security/project/internal_access_spec.rb @@ -464,9 +464,9 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:owner).of(project) } it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } - it { is_expected.to be_denied_for(:reporter).of(project) } - it { is_expected.to be_denied_for(:guest).of(project) } - it { is_expected.to be_denied_for(:user) } + it { is_expected.to be_allowed_for(:reporter).of(project) } + it { is_expected.to be_allowed_for(:guest).of(project) } + it { is_expected.to be_allowed_for(:user) } it { is_expected.to be_denied_for(:external) } it { is_expected.to be_denied_for(:visitor) } end diff --git a/spec/features/security/project/private_access_spec.rb b/spec/features/security/project/private_access_spec.rb index 9aeb3ffbd43..ac8596d89bc 100644 --- a/spec/features/security/project/private_access_spec.rb +++ b/spec/features/security/project/private_access_spec.rb @@ -499,7 +499,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:owner).of(project) } it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } - it { is_expected.to be_denied_for(:reporter).of(project) } + it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } it { is_expected.to be_denied_for(:user) } it { is_expected.to be_denied_for(:external) } diff --git a/spec/features/security/project/public_access_spec.rb b/spec/features/security/project/public_access_spec.rb index 4d8c2c7822c..11e9bff10a1 100644 --- a/spec/features/security/project/public_access_spec.rb +++ b/spec/features/security/project/public_access_spec.rb @@ -278,11 +278,11 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:owner).of(project) } it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } - it { is_expected.to be_denied_for(:reporter).of(project) } - it { is_expected.to be_denied_for(:guest).of(project) } - it { is_expected.to be_denied_for(:user) } - it { is_expected.to be_denied_for(:external) } - it { is_expected.to be_denied_for(:visitor) } + it { is_expected.to be_allowed_for(:reporter).of(project) } + it { is_expected.to be_allowed_for(:guest).of(project) } + it { is_expected.to be_allowed_for(:user) } + it { is_expected.to be_allowed_for(:external) } + it { is_expected.to be_allowed_for(:visitor) } end describe "GET /:project_path/-/environments" do diff --git a/spec/features/users/signup_spec.rb b/spec/features/users/signup_spec.rb index daa987ea389..0ef86dde030 100644 --- a/spec/features/users/signup_spec.rb +++ b/spec/features/users/signup_spec.rb @@ -470,8 +470,8 @@ end describe 'With experimental flow' do before do - stub_experiment(signup_flow: true, paid_signup_flow: false) - stub_experiment_for_user(signup_flow: true, paid_signup_flow: false) + stub_experiment(signup_flow: true) + stub_experiment_for_user(signup_flow: true) end it_behaves_like 'Signup' diff --git a/spec/frontend/alert_management/components/alert_management_list_spec.js b/spec/frontend/alert_management/components/alert_management_list_spec.js index c18c2ec0d53..a47363f4dc7 100644 --- a/spec/frontend/alert_management/components/alert_management_list_spec.js +++ b/spec/frontend/alert_management/components/alert_management_list_spec.js @@ -1,17 +1,18 @@ import { mount } from '@vue/test-utils'; import { GlEmptyState, GlTable, GlAlert, GlLoadingIcon } from '@gitlab/ui'; -import stubChildren from 'helpers/stub_children'; import AlertManagementList from '~/alert_management/components/alert_management_list.vue'; +import mockAlerts from '../mocks/alerts.json'; + describe('AlertManagementList', () => { let wrapper; const findAlertsTable = () => wrapper.find(GlTable); + const findAlerts = () => wrapper.findAll('table tbody tr'); const findAlert = () => wrapper.find(GlAlert); const findLoader = () => wrapper.find(GlLoadingIcon); function mountComponent({ - stubs = {}, props = { alertManagementEnabled: false, userCanEnableAlertManagement: false, @@ -21,7 +22,7 @@ describe('AlertManagementList', () => { } = {}) { wrapper = mount(AlertManagementList, { propsData: { - indexPath: '/path', + projectPath: 'gitlab-org/gitlab', enableAlertManagementPath: '/link', emptyAlertSvgPath: 'illustration/path', ...props, @@ -38,10 +39,6 @@ describe('AlertManagementList', () => { }, }, }, - stubs: { - ...stubChildren(AlertManagementList), - ...stubs, - }, }); } @@ -64,7 +61,6 @@ describe('AlertManagementList', () => { describe('Alerts table', () => { it('loading state', () => { mountComponent({ - stubs: { GlTable }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, data: { alerts: null }, loading: true, @@ -75,7 +71,6 @@ describe('AlertManagementList', () => { it('error state', () => { mountComponent({ - stubs: { GlTable }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, data: { alerts: null, errored: true }, loading: false, @@ -88,7 +83,6 @@ describe('AlertManagementList', () => { it('empty state', () => { mountComponent({ - stubs: { GlTable }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, data: { alerts: [], errored: false }, loading: false, @@ -98,5 +92,16 @@ describe('AlertManagementList', () => { expect(findLoader().exists()).toBe(false); expect(findAlert().props().variant).toBe('info'); }); + + it('has data state', () => { + mountComponent({ + props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, + data: { alerts: mockAlerts, errored: false }, + loading: false, + }); + expect(findLoader().exists()).toBe(false); + expect(findAlertsTable().exists()).toBe(true); + expect(findAlerts()).toHaveLength(mockAlerts.length); + }); }); }); diff --git a/spec/frontend/alert_management/mocks/alerts.json b/spec/frontend/alert_management/mocks/alerts.json new file mode 100644 index 00000000000..d4667eb21f8 --- /dev/null +++ b/spec/frontend/alert_management/mocks/alerts.json @@ -0,0 +1,29 @@ +[ + { + "iid": "1527542", + "title": "SyntaxError: Invalid or unexpected token", + "severity": "Critical", + "eventCount": 7, + "startedAt": "2020-04-17T23:18:14.996Z", + "endedAt": "2020-04-17T23:18:14.996Z", + "status": "triggered" + }, + { + "iid": "1527542", + "title": "Some otherr alert Some otherr alert Some otherr alert Some otherr alert Some otherr alert Some otherr alert", + "severity": "Medium", + "eventCount": 1, + "startedAt": "2020-04-17T23:18:14.996Z", + "endedAt": "2020-04-17T23:18:14.996Z", + "status": "acknowledged" + }, + { + "iid": "1527542", + "title": "SyntaxError: Invalid or unexpected token", + "severity": "Low", + "eventCount": 4, + "startedAt": "2020-04-17T23:18:14.996Z", + "endedAt": "2020-04-17T23:18:14.996Z", + "status": "resolved" + } + ] diff --git a/spec/frontend/diffs/store/mutations_spec.js b/spec/frontend/diffs/store/mutations_spec.js index 858ab5be167..c24d406fef3 100644 --- a/spec/frontend/diffs/store/mutations_spec.js +++ b/spec/frontend/diffs/store/mutations_spec.js @@ -1041,6 +1041,36 @@ describe('DiffsStoreMutations', () => { }); }); + describe('SET_DIFF_FILE_VIEWER', () => { + it("should update the correct diffFile's viewer property", () => { + const state = { + diffFiles: [ + { file_path: 'SearchString', viewer: 'OLD VIEWER' }, + { file_path: 'OtherSearchString' }, + { file_path: 'SomeOtherString' }, + ], + }; + + mutations[types.SET_DIFF_FILE_VIEWER](state, { + filePath: 'SearchString', + viewer: 'NEW VIEWER', + }); + + expect(state.diffFiles[0].viewer).toEqual('NEW VIEWER'); + expect(state.diffFiles[1].viewer).not.toBeDefined(); + expect(state.diffFiles[2].viewer).not.toBeDefined(); + + mutations[types.SET_DIFF_FILE_VIEWER](state, { + filePath: 'OtherSearchString', + viewer: 'NEW VIEWER', + }); + + expect(state.diffFiles[0].viewer).toEqual('NEW VIEWER'); + expect(state.diffFiles[1].viewer).toEqual('NEW VIEWER'); + expect(state.diffFiles[2].viewer).not.toBeDefined(); + }); + }); + describe('SET_SHOW_SUGGEST_POPOVER', () => { it('sets showSuggestPopover to false', () => { const state = { showSuggestPopover: true }; diff --git a/spec/helpers/projects/alert_management_helper_spec.rb b/spec/helpers/projects/alert_management_helper_spec.rb index 9246d1deff6..177dcb4ec2e 100644 --- a/spec/helpers/projects/alert_management_helper_spec.rb +++ b/spec/helpers/projects/alert_management_helper_spec.rb @@ -11,10 +11,7 @@ describe Projects::AlertManagementHelper do describe '#alert_management_data' do let(:user_can_enable_alert_management) { false } let(:setting_path) { project_settings_operations_path(project) } - - let(:index_path) do - project_alert_management_index_path(project, format: :json) - end + let(:project_path) { project.full_path } before do allow(helper) @@ -26,9 +23,9 @@ describe Projects::AlertManagementHelper do context 'without alert_managements_setting' do it 'returns frontend configuration' do expect(alert_management_data(current_user, project)).to eq( - 'index-path' => index_path, + 'project-path' => project_path, 'enable-alert-management-path' => setting_path, - "empty-alert-svg-path" => "/images/illustrations/alert-management-empty-state.svg", + 'empty-alert-svg-path' => '/images/illustrations/alert-management-empty-state.svg', 'user-can-enable-alert-management' => 'false', 'alert-management-enabled' => 'true' ) diff --git a/spec/lib/quality/test_level_spec.rb b/spec/lib/quality/test_level_spec.rb index 6042ab24787..b784a92fa85 100644 --- a/spec/lib/quality/test_level_spec.rb +++ b/spec/lib/quality/test_level_spec.rb @@ -21,7 +21,7 @@ RSpec.describe Quality::TestLevel do context 'when level is unit' do it 'returns a pattern' do expect(subject.pattern(:unit)) - .to eq("spec/{bin,config,db,dependencies,factories,finders,frontend,graphql,haml_lint,helpers,initializers,javascripts,lib,models,policies,presenters,rack_servers,replicators,routing,rubocop,serializers,services,sidekiq,support_specs,tasks,uploaders,validators,views,workers,elastic_integration}{,/**/}*_spec.rb") + .to eq("spec/{bin,channels,config,db,dependencies,factories,finders,frontend,graphql,haml_lint,helpers,initializers,javascripts,lib,models,policies,presenters,rack_servers,replicators,routing,rubocop,serializers,services,sidekiq,support_specs,tasks,uploaders,validators,views,workers,elastic_integration}{,/**/}*_spec.rb") end end @@ -89,7 +89,7 @@ RSpec.describe Quality::TestLevel do context 'when level is unit' do it 'returns a regexp' do expect(subject.regexp(:unit)) - .to eq(%r{spec/(bin|config|db|dependencies|factories|finders|frontend|graphql|haml_lint|helpers|initializers|javascripts|lib|models|policies|presenters|rack_servers|replicators|routing|rubocop|serializers|services|sidekiq|support_specs|tasks|uploaders|validators|views|workers|elastic_integration)}) + .to eq(%r{spec/(bin|channels|config|db|dependencies|factories|finders|frontend|graphql|haml_lint|helpers|initializers|javascripts|lib|models|policies|presenters|rack_servers|replicators|routing|rubocop|serializers|services|sidekiq|support_specs|tasks|uploaders|validators|views|workers|elastic_integration)}) end end diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index c32bef5a1a5..556a0d605d5 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -842,5 +842,33 @@ describe Issues::UpdateService, :mailer do let(:open_issuable) { issue } let(:closed_issuable) { create(:closed_issue, project: project) } end + + context 'real-time updates' do + let(:update_params) { { assignee_ids: [user2.id] } } + + context 'when broadcast_issue_updates is enabled' do + before do + stub_feature_flags(broadcast_issue_updates: true) + end + + it 'broadcasts to the issues channel' do + expect(IssuesChannel).to receive(:broadcast_to).with(issue, event: 'updated') + + update_issue(update_params) + end + end + + context 'when broadcast_issue_updates is disabled' do + before do + stub_feature_flags(broadcast_issue_updates: false) + end + + it 'does not broadcast to the issues channel' do + expect(IssuesChannel).not_to receive(:broadcast_to) + + update_issue(update_params) + end + end + end end end |