Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/projects')
-rw-r--r--spec/requests/projects/google_cloud_controller_spec.rb94
-rw-r--r--spec/requests/projects/issues/discussions_spec.rb115
-rw-r--r--spec/requests/projects/issues_controller_spec.rb71
-rw-r--r--spec/requests/projects/usage_quotas_spec.rb50
4 files changed, 280 insertions, 50 deletions
diff --git a/spec/requests/projects/google_cloud_controller_spec.rb b/spec/requests/projects/google_cloud_controller_spec.rb
index 3b43f0d1dfb..37682152994 100644
--- a/spec/requests/projects/google_cloud_controller_spec.rb
+++ b/spec/requests/projects/google_cloud_controller_spec.rb
@@ -2,48 +2,106 @@
require 'spec_helper'
+# Mock Types
+MockGoogleOAuth2Credentials = Struct.new(:app_id, :app_secret)
+
RSpec.describe Projects::GoogleCloudController do
let_it_be(:project) { create(:project, :public) }
describe 'GET index' do
let_it_be(:url) { "#{project_google_cloud_index_path(project)}" }
- let(:subject) { get url }
+ context 'when a public request is made' do
+ it 'returns not found' do
+ get url
- context 'when user is authorized' do
- let(:user) { project.creator }
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
- before do
+ context 'when a project.guest makes request' do
+ let(:user) { create(:user) }
+
+ it 'returns not found' do
+ project.add_guest(user)
sign_in(user)
- subject
+
+ get url
+
+ expect(response).to have_gitlab_http_status(:not_found)
end
+ end
- it 'renders content' do
- expect(response).to be_successful
+ context 'when project.developer makes request' do
+ let(:user) { create(:user) }
+
+ it 'returns not found' do
+ project.add_developer(user)
+ sign_in(user)
+
+ get url
+
+ expect(response).to have_gitlab_http_status(:not_found)
end
end
- context 'when user is unauthorized' do
+ context 'when project.maintainer makes request' do
let(:user) { create(:user) }
- before do
- project.add_guest(user)
+ it 'returns successful' do
+ project.add_maintainer(user)
sign_in(user)
- subject
+
+ get url
+
+ expect(response).to be_successful
end
+ end
- it 'shows 404' do
- expect(response).to have_gitlab_http_status(:not_found)
+ context 'when project.creator makes request' do
+ let(:user) { project.creator }
+
+ it 'returns successful' do
+ sign_in(user)
+
+ get url
+
+ expect(response).to be_successful
end
end
- context 'when no user is present' do
- before do
- subject
+ describe 'when authorized user makes request' do
+ let(:user) { project.creator }
+
+ context 'but gitlab instance is not configured for google oauth2' do
+ before do
+ unconfigured_google_oauth2 = MockGoogleOAuth2Credentials.new('', '')
+ allow(Gitlab::Auth::OAuth::Provider).to receive(:config_for)
+ .with('google_oauth2')
+ .and_return(unconfigured_google_oauth2)
+ end
+
+ it 'returns forbidden' do
+ sign_in(user)
+
+ get url
+
+ expect(response).to have_gitlab_http_status(:forbidden)
+ end
end
- it 'shows 404' do
- expect(response).to have_gitlab_http_status(:not_found)
+ context 'but feature flag is disabled' do
+ before do
+ stub_feature_flags(incubation_5mp_google_cloud: false)
+ end
+
+ it 'returns not found' do
+ sign_in(user)
+
+ get url
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
end
end
end
diff --git a/spec/requests/projects/issues/discussions_spec.rb b/spec/requests/projects/issues/discussions_spec.rb
new file mode 100644
index 00000000000..dcdca2d9c27
--- /dev/null
+++ b/spec/requests/projects/issues/discussions_spec.rb
@@ -0,0 +1,115 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'issue discussions' do
+ describe 'GET /:namespace/:project/-/issues/:iid/discussions' do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:issue) { create(:issue, project: project) }
+ let_it_be(:note_author) { create(:user) }
+ let_it_be(:notes) { create_list(:note, 5, project: project, noteable: issue, author: note_author) }
+
+ before_all do
+ project.add_maintainer(user)
+ end
+
+ context 'HTTP caching' do
+ def get_discussions
+ get discussions_namespace_project_issue_path(namespace_id: project.namespace, project_id: project, id: issue.iid), headers: {
+ 'If-None-Match' => @etag
+ }
+
+ @etag = response.etag
+ end
+
+ before do
+ sign_in(user)
+
+ get_discussions
+ end
+
+ it 'returns 304 without serializing JSON' do
+ expect(DiscussionSerializer).not_to receive(:new)
+
+ get_discussions
+
+ expect(response).to have_gitlab_http_status(:not_modified)
+ end
+
+ shared_examples 'cache miss' do
+ it 'returns 200 and serializes JSON' do
+ expect(DiscussionSerializer).to receive(:new).and_call_original
+
+ get_discussions
+
+ expect(response).to have_gitlab_http_status(:ok)
+ end
+ end
+
+ context 'when user role changes' do
+ before do
+ project.add_guest(user)
+ end
+
+ it_behaves_like 'cache miss'
+ end
+
+ context 'when emoji is awarded to a note' do
+ before do
+ travel_to(1.minute.from_now) { create(:award_emoji, awardable: notes.first) }
+ end
+
+ it_behaves_like 'cache miss'
+ end
+
+ context 'when note author name changes' do
+ before do
+ note_author.update!(name: 'New name')
+ end
+
+ it_behaves_like 'cache miss'
+ end
+
+ context 'when note author status changes' do
+ before do
+ Users::SetStatusService.new(note_author, message: "updated status").execute
+ end
+
+ it_behaves_like 'cache miss'
+ end
+
+ context 'when note author role changes' do
+ before do
+ project.add_developer(note_author)
+ end
+
+ it_behaves_like 'cache miss'
+ end
+
+ context 'when note is added' do
+ before do
+ create(:note, project: project, noteable: issue)
+ end
+
+ it_behaves_like 'cache miss'
+ end
+
+ context 'when note is modified' do
+ before do
+ notes.first.update!(note: 'edited text')
+ end
+
+ it_behaves_like 'cache miss'
+ end
+
+ context 'when note is deleted' do
+ before do
+ notes.first.destroy!
+ end
+
+ it_behaves_like 'cache miss'
+ end
+ end
+ end
+end
diff --git a/spec/requests/projects/issues_controller_spec.rb b/spec/requests/projects/issues_controller_spec.rb
new file mode 100644
index 00000000000..f44b1f4d502
--- /dev/null
+++ b/spec/requests/projects/issues_controller_spec.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Projects::IssuesController do
+ let_it_be(:issue) { create(:issue) }
+ let_it_be(:group) { create(:group) }
+ let_it_be(:project) { issue.project }
+ let_it_be(:user) { issue.author }
+
+ before do
+ login_as(user)
+ end
+
+ describe 'GET #discussions' do
+ let_it_be(:discussion) { create(:discussion_note_on_issue, noteable: issue, project: issue.project) }
+ let_it_be(:discussion_reply) { create(:discussion_note_on_issue, noteable: issue, project: issue.project, in_reply_to: discussion) }
+ let_it_be(:state_event) { create(:resource_state_event, issue: issue) }
+ let_it_be(:discussion_2) { create(:discussion_note_on_issue, noteable: issue, project: issue.project) }
+ let_it_be(:discussion_3) { create(:discussion_note_on_issue, noteable: issue, project: issue.project) }
+
+ context 'pagination' do
+ def get_discussions(**params)
+ get discussions_project_issue_path(project, issue, params: params.merge(format: :json))
+ end
+
+ it 'returns paginated notes and cursor based on per_page param' do
+ get_discussions(per_page: 2)
+
+ discussions = Gitlab::Json.parse(response.body)
+ notes = discussions.flat_map { |d| d['notes'] }
+
+ expect(discussions.count).to eq(2)
+ expect(notes).to match([
+ a_hash_including('id' => discussion.id.to_s),
+ a_hash_including('id' => discussion_reply.id.to_s),
+ a_hash_including('type' => 'StateNote')
+ ])
+
+ cursor = response.header['X-Next-Page-Cursor']
+ expect(cursor).to be_present
+
+ get_discussions(per_page: 1, cursor: cursor)
+
+ discussions = Gitlab::Json.parse(response.body)
+ notes = discussions.flat_map { |d| d['notes'] }
+
+ expect(discussions.count).to eq(1)
+ expect(notes).to match([
+ a_hash_including('id' => discussion_2.id.to_s)
+ ])
+ end
+
+ context 'when paginated_issue_discussions is disabled' do
+ before do
+ stub_feature_flags(paginated_issue_discussions: false)
+ end
+
+ it 'returns all discussions and ignores per_page param' do
+ get_discussions(per_page: 2)
+
+ discussions = Gitlab::Json.parse(response.body)
+ notes = discussions.flat_map { |d| d['notes'] }
+
+ expect(discussions.count).to eq(4)
+ expect(notes.count).to eq(5)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/requests/projects/usage_quotas_spec.rb b/spec/requests/projects/usage_quotas_spec.rb
index 04e01da61ef..114e9bd9f1e 100644
--- a/spec/requests/projects/usage_quotas_spec.rb
+++ b/spec/requests/projects/usage_quotas_spec.rb
@@ -22,40 +22,26 @@ RSpec.describe 'Project Usage Quotas' do
end
describe 'GET /:namespace/:project/usage_quotas' do
- context 'with project_storage_ui feature flag enabled' do
- before do
- stub_feature_flags(project_storage_ui: true)
- end
-
- it 'renders usage quotas path' do
- mock_storage_app_data = {
- project_path: project.full_path,
- usage_quotas_help_page_path: help_page_path('user/usage_quotas'),
- build_artifacts_help_page_path: help_page_path('ci/pipelines/job_artifacts', anchor: 'when-job-artifacts-are-deleted'),
- packages_help_page_path: help_page_path('user/packages/package_registry/index.md', anchor: 'delete-a-package'),
- repository_help_page_path: help_page_path('user/project/repository/reducing_the_repo_size_using_git'),
- snippets_help_page_path: help_page_path('user/snippets', anchor: 'reduce-snippets-repository-size'),
- wiki_help_page_path: help_page_path('administration/wikis/index.md', anchor: 'reduce-wiki-repository-size')
- }
- get project_usage_quotas_path(project)
-
- expect(response).to have_gitlab_http_status(:ok)
- expect(response.body).to include(project_usage_quotas_path(project))
- expect(assigns[:storage_app_data]).to eq(mock_storage_app_data)
- expect(response.body).to include("Usage of project resources across the <strong>#{project.name}</strong> project")
- end
-
- context 'renders :not_found for user without permission' do
- let(:role) { :developer }
-
- it_behaves_like 'response with 404 status'
- end
+ it 'renders usage quotas path' do
+ mock_storage_app_data = {
+ project_path: project.full_path,
+ usage_quotas_help_page_path: help_page_path('user/usage_quotas'),
+ build_artifacts_help_page_path: help_page_path('ci/pipelines/job_artifacts', anchor: 'when-job-artifacts-are-deleted'),
+ packages_help_page_path: help_page_path('user/packages/package_registry/index.md', anchor: 'delete-a-package'),
+ repository_help_page_path: help_page_path('user/project/repository/reducing_the_repo_size_using_git'),
+ snippets_help_page_path: help_page_path('user/snippets', anchor: 'reduce-snippets-repository-size'),
+ wiki_help_page_path: help_page_path('administration/wikis/index.md', anchor: 'reduce-wiki-repository-size')
+ }
+ get project_usage_quotas_path(project)
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response.body).to include(project_usage_quotas_path(project))
+ expect(assigns[:storage_app_data]).to eq(mock_storage_app_data)
+ expect(response.body).to include("Usage of project resources across the <strong>#{project.name}</strong> project")
end
- context 'with project_storage_ui feature flag disabled' do
- before do
- stub_feature_flags(project_storage_ui: false)
- end
+ context 'renders :not_found for user without permission' do
+ let(:role) { :developer }
it_behaves_like 'response with 404 status'
end