summaryrefslogtreecommitdiff
path: root/spec/controllers/groups
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-05-24 16:58:48 +0200
committerToon Claes <toon@gitlab.com>2018-05-29 11:45:17 +0200
commit607225923008d62a3fa9fafb1a33205d28456d5f (patch)
tree633e349e366ef53b6f5586873c4d5224b795a0a3 /spec/controllers/groups
parentc5adf04cd69035a7a1737df8c2303bc228ea4089 (diff)
downloadgitlab-ce-607225923008d62a3fa9fafb1a33205d28456d5f.tar.gz
Add `shared_projects` endpoint
This endpoint lists projects shared with a group visible to the current user. The `filter` and `sort` params are supported like on the `children` endpoint.
Diffstat (limited to 'spec/controllers/groups')
-rw-r--r--spec/controllers/groups/shared_projects_controller_spec.rb59
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/controllers/groups/shared_projects_controller_spec.rb b/spec/controllers/groups/shared_projects_controller_spec.rb
new file mode 100644
index 00000000000..f8d1c13416d
--- /dev/null
+++ b/spec/controllers/groups/shared_projects_controller_spec.rb
@@ -0,0 +1,59 @@
+require 'spec_helper'
+
+describe Groups::SharedProjectsController do
+ def get_shared_projects(params = {})
+ get :index, params.reverse_merge(format: :json, group_id: group.full_path)
+ end
+
+ def share_project(project)
+ Projects::GroupLinks::CreateService.new(
+ project,
+ user,
+ link_group_access: ProjectGroupLink::DEVELOPER
+ ).execute(group)
+ end
+
+ let(:group) { create(:group) }
+ let(:user) { create(:user) }
+ let!(:shared_project) do
+ shared_project = create(:project, namespace: user.namespace)
+ share_project(shared_project)
+
+ shared_project
+ end
+
+ let(:json_project_ids) { json_response.map { |project_info| project_info['id'] } }
+
+ before do
+ sign_in(user)
+ end
+
+ describe 'GET #index' do
+ it 'returns only projects shared with the group' do
+ create(:project, namespace: group)
+
+ get_shared_projects
+
+ expect(json_project_ids).to contain_exactly(shared_project.id)
+ end
+
+ it 'allows fitlering shared projects' do
+ project = create(:project, :archived, namespace: user.namespace, name: "Searching for")
+ share_project(project)
+
+ get_shared_projects(filter: 'search')
+
+ expect(json_project_ids).to contain_exactly(project.id)
+ end
+
+ it 'allows sorting projects' do
+ shared_project.update!(name: 'bbb')
+ second_project = create(:project, namespace: user.namespace, name: 'aaaa')
+ share_project(second_project)
+
+ get_shared_projects(sort: 'name_asc')
+
+ expect(json_project_ids).to eq([second_project.id, shared_project.id])
+ end
+ end
+end