BigW Consortium Gitlab

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

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

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

18
    context "when authenticated as admin" do
19
      it "admin: returns an array of all namespaces" do
20
        get api("/namespaces", admin)
21
        expect(response).to have_http_status(200)
22
        expect(json_response).to be_an Array
23

24
        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=#{group1.name}", admin)
29
        expect(response).to have_http_status(200)
30 31 32 33 34 35 36
        expect(json_response).to be_an Array

        expect(json_response.length).to eq(1)
      end
    end

    context "when authenticated as a regular user" do
37
      it "user: returns an array of namespaces" do
38
        get api("/namespaces", user)
39
        expect(response).to have_http_status(200)
40 41 42 43 44
        expect(json_response).to be_an Array

        expect(json_response.length).to eq(1)
      end

45
      it "admin: returns an array of matched namespaces" do
46
        get api("/namespaces?search=#{user.username}", user)
47
        expect(response).to have_http_status(200)
48 49 50 51
        expect(json_response).to be_an Array

        expect(json_response.length).to eq(1)
      end
52 53 54
    end
  end
end