BigW Consortium Gitlab

namespaces_spec.rb 1.89 KB
Newer Older
1 2
require 'spec_helper'

3
describe API::Namespaces do
4
  let(:admin) { create(:admin) }
5
  let(:user) { create(:user) }
6
  let!(:group1) { create(:group) }
7
  let!(:group2) { create(:group, :nested) }
8 9 10

  describe "GET /namespaces" do
    context "when unauthenticated" do
11
      it "returns authentication error" do
12
        get api("/namespaces")
13
        expect(response).to have_http_status(401)
14 15 16
      end
    end

17
    context "when authenticated as admin" do
18
      it "admin: returns an array of all namespaces" do
19
        get api("/namespaces", admin)
20

21
        expect(response).to have_http_status(200)
22
        expect(response).to include_pagination_headers
23 24
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(Namespace.count)
25
      end
26

27
      it "admin: returns an array of matched namespaces" do
28
        get api("/namespaces?search=#{group2.name}", admin)
29

30
        expect(response).to have_http_status(200)
31
        expect(response).to include_pagination_headers
32 33
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(1)
34 35
        expect(json_response.last['path']).to eq(group2.path)
        expect(json_response.last['full_path']).to eq(group2.full_path)
36 37 38 39
      end
    end

    context "when authenticated as a regular user" do
40
      it "user: returns an array of namespaces" do
41
        get api("/namespaces", user)
42

43
        expect(response).to have_http_status(200)
44
        expect(response).to include_pagination_headers
45 46 47 48
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(1)
      end

49
      it "admin: returns an array of matched namespaces" do
50
        get api("/namespaces?search=#{user.username}", user)
51

52
        expect(response).to have_http_status(200)
53
        expect(response).to include_pagination_headers
54 55 56
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(1)
      end
57 58 59
    end
  end
end