diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-10 00:07:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-10 00:07:04 +0300 |
commit | 1bcebb67d554d95aa77d4cf42b22e7c96e1c8527 (patch) | |
tree | 6c1575d053400cc81db2d31e2d565320baae19ee /spec | |
parent | 4da595a071829d1046f921e402f3978eeca15d93 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/blob_controller_spec.rb | 19 | ||||
-rw-r--r-- | spec/controllers/projects/pipelines_controller_spec.rb | 4 | ||||
-rw-r--r-- | spec/features/issues/form_spec.rb | 8 | ||||
-rw-r--r-- | spec/frontend/code_quality_walkthrough/components/__snapshots__/step_spec.js.snap | 174 | ||||
-rw-r--r-- | spec/frontend/code_quality_walkthrough/components/step_spec.js | 156 | ||||
-rw-r--r-- | spec/frontend/jobs/components/job_app_spec.js | 1 | ||||
-rw-r--r-- | spec/frontend/pipelines/pipelines_spec.js | 36 | ||||
-rw-r--r-- | spec/helpers/ci/pipelines_helper_spec.rb | 1 | ||||
-rw-r--r-- | spec/presenters/project_presenter_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/groups/deploy_tokens_controller_spec.rb | 40 | ||||
-rw-r--r-- | spec/serializers/pipeline_details_entity_spec.rb | 14 | ||||
-rw-r--r-- | spec/services/groups/deploy_tokens/revoke_service_spec.rb | 28 |
12 files changed, 76 insertions, 411 deletions
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`] = ` -<div> - <gl-popover-stub - container="viewport" - cssclasses="" - offset="90" - placement="right" - show="" - target="#js-code-quality-walkthrough" - triggers="manual" - > - - <gl-sprintf-stub - message="To begin with code quality, we first need to create a new CI file using our code editor. We added a code quality template in the code editor to help you get started %{emojiStart}wink%{emojiEnd} .%{lineBreak}Take some time to review the template, when you are ready, use the %{strongStart}commit changes%{strongEnd} button at the bottom of the page." - /> - - <div - class="gl-mt-2 gl-text-right" - > - <gl-button-stub - buttontextclasses="" - category="tertiary" - href="" - icon="" - size="medium" - variant="link" - > - - Got it - - </gl-button-stub> - </div> - </gl-popover-stub> - - <!----> -</div> -`; - -exports[`When the code_quality_walkthrough URL parameter is present Code Quality Walkthrough Step component failed_pipeline step renders a popover 1`] = ` -<div> - <gl-popover-stub - container="viewport" - cssclasses="" - offset="98" - placement="bottom" - show="" - target="#js-code-quality-walkthrough" - triggers="manual" - > - - <gl-sprintf-stub - message="Your job failed. No worries - this happens. Let's view the logs, and see how we can fix it." - /> - - <div - class="gl-mt-2 gl-text-right" - > - <gl-button-stub - buttontextclasses="" - category="tertiary" - href="/group/project/-/jobs/:id?code_quality_walkthrough=true" - icon="" - size="medium" - variant="link" - > - - View the logs - - </gl-button-stub> - </div> - </gl-popover-stub> - - <!----> -</div> -`; - -exports[`When the code_quality_walkthrough URL parameter is present Code Quality Walkthrough Step component running_pipeline step renders a popover 1`] = ` -<div> - <gl-popover-stub - container="viewport" - cssclasses="" - offset="97" - placement="bottom" - show="" - target="#js-code-quality-walkthrough" - triggers="manual" - > - - <gl-sprintf-stub - message="Your pipeline can take a few minutes to run. If you enabled email notifications, you'll receive an email with your pipeline status. In the meantime, why don't you get some coffee? You earned it!" - /> - - <div - class="gl-mt-2 gl-text-right" - > - <gl-button-stub - buttontextclasses="" - category="tertiary" - href="" - icon="" - size="medium" - variant="link" - > - - Got it - - </gl-button-stub> - </div> - </gl-popover-stub> - - <!----> -</div> -`; - -exports[`When the code_quality_walkthrough URL parameter is present Code Quality Walkthrough Step component success_pipeline step renders a popover 1`] = ` -<div> - <gl-popover-stub - container="viewport" - cssclasses="" - offset="98" - placement="bottom" - show="" - target="#js-code-quality-walkthrough" - triggers="manual" - > - - <gl-sprintf-stub - message="A code quality job will now run every time you or your team members commit changes to your project. You can view the results of the code quality job in the job logs." - /> - - <div - class="gl-mt-2 gl-text-right" - > - <gl-button-stub - buttontextclasses="" - category="tertiary" - href="/group/project/-/jobs/:id?code_quality_walkthrough=true" - icon="" - size="medium" - variant="link" - > - - View the logs - - </gl-button-stub> - </div> - </gl-popover-stub> - - <!----> -</div> -`; - -exports[`When the code_quality_walkthrough URL parameter is present Code Quality Walkthrough Step component troubleshoot_job step renders an alert 1`] = ` -<div> - <!----> - - <gl-alert-stub - class="gl-my-5" - dismissible="true" - dismisslabel="Dismiss" - primarybuttontext="Read the documentation" - secondarybuttonlink="" - secondarybuttontext="" - title="Troubleshoot your code quality job" - variant="tip" - > - - Not sure how to fix your failed job? We have compiled some tips on how to troubleshoot code quality jobs in the documentation. - - </gl-alert-stub> -</div> -`; 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 |