diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-19 12:09:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-19 12:09:30 +0300 |
commit | 3257ae3af07a4ad026be3c868e74ff82866fc400 (patch) | |
tree | 1d1035692fb66e9eea6284ccb3ef186162353ac8 /spec | |
parent | c4e03a0f9695e2c0e73084873da3464570886699 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/projects/pipelines/charts/components/app_spec.js | 72 | ||||
-rw-r--r-- | spec/helpers/graph_helper_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/api/helpers_spec.rb | 52 | ||||
-rw-r--r-- | spec/requests/api/npm_project_packages_spec.rb | 38 |
4 files changed, 97 insertions, 81 deletions
diff --git a/spec/frontend/projects/pipelines/charts/components/app_spec.js b/spec/frontend/projects/pipelines/charts/components/app_spec.js index ab1ce260c07..0cf05d4ac37 100644 --- a/spec/frontend/projects/pipelines/charts/components/app_spec.js +++ b/spec/frontend/projects/pipelines/charts/components/app_spec.js @@ -22,8 +22,7 @@ describe('ProjectsPipelinesChartsApp', () => { {}, { provide: { - shouldRenderDeploymentFrequencyCharts: true, - shouldRenderLeadTimeCharts: true, + shouldRenderDoraCharts: true, }, stubs: { DeploymentFrequencyCharts: DeploymentFrequencyChartsStub, @@ -41,39 +40,35 @@ describe('ProjectsPipelinesChartsApp', () => { const findGlTabs = () => wrapper.find(GlTabs); const findAllGlTabs = () => wrapper.findAll(GlTab); + const findGlTabAtIndex = (index) => findAllGlTabs().at(index); const findLeadTimeCharts = () => wrapper.find(LeadTimeChartsStub); const findDeploymentFrequencyCharts = () => wrapper.find(DeploymentFrequencyChartsStub); const findPipelineCharts = () => wrapper.find(PipelineCharts); - const expectCorrectTabs = ({ pipelines, leadTime, deploymentFreqency }) => { - it('renders the expected tabs', () => { - expect(findGlTabs().exists()).toBe(true); - - const allTabTitles = findAllGlTabs().wrappers.map((w) => w.attributes('title')); + describe('when all charts are available', () => { + beforeEach(() => { + createComponent(); + }); - if (pipelines) { - expect(allTabTitles).toContain('Pipelines'); - expect(findPipelineCharts().exists()).toBe(true); - } + it('renders tabs', () => { + expect(findGlTabs().exists()).toBe(true); - if (deploymentFreqency) { - expect(allTabTitles).toContain('Deployments'); - expect(findDeploymentFrequencyCharts().exists()).toBe(true); - } + expect(findGlTabAtIndex(0).attributes('title')).toBe('Pipelines'); + expect(findGlTabAtIndex(1).attributes('title')).toBe('Deployments'); + expect(findGlTabAtIndex(2).attributes('title')).toBe('Lead Time'); + }); - if (leadTime) { - expect(allTabTitles).toContain('Lead Time'); - expect(findLeadTimeCharts().exists()).toBe(true); - } + it('renders the pipeline charts', () => { + expect(findPipelineCharts().exists()).toBe(true); }); - }; - describe('when all charts are available', () => { - beforeEach(() => { - createComponent(); + it('renders the deployment frequency charts', () => { + expect(findDeploymentFrequencyCharts().exists()).toBe(true); }); - expectCorrectTabs({ pipelines: true, deploymentFreqency: true, leadTime: true }); + it('renders the lead time charts', () => { + expect(findLeadTimeCharts().exists()).toBe(true); + }); it('sets the tab and url when a tab is clicked', async () => { let chartsPath; @@ -131,7 +126,7 @@ describe('ProjectsPipelinesChartsApp', () => { expect(name).toBe('chart'); return chart ? [chart] : []; }); - createComponent({ provide: { shouldRenderDeploymentFrequencyCharts: true } }); + createComponent(); expect(findGlTabs().attributes('value')).toBe(tab); }); @@ -151,7 +146,7 @@ describe('ProjectsPipelinesChartsApp', () => { return []; }); - createComponent({ provide: { shouldRenderDeploymentFrequencyCharts: true } }); + createComponent(); expect(findGlTabs().attributes('value')).toBe('0'); @@ -168,30 +163,9 @@ describe('ProjectsPipelinesChartsApp', () => { }); }); - describe('when shouldRenderDeploymentFrequencyCharts is false', () => { - beforeEach(() => { - createComponent({ provide: { shouldRenderDeploymentFrequencyCharts: false } }); - }); - - expectCorrectTabs({ pipelines: true, deploymentFreqency: false, leadTime: true }); - }); - - describe('when shouldRenderLeadTimeCharts is false', () => { - beforeEach(() => { - createComponent({ provide: { shouldRenderLeadTimeCharts: false } }); - }); - - expectCorrectTabs({ pipelines: true, deploymentFreqency: true, leadTime: false }); - }); - - describe('when shouldRenderDeploymentFrequencyCharts and shouldRenderLeadTimeCharts are false', () => { + describe('when the dora charts are not available', () => { beforeEach(() => { - createComponent({ - provide: { - shouldRenderDeploymentFrequencyCharts: false, - shouldRenderLeadTimeCharts: false, - }, - }); + createComponent({ provide: { shouldRenderDoraCharts: false } }); }); it('does not render tabs', () => { diff --git a/spec/helpers/graph_helper_spec.rb b/spec/helpers/graph_helper_spec.rb index 5b5ad59ed0d..0930417accb 100644 --- a/spec/helpers/graph_helper_spec.rb +++ b/spec/helpers/graph_helper_spec.rb @@ -16,7 +16,7 @@ RSpec.describe GraphHelper do end end - describe '#should_render_deployment_frequency_charts' do + describe '#should_render_dora_charts' do let(:project) { create(:project, :private) } before do @@ -24,19 +24,7 @@ RSpec.describe GraphHelper do end it 'always returns false' do - expect(should_render_deployment_frequency_charts).to be(false) - end - end - - describe '#should_render_lead_time_charts' do - let(:project) { create(:project, :private) } - - before do - self.instance_variable_set(:@project, project) - end - - it 'always returns false' do - expect(should_render_lead_time_charts).to be(false) + expect(should_render_dora_charts).to be(false) end end end diff --git a/spec/lib/api/helpers_spec.rb b/spec/lib/api/helpers_spec.rb index 92326cd34d9..15b22fcf25e 100644 --- a/spec/lib/api/helpers_spec.rb +++ b/spec/lib/api/helpers_spec.rb @@ -47,6 +47,58 @@ RSpec.describe API::Helpers do end end + describe '#find_project!' do + let_it_be(:project) { create(:project, :public) } + let_it_be(:user) { create(:user) } + + shared_examples 'private project without access' do + before do + project.update_column(:visibility_level, Gitlab::VisibilityLevel.level_value('private')) + allow(subject).to receive(:authenticate_non_public?).and_return(false) + end + + it 'returns not found' do + expect(subject).to receive(:not_found!) + + subject.find_project!(project.id) + end + end + + context 'when user is authenticated' do + before do + subject.instance_variable_set(:@current_user, user) + subject.instance_variable_set(:@initial_current_user, user) + end + + context 'public project' do + it 'returns requested project' do + expect(subject.find_project!(project.id)).to eq(project) + end + end + + context 'private project' do + it_behaves_like 'private project without access' + end + end + + context 'when user is not authenticated' do + before do + subject.instance_variable_set(:@current_user, nil) + subject.instance_variable_set(:@initial_current_user, nil) + end + + context 'public project' do + it 'returns requested project' do + expect(subject.find_project!(project.id)).to eq(project) + end + end + + context 'private project' do + it_behaves_like 'private project without access' + end + end + end + describe '#find_namespace' do let(:namespace) { create(:namespace) } diff --git a/spec/requests/api/npm_project_packages_spec.rb b/spec/requests/api/npm_project_packages_spec.rb index e64b5ddc374..10271719a15 100644 --- a/spec/requests/api/npm_project_packages_spec.rb +++ b/spec/requests/api/npm_project_packages_spec.rb @@ -41,6 +41,15 @@ RSpec.describe API::NpmProjectPackages do project.add_developer(user) end + shared_examples 'successfully downloads the file' do + it 'returns the file' do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(response.media_type).to eq('application/octet-stream') + end + end + shared_examples 'a package file that requires auth' do it 'denies download with no token' do subject @@ -51,35 +60,28 @@ RSpec.describe API::NpmProjectPackages do context 'with access token' do let(:headers) { build_token_auth_header(token.token) } - it 'returns the file' do - subject - - expect(response).to have_gitlab_http_status(:ok) - expect(response.media_type).to eq('application/octet-stream') - end + it_behaves_like 'successfully downloads the file' end context 'with job token' do let(:headers) { build_token_auth_header(job.token) } - it 'returns the file' do - subject - - expect(response).to have_gitlab_http_status(:ok) - expect(response.media_type).to eq('application/octet-stream') - end + it_behaves_like 'successfully downloads the file' end end context 'a public project' do - it 'returns the file with no token needed' do - subject + it_behaves_like 'successfully downloads the file' + it_behaves_like 'a package tracking event', 'API::NpmPackages', 'pull_package' - expect(response).to have_gitlab_http_status(:ok) - expect(response.media_type).to eq('application/octet-stream') - end + context 'with a job token for a different user' do + let_it_be(:other_user) { create(:user) } + let_it_be_with_reload(:other_job) { create(:ci_build, :running, user: other_user) } - it_behaves_like 'a package tracking event', 'API::NpmPackages', 'pull_package' + let(:headers) { build_token_auth_header(other_job.token) } + + it_behaves_like 'successfully downloads the file' + end end context 'private project' do |