diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-09 09:11:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-09 09:11:13 +0300 |
commit | 130e0444c6e5498ea95d38dd96bf758a724e2345 (patch) | |
tree | 1c4ebc8b3f451b7d0690a02f9f78bfc9dc1ca0ea /spec | |
parent | 97b58a8a76559ddfed510c8a867c7dc1b0bbfc24 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
8 files changed, 106 insertions, 23 deletions
diff --git a/spec/frontend/members/components/action_buttons/remove_member_button_spec.js b/spec/frontend/members/components/action_buttons/remove_member_button_spec.js index 7eb0ea37fe6..1a031cc56d6 100644 --- a/spec/frontend/members/components/action_buttons/remove_member_button_spec.js +++ b/spec/frontend/members/components/action_buttons/remove_member_button_spec.js @@ -54,6 +54,8 @@ describe('RemoveMemberButton', () => { }); }; + const findButton = () => wrapper.findComponent(GlButton); + beforeEach(() => { createComponent(); }); @@ -66,7 +68,6 @@ describe('RemoveMemberButton', () => { expect(wrapper.attributes()).toMatchObject({ 'aria-label': 'Remove member', title: 'Remove member', - icon: 'remove', }); }); @@ -75,8 +76,22 @@ describe('RemoveMemberButton', () => { }); it('calls Vuex action to show `remove member` modal when clicked', () => { - wrapper.findComponent(GlButton).vm.$emit('click'); + findButton().vm.$emit('click'); expect(actions.showRemoveMemberModal).toHaveBeenCalledWith(expect.any(Object), modalData); }); + + describe('button optional properties', () => { + it('has default value for category and text', () => { + createComponent(); + expect(findButton().props('category')).toBe('secondary'); + expect(findButton().text()).toBe(''); + }); + + it('allow changing value of button category and text', () => { + createComponent({ buttonCategory: 'primary', buttonText: 'Decline request' }); + expect(findButton().props('category')).toBe('primary'); + expect(findButton().text()).toBe('Decline request'); + }); + }); }); diff --git a/spec/frontend/members/components/action_buttons/user_action_buttons_spec.js b/spec/frontend/members/components/action_buttons/user_action_buttons_spec.js index 10e451376c8..356df7e7b11 100644 --- a/spec/frontend/members/components/action_buttons/user_action_buttons_spec.js +++ b/spec/frontend/members/components/action_buttons/user_action_buttons_spec.js @@ -13,6 +13,7 @@ describe('UserActionButtons', () => { propsData: { member, isCurrentUser: false, + isInvitedUser: false, ...propsData, }, }); @@ -45,7 +46,9 @@ describe('UserActionButtons', () => { title: 'Remove member', isAccessRequest: false, isInvite: false, - icon: 'remove', + icon: '', + buttonCategory: 'secondary', + buttonText: 'Remove user', userDeletionObstacles: { name: member.user.name, obstacles: parseUserDeletionObstacles(member.user), @@ -129,4 +132,30 @@ describe('UserActionButtons', () => { expect(findRemoveMemberButton().props().memberType).toBe('ProjectMember'); }); }); + + describe('isInvitedUser', () => { + it.each` + isInvitedUser | icon | buttonText | buttonCategory + ${true} | ${'remove'} | ${null} | ${'primary'} + ${false} | ${''} | ${'Remove user'} | ${'secondary'} + `( + 'passes the correct props to remove-member-button when isInvitedUser is $isInvitedUser', + ({ isInvitedUser, icon, buttonText, buttonCategory }) => { + createComponent({ + isInvitedUser, + permissions: { + canRemove: true, + }, + }); + + expect(findRemoveMemberButton().props()).toEqual( + expect.objectContaining({ + icon, + buttonText, + buttonCategory, + }), + ); + }, + ); + }); }); diff --git a/spec/frontend/members/components/table/member_action_buttons_spec.js b/spec/frontend/members/components/table/member_action_buttons_spec.js index 546d09732d6..1379b2d26ce 100644 --- a/spec/frontend/members/components/table/member_action_buttons_spec.js +++ b/spec/frontend/members/components/table/member_action_buttons_spec.js @@ -14,6 +14,7 @@ describe('MemberActionButtons', () => { wrapper = shallowMount(MemberActionButtons, { propsData: { isCurrentUser: false, + isInvitedUser: false, permissions: { canRemove: true, }, diff --git a/spec/lib/api/entities/ci/pipeline_spec.rb b/spec/lib/api/entities/ci/pipeline_spec.rb new file mode 100644 index 00000000000..6a658cc3e18 --- /dev/null +++ b/spec/lib/api/entities/ci/pipeline_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe API::Entities::Ci::Pipeline do + let_it_be(:pipeline) { create(:ci_empty_pipeline) } + let_it_be(:job) { create(:ci_build, name: "rspec", coverage: 30.212, pipeline: pipeline) } + + let(:entity) { described_class.new(pipeline) } + + subject { entity.as_json } + + it 'returns the coverage as a string' do + expect(subject[:coverage]).to eq '30.21' + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 3813fcd18b1..acc3d598269 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2602,26 +2602,18 @@ RSpec.describe User do end describe '.find_by_full_path' do - using RSpec::Parameterized::TableSyntax + let!(:user) { create(:user, namespace: create(:user_namespace)) } - # TODO: this `where/when` can be removed in issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070 - # At that point we only need to check `user_namespace` - where(namespace_type: [:namespace, :user_namespace]) + context 'with a route matching the given path' do + let!(:route) { user.namespace.route } - with_them do - let!(:user) { create(:user, namespace: create(namespace_type)) } - - context 'with a route matching the given path' do - let!(:route) { user.namespace.route } - - it 'returns the user' do - expect(described_class.find_by_full_path(route.path)).to eq(user) - end + it 'returns the user' do + expect(described_class.find_by_full_path(route.path)).to eq(user) + end - it 'is case-insensitive' do - expect(described_class.find_by_full_path(route.path.upcase)).to eq(user) - expect(described_class.find_by_full_path(route.path.downcase)).to eq(user) - end + it 'is case-insensitive' do + expect(described_class.find_by_full_path(route.path.upcase)).to eq(user) + expect(described_class.find_by_full_path(route.path.downcase)).to eq(user) end context 'with a redirect route matching the given path' do diff --git a/spec/requests/api/ci/pipelines_spec.rb b/spec/requests/api/ci/pipelines_spec.rb index 7ae350885f4..ab977f8326d 100644 --- a/spec/requests/api/ci/pipelines_spec.rb +++ b/spec/requests/api/ci/pipelines_spec.rb @@ -840,7 +840,7 @@ RSpec.describe API::Ci::Pipelines do it 'exposes the coverage' do get api("/projects/#{project.id}/pipelines/#{pipeline.id}", user) - expect(json_response["coverage"].to_i).to eq(30) + expect(json_response["coverage"]).to eq('30.00') end end end diff --git a/spec/services/import/github_service_spec.rb b/spec/services/import/github_service_spec.rb index 776df01d399..04a94d96f67 100644 --- a/spec/services/import/github_service_spec.rb +++ b/spec/services/import/github_service_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Import::GithubService do let_it_be(:access_params) { { github_access_token: 'github-complex-token' } } let_it_be(:params) { { repo_id: 123, new_name: 'new_repo', target_namespace: 'root' } } - let(:subject) { described_class.new(client, user, params) } + subject(:github_importer) { described_class.new(client, user, params) } before do allow(subject).to receive(:authorized?).and_return(true) @@ -110,6 +110,29 @@ RSpec.describe Import::GithubService do end end end + + context 'when a blocked/local URL is used as github_hostname' do + let(:message) { 'Error while attempting to import from GitHub' } + let(:error) { "Invalid URL: #{url}" } + + before do + stub_application_setting(allow_local_requests_from_web_hooks_and_services: false) + end + + where(url: %w[https://localhost https://10.0.0.1]) + + with_them do + it 'returns and logs an error' do + allow(github_importer).to receive(:url).and_return(url) + + expect(Gitlab::Import::Logger).to receive(:error).with({ + message: message, + error: error + }).and_call_original + expect(github_importer.execute(access_params, :github)).to include(blocked_url_error(url)) + end + end + end end context 'when remove_legacy_github_client feature flag is enabled' do @@ -135,4 +158,12 @@ RSpec.describe Import::GithubService do message: '"repository" size (101 Bytes) is larger than the limit of 100 Bytes.' } end + + def blocked_url_error(url) + { + status: :error, + http_status: :bad_request, + message: "Invalid URL: #{url}" + } + end end diff --git a/spec/support/database/cross-database-modification-allowlist.yml b/spec/support/database/cross-database-modification-allowlist.yml index 1bc77577f56..9b4233c64f4 100644 --- a/spec/support/database/cross-database-modification-allowlist.yml +++ b/spec/support/database/cross-database-modification-allowlist.yml @@ -3,7 +3,6 @@ - "./ee/spec/mailers/notify_spec.rb" - "./ee/spec/models/ci/bridge_spec.rb" - "./ee/spec/models/ci/build_spec.rb" -- "./ee/spec/models/ci/minutes/additional_pack_spec.rb" - "./ee/spec/models/ee/ci/job_artifact_spec.rb" - "./ee/spec/models/group_member_spec.rb" - "./ee/spec/replicators/geo/pipeline_artifact_replicator_spec.rb" |