debian-mirror-gitlab/spec/requests/api/namespaces_spec.rb

60 lines
1.9 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
describe API::Namespaces do
2014-09-02 18:07:02 +05:30
let(:admin) { create(:admin) }
2015-09-11 14:41:01 +05:30
let(:user) { create(:user) }
2014-09-02 18:07:02 +05:30
let!(:group1) { create(:group) }
2017-08-17 22:00:37 +05:30
let!(:group2) { create(:group, :nested) }
2014-09-02 18:07:02 +05:30
describe "GET /namespaces" do
context "when unauthenticated" do
2016-09-13 17:45:13 +05:30
it "returns authentication error" do
2014-09-02 18:07:02 +05:30
get api("/namespaces")
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(401)
2014-09-02 18:07:02 +05:30
end
end
2015-09-11 14:41:01 +05:30
context "when authenticated as admin" do
2016-09-13 17:45:13 +05:30
it "admin: returns an array of all namespaces" do
2014-09-02 18:07:02 +05:30
get api("/namespaces", admin)
2017-08-17 22:00:37 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2017-08-17 22:00:37 +05:30
expect(response).to include_pagination_headers
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Array
expect(json_response.length).to eq(Namespace.count)
2014-09-02 18:07:02 +05:30
end
2015-09-11 14:41:01 +05:30
2016-09-13 17:45:13 +05:30
it "admin: returns an array of matched namespaces" do
2017-08-17 22:00:37 +05:30
get api("/namespaces?search=#{group2.name}", admin)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2017-08-17 22:00:37 +05:30
expect(response).to include_pagination_headers
2015-09-11 14:41:01 +05:30
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
2017-08-17 22:00:37 +05:30
expect(json_response.last['path']).to eq(group2.path)
expect(json_response.last['full_path']).to eq(group2.full_path)
2015-09-11 14:41:01 +05:30
end
end
context "when authenticated as a regular user" do
2016-09-13 17:45:13 +05:30
it "user: returns an array of namespaces" do
2015-09-11 14:41:01 +05:30
get api("/namespaces", user)
2017-08-17 22:00:37 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2017-08-17 22:00:37 +05:30
expect(response).to include_pagination_headers
2015-09-11 14:41:01 +05:30
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
end
2016-09-13 17:45:13 +05:30
it "admin: returns an array of matched namespaces" do
2015-09-11 14:41:01 +05:30
get api("/namespaces?search=#{user.username}", user)
2017-08-17 22:00:37 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2017-08-17 22:00:37 +05:30
expect(response).to include_pagination_headers
2015-09-11 14:41:01 +05:30
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
end
2014-09-02 18:07:02 +05:30
end
end
end