From 1bcebb67d554d95aa77d4cf42b22e7c96e1c8527 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 9 Mar 2022 21:07:04 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/controllers/projects/blob_controller_spec.rb | 19 --- .../projects/pipelines_controller_spec.rb | 4 - spec/features/issues/form_spec.rb | 8 + .../components/__snapshots__/step_spec.js.snap | 174 --------------------- .../components/step_spec.js | 156 ------------------ spec/frontend/jobs/components/job_app_spec.js | 1 - spec/frontend/pipelines/pipelines_spec.js | 36 ----- spec/helpers/ci/pipelines_helper_spec.rb | 1 - spec/presenters/project_presenter_spec.rb | 6 - .../groups/deploy_tokens_controller_spec.rb | 40 +++++ spec/serializers/pipeline_details_entity_spec.rb | 14 -- .../groups/deploy_tokens/revoke_service_spec.rb | 28 ++++ 12 files changed, 76 insertions(+), 411 deletions(-) delete mode 100644 spec/frontend/code_quality_walkthrough/components/__snapshots__/step_spec.js.snap delete mode 100644 spec/frontend/code_quality_walkthrough/components/step_spec.js create mode 100644 spec/requests/groups/deploy_tokens_controller_spec.rb create mode 100644 spec/services/groups/deploy_tokens/revoke_service_spec.rb (limited to 'spec') diff --git a/spec/controllers/projects/blob_controller_spec.rb b/spec/controllers/projects/blob_controller_spec.rb index 53efcc65066..d47d54747c8 100644 --- a/spec/controllers/projects/blob_controller_spec.rb +++ b/spec/controllers/projects/blob_controller_spec.rb @@ -525,24 +525,5 @@ RSpec.describe Projects::BlobController do expect(response).to redirect_to(project_blob_path(project, 'master/docs/EXAMPLE_FILE')) end - - context 'when code_quality_walkthrough param is present' do - let(:default_params) { super().merge(code_quality_walkthrough: true) } - - it 'redirects to the pipelines page' do - request - - expect(response).to redirect_to(project_pipelines_path(project, code_quality_walkthrough: true)) - end - - it 'creates an "commit_created" experiment tracking event' do - experiment = double(track: true) - expect(controller).to receive(:experiment).with(:code_quality_walkthrough, namespace: project.root_ancestor).and_return(experiment) - - request - - expect(experiment).to have_received(:track).with(:commit_created) - end - end end end diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index 283d7b49674..75d29acfbc4 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -292,10 +292,6 @@ RSpec.describe Projects::PipelinesController do subject { project.namespace } - context 'code_quality_walkthrough experiment' do - it_behaves_like 'tracks assignment and records the subject', :code_quality_walkthrough, :namespace - end - context 'runners_availability_section experiment' do it_behaves_like 'tracks assignment and records the subject', :runners_availability_section, :namespace end diff --git a/spec/features/issues/form_spec.rb b/spec/features/issues/form_spec.rb index 18942e48400..0700423983f 100644 --- a/spec/features/issues/form_spec.rb +++ b/spec/features/issues/form_spec.rb @@ -187,6 +187,14 @@ RSpec.describe 'New/edit issue', :js do end end + it 'displays an error message when submitting an invalid form' do + click_button 'Create issue' + + page.within('[data-testid="issue-title-input-field"]') do + expect(page).to have_text(_('This field is required.')) + end + end + it 'correctly updates the dropdown toggle when removing a label' do click_button 'Labels' diff --git a/spec/frontend/code_quality_walkthrough/components/__snapshots__/step_spec.js.snap b/spec/frontend/code_quality_walkthrough/components/__snapshots__/step_spec.js.snap deleted file mode 100644 index f17d99ad257..00000000000 --- a/spec/frontend/code_quality_walkthrough/components/__snapshots__/step_spec.js.snap +++ /dev/null @@ -1,174 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`When the code_quality_walkthrough URL parameter is present Code Quality Walkthrough Step component commit_ci_file step renders a popover 1`] = ` -
- - - - -
- - - Got it - - -
-
- - -
-`; - -exports[`When the code_quality_walkthrough URL parameter is present Code Quality Walkthrough Step component failed_pipeline step renders a popover 1`] = ` -
- - - - -
- - - View the logs - - -
-
- - -
-`; - -exports[`When the code_quality_walkthrough URL parameter is present Code Quality Walkthrough Step component running_pipeline step renders a popover 1`] = ` -
- - - - -
- - - Got it - - -
-
- - -
-`; - -exports[`When the code_quality_walkthrough URL parameter is present Code Quality Walkthrough Step component success_pipeline step renders a popover 1`] = ` -
- - - - -
- - - View the logs - - -
-
- - -
-`; - -exports[`When the code_quality_walkthrough URL parameter is present Code Quality Walkthrough Step component troubleshoot_job step renders an alert 1`] = ` -
- - - - - Not sure how to fix your failed job? We have compiled some tips on how to troubleshoot code quality jobs in the documentation. - - -
-`; diff --git a/spec/frontend/code_quality_walkthrough/components/step_spec.js b/spec/frontend/code_quality_walkthrough/components/step_spec.js deleted file mode 100644 index b43629c2f96..00000000000 --- a/spec/frontend/code_quality_walkthrough/components/step_spec.js +++ /dev/null @@ -1,156 +0,0 @@ -import { GlButton, GlPopover } from '@gitlab/ui'; -import { shallowMount } from '@vue/test-utils'; -import Cookies from 'js-cookie'; -import Step from '~/code_quality_walkthrough/components/step.vue'; -import { EXPERIMENT_NAME, STEPS } from '~/code_quality_walkthrough/constants'; -import { TRACKING_CONTEXT_SCHEMA } from '~/experimentation/constants'; -import { getParameterByName } from '~/lib/utils/url_utility'; -import Tracking from '~/tracking'; - -jest.mock('~/lib/utils/url_utility', () => ({ - ...jest.requireActual('~/lib/utils/url_utility'), - getParameterByName: jest.fn(), -})); - -let wrapper; - -function factory({ step, link }) { - wrapper = shallowMount(Step, { - propsData: { step, link }, - }); -} - -afterEach(() => { - wrapper.destroy(); -}); - -const dummyLink = '/group/project/-/jobs/:id?code_quality_walkthrough=true'; -const dummyContext = 'experiment_context'; - -const findButton = () => wrapper.findComponent(GlButton); -const findPopover = () => wrapper.findComponent(GlPopover); - -describe('When the code_quality_walkthrough URL parameter is missing', () => { - beforeEach(() => { - getParameterByName.mockReturnValue(false); - }); - - it('does not render the component', () => { - factory({ - step: STEPS.commitCiFile, - }); - - expect(findPopover().exists()).toBe(false); - }); -}); - -describe('When the code_quality_walkthrough URL parameter is present', () => { - beforeEach(() => { - getParameterByName.mockReturnValue(true); - Cookies.set(EXPERIMENT_NAME, { data: dummyContext }); - }); - - afterEach(() => { - Cookies.remove(EXPERIMENT_NAME); - }); - - describe('When mounting the component', () => { - beforeEach(() => { - jest.spyOn(Tracking, 'event'); - - factory({ - step: STEPS.commitCiFile, - }); - }); - - it('tracks an event', () => { - expect(Tracking.event).toHaveBeenCalledWith( - EXPERIMENT_NAME, - `${STEPS.commitCiFile}_displayed`, - { - context: { - schema: TRACKING_CONTEXT_SCHEMA, - data: dummyContext, - }, - }, - ); - }); - }); - - describe('When updating the component', () => { - beforeEach(() => { - factory({ - step: STEPS.runningPipeline, - }); - - jest.spyOn(Tracking, 'event'); - - wrapper.setProps({ step: STEPS.successPipeline }); - }); - - it('tracks an event', () => { - expect(Tracking.event).toHaveBeenCalledWith( - EXPERIMENT_NAME, - `${STEPS.successPipeline}_displayed`, - { - context: { - schema: TRACKING_CONTEXT_SCHEMA, - data: dummyContext, - }, - }, - ); - }); - }); - - describe('When dismissing a popover', () => { - beforeEach(() => { - factory({ - step: STEPS.commitCiFile, - }); - - jest.spyOn(Cookies, 'set'); - jest.spyOn(Tracking, 'event'); - - findButton().vm.$emit('click'); - }); - - it('sets a cookie', () => { - expect(Cookies.set).toHaveBeenCalledWith( - EXPERIMENT_NAME, - { commit_ci_file: true, data: dummyContext }, - { expires: 365, secure: false }, - ); - }); - - it('removes the popover', () => { - expect(findPopover().exists()).toBe(false); - }); - - it('tracks an event', () => { - expect(Tracking.event).toHaveBeenCalledWith( - EXPERIMENT_NAME, - `${STEPS.commitCiFile}_dismissed`, - { - context: { - schema: TRACKING_CONTEXT_SCHEMA, - data: dummyContext, - }, - }, - ); - }); - }); - - describe('Code Quality Walkthrough Step component', () => { - describe.each(Object.values(STEPS))('%s step', (step) => { - it(`renders ${step === STEPS.troubleshootJob ? 'an alert' : 'a popover'}`, () => { - const options = { step }; - if ([STEPS.successPipeline, STEPS.failedPipeline].includes(step)) { - options.link = dummyLink; - } - factory(options); - - expect(wrapper.element).toMatchSnapshot(); - }); - }); - }); -}); diff --git a/spec/frontend/jobs/components/job_app_spec.js b/spec/frontend/jobs/components/job_app_spec.js index d4e1e711777..06ebcd7f134 100644 --- a/spec/frontend/jobs/components/job_app_spec.js +++ b/spec/frontend/jobs/components/job_app_spec.js @@ -34,7 +34,6 @@ describe('Job App', () => { const props = { artifactHelpUrl: 'help/artifact', deploymentHelpUrl: 'help/deployment', - codeQualityHelpPath: '/help/code_quality', runnerSettingsUrl: 'settings/ci-cd/runners', terminalPath: 'jobs/123/terminal', projectPath: 'user-name/project-name', diff --git a/spec/frontend/pipelines/pipelines_spec.js b/spec/frontend/pipelines/pipelines_spec.js index 1c84e20c9e1..ca19a6d337a 100644 --- a/spec/frontend/pipelines/pipelines_spec.js +++ b/spec/frontend/pipelines/pipelines_spec.js @@ -10,7 +10,6 @@ import { TEST_HOST } from 'helpers/test_constants'; import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import waitForPromises from 'helpers/wait_for_promises'; import Api from '~/api'; -import { getExperimentData, getExperimentVariant } from '~/experimentation/utils'; import createFlash from '~/flash'; import axios from '~/lib/utils/axios_utils'; import NavigationControls from '~/pipelines/components/pipelines_list/nav_controls.vue'; @@ -25,11 +24,6 @@ import TablePagination from '~/vue_shared/components/pagination/table_pagination import { stageReply, users, mockSearch, branches } from './mock_data'; jest.mock('~/flash'); -jest.mock('~/experimentation/utils', () => ({ - ...jest.requireActual('~/experimentation/utils'), - getExperimentData: jest.fn().mockReturnValue(false), - getExperimentVariant: jest.fn().mockReturnValue('control'), -})); const mockProjectPath = 'twitter/flight'; const mockProjectId = '21'; @@ -50,7 +44,6 @@ describe('Pipelines', () => { ciLintPath: '/ci/lint', resetCachePath: `${mockProjectPath}/settings/ci_cd/reset_cache`, newPipelinePath: `${mockProjectPath}/pipelines/new`, - codeQualityPagePath: `${mockProjectPath}/-/new/master?commit_message=Add+.gitlab-ci.yml+and+create+a+code+quality+job&file_name=.gitlab-ci.yml&template=Code-Quality`, ciRunnerSettingsPath: `${mockProjectPath}/-/settings/ci_cd#js-runners-settings`, }; @@ -557,35 +550,6 @@ describe('Pipelines', () => { expect(wrapper.findComponent(PipelinesCiTemplates).exists()).toBe(true); }); - describe('when the code_quality_walkthrough experiment is active', () => { - beforeAll(() => { - getExperimentData.mockImplementation((name) => name === 'code_quality_walkthrough'); - }); - - describe('the control state', () => { - beforeAll(() => { - getExperimentVariant.mockReturnValue('control'); - }); - - it('renders the CI/CD templates', () => { - expect(wrapper.findComponent(PipelinesCiTemplates).exists()).toBe(true); - }); - }); - - describe('the candidate state', () => { - beforeAll(() => { - getExperimentVariant.mockReturnValue('candidate'); - }); - - it('renders another CTA button', () => { - expect(findEmptyState().findComponent(GlButton).text()).toBe('Add a code quality job'); - expect(findEmptyState().findComponent(GlButton).attributes('href')).toBe( - paths.codeQualityPagePath, - ); - }); - }); - }); - it('does not render filtered search', () => { expect(findFilteredSearch().exists()).toBe(false); }); diff --git a/spec/helpers/ci/pipelines_helper_spec.rb b/spec/helpers/ci/pipelines_helper_spec.rb index 1baaefe0b7f..a7a96efcb3f 100644 --- a/spec/helpers/ci/pipelines_helper_spec.rb +++ b/spec/helpers/ci/pipelines_helper_spec.rb @@ -120,7 +120,6 @@ RSpec.describe Ci::PipelinesHelper do :has_gitlab_ci, :pipeline_editor_path, :suggested_ci_templates, - :code_quality_page_path, :ci_runner_settings_path]) end diff --git a/spec/presenters/project_presenter_spec.rb b/spec/presenters/project_presenter_spec.rb index e4a08bd56c8..33a4a1b9d4c 100644 --- a/spec/presenters/project_presenter_spec.rb +++ b/spec/presenters/project_presenter_spec.rb @@ -747,10 +747,4 @@ RSpec.describe ProjectPresenter do end end end - - describe '#add_code_quality_ci_yml_path' do - subject { presenter.add_code_quality_ci_yml_path } - - it { is_expected.to match(/code_quality_walkthrough=true.*template=Code-Quality/) } - end end diff --git a/spec/requests/groups/deploy_tokens_controller_spec.rb b/spec/requests/groups/deploy_tokens_controller_spec.rb new file mode 100644 index 00000000000..b3dce9b9cf1 --- /dev/null +++ b/spec/requests/groups/deploy_tokens_controller_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Groups::DeployTokensController do + let_it_be(:group) { create(:group) } + let_it_be(:user) { create(:user) } + let_it_be(:deploy_token) { create(:deploy_token, :group, groups: [group]) } + let_it_be(:params) do + { id: deploy_token.id, group_id: group } + end + + before do + group.add_owner(user) + + sign_in(user) + end + + describe 'PUT /groups/:group_path_with_namespace/-/deploy_tokens/:id/revoke' do + subject(:put_revoke) do + put "/groups/#{group.full_path}/-/deploy_tokens/#{deploy_token.id}/revoke", params: params + end + + it 'invokes the Groups::DeployTokens::RevokeService' do + expect(deploy_token.revoked).to eq(false) + expect(Groups::DeployTokens::RevokeService).to receive(:new).and_call_original + + put_revoke + + expect(deploy_token.reload.revoked).to eq(true) + end + + it 'redirects to group repository settings with correct anchor' do + put_revoke + + expect(response).to have_gitlab_http_status(:redirect) + expect(response).to redirect_to(group_settings_repository_path(group, anchor: 'js-deploy-tokens')) + end + end +end diff --git a/spec/serializers/pipeline_details_entity_spec.rb b/spec/serializers/pipeline_details_entity_spec.rb index 128f1922887..67f8860ed4a 100644 --- a/spec/serializers/pipeline_details_entity_spec.rb +++ b/spec/serializers/pipeline_details_entity_spec.rb @@ -70,20 +70,6 @@ RSpec.describe PipelineDetailsEntity do expect(subject[:flags][:retryable]).to eq false end end - - it 'does not contain code_quality_build_path in details' do - expect(subject[:details]).not_to include :code_quality_build_path - end - - context 'when option code_quality_walkthrough is set and pipeline is a success' do - let(:entity) do - described_class.represent(pipeline, request: request, code_quality_walkthrough: true) - end - - it 'contains details.code_quality_build_path' do - expect(subject[:details]).to include :code_quality_build_path - end - end end context 'when pipeline is cancelable' do diff --git a/spec/services/groups/deploy_tokens/revoke_service_spec.rb b/spec/services/groups/deploy_tokens/revoke_service_spec.rb new file mode 100644 index 00000000000..fcf11bbb8e6 --- /dev/null +++ b/spec/services/groups/deploy_tokens/revoke_service_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Groups::DeployTokens::RevokeService do + let_it_be(:entity) { create(:group) } + let_it_be(:deploy_token) { create(:deploy_token, :group, groups: [entity]) } + let_it_be(:user) { create(:user) } + let_it_be(:deploy_token_params) { { id: deploy_token.id } } + + describe '#execute' do + subject { described_class.new(entity, user, deploy_token_params).execute } + + it "revokes a group deploy token" do + expect(deploy_token.revoked).to eq(false) + + expect { subject }.to change { deploy_token.reload.revoked }.to eq(true) + end + + context 'invalid token id' do + let(:deploy_token_params) { { token_id: non_existing_record_id } } + + it 'raises an error' do + expect { subject }.to raise_error(ActiveRecord::RecordNotFound) + end + end + end +end -- cgit v1.2.3