diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2017-11-17 04:43:55 +0300 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2017-11-23 16:34:34 +0300 |
commit | 392cc887097bfd0c28b547700b9a67c32cf14e69 (patch) | |
tree | c63c9bb1b2420f0140371ccd90e91c173b1e274c /spec/requests/api/namespaces_spec.rb | |
parent | b8db9c8c8c406d4abc03ba7246bbfecbecfbc784 (diff) |
Add new API endpoint - get a namespace by ID
Diffstat (limited to 'spec/requests/api/namespaces_spec.rb')
-rw-r--r-- | spec/requests/api/namespaces_spec.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/requests/api/namespaces_spec.rb b/spec/requests/api/namespaces_spec.rb index e60716d46d7..80698e1ff74 100644 --- a/spec/requests/api/namespaces_spec.rb +++ b/spec/requests/api/namespaces_spec.rb @@ -91,4 +91,73 @@ describe API::Namespaces do end end end + + describe 'GET /namespaces/:id' do + let(:owned_group) { group1 } + + shared_examples 'namespace reader' do + before do + owned_group.add_owner(request_actor) + end + + context 'when namespace exists' do + it 'returns namespace details' do + get api("/namespaces/#{owned_group.id}", request_actor) + + expect(response).to have_gitlab_http_status(200) + + expect(json_response['id']).to eq(owned_group.id) + expect(json_response['name']).to eq(owned_group.name) + end + end + + context "when namespace doesn't exist" do + it 'returns not-found' do + get api('/namespaces/9999', request_actor) + + expect(response).to have_gitlab_http_status(404) + end + end + end + + context 'when unauthenticated' do + it 'returns authentication error' do + get api("/namespaces/#{group1.id}") + + expect(response).to have_gitlab_http_status(401) + end + end + + context 'when authenticated as regular user' do + let(:request_actor) { user } + + context 'when requested namespace is not owned by user' do + it 'returns authentication error' do + get api("/namespaces/#{group2.id}", request_actor) + + expect(response).to have_gitlab_http_status(403) + end + end + + context 'when requested namespace is owned by user' do + it_behaves_like 'namespace reader' + end + end + + context 'when authenticated as admin' do + let(:request_actor) { admin } + + context 'when requested namespace is not owned by user' do + it 'returns authentication error' do + get api("/namespaces/#{group2.id}", request_actor) + + expect(response).to have_gitlab_http_status(200) + end + end + + context 'when requested namespace is owned by user' do + it_behaves_like 'namespace reader' + end + end + end end |