BigW Consortium Gitlab

boards_spec.rb 3.2 KB
Newer Older
Robert Schilling committed
1 2
require 'spec_helper'

3
describe API::V3::Boards do
4 5 6 7
  set(:user)        { create(:user) }
  set(:guest)       { create(:user) }
  set(:non_member)  { create(:user) }
  set(:project)    { create(:project, :public, creator_id: user.id, namespace: user.namespace ) }
Robert Schilling committed
8

9
  set(:dev_label) do
Robert Schilling committed
10 11 12
    create(:label, title: 'Development', color: '#FFAABB', project: project)
  end

13
  set(:test_label) do
Robert Schilling committed
14 15 16
    create(:label, title: 'Testing', color: '#FFAACC', project: project)
  end

17
  set(:dev_list) do
Robert Schilling committed
18 19 20
    create(:list, label: dev_label, position: 1)
  end

21
  set(:test_list) do
Robert Schilling committed
22 23 24
    create(:list, label: test_label, position: 2)
  end

25
  set(:board) do
Robert Schilling committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    create(:board, project: project, lists: [dev_list, test_list])
  end

  before do
    project.team << [user, :reporter]
    project.team << [guest, :guest]
  end

  describe "GET /projects/:id/boards" do
    let(:base_url) { "/projects/#{project.id}/boards" }

    context "when unauthenticated" do
      it "returns authentication error" do
        get v3_api(base_url)

41
        expect(response).to have_gitlab_http_status(401)
Robert Schilling committed
42 43 44 45 46 47 48
      end
    end

    context "when authenticated" do
      it "returns the project issue board" do
        get v3_api(base_url, user)

49
        expect(response).to have_gitlab_http_status(200)
Robert Schilling committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
        expect(json_response).to be_an Array
        expect(json_response.length).to eq(1)
        expect(json_response.first['id']).to eq(board.id)
        expect(json_response.first['lists']).to be_an Array
        expect(json_response.first['lists'].length).to eq(2)
        expect(json_response.first['lists'].last).to have_key('position')
      end
    end
  end

  describe "GET /projects/:id/boards/:board_id/lists" do
    let(:base_url) { "/projects/#{project.id}/boards/#{board.id}/lists" }

    it 'returns issue board lists' do
      get v3_api(base_url, user)

66
      expect(response).to have_gitlab_http_status(200)
Robert Schilling committed
67 68 69 70 71 72 73 74
      expect(json_response).to be_an Array
      expect(json_response.length).to eq(2)
      expect(json_response.first['label']['name']).to eq(dev_label.title)
    end

    it 'returns 404 if board not found' do
      get v3_api("/projects/#{project.id}/boards/22343/lists", user)

75
      expect(response).to have_gitlab_http_status(404)
Robert Schilling committed
76 77
    end
  end
Robert Schilling committed
78 79 80 81 82 83 84

  describe "DELETE /projects/:id/board/lists/:list_id" do
    let(:base_url) { "/projects/#{project.id}/boards/#{board.id}/lists" }

    it "rejects a non member from deleting a list" do
      delete v3_api("#{base_url}/#{dev_list.id}", non_member)

85
      expect(response).to have_gitlab_http_status(403)
Robert Schilling committed
86 87 88 89 90
    end

    it "rejects a user with guest role from deleting a list" do
      delete v3_api("#{base_url}/#{dev_list.id}", guest)

91
      expect(response).to have_gitlab_http_status(403)
Robert Schilling committed
92 93 94 95 96
    end

    it "returns 404 error if list id not found" do
      delete v3_api("#{base_url}/44444", user)

97
      expect(response).to have_gitlab_http_status(404)
Robert Schilling committed
98 99 100
    end

    context "when the user is project owner" do
101 102 103 104 105
      set(:owner) { create(:user) }

      before do
        project.update(namespace: owner.namespace)
      end
Robert Schilling committed
106 107 108 109

      it "deletes the list if an admin requests it" do
        delete v3_api("#{base_url}/#{dev_list.id}", owner)

110
        expect(response).to have_gitlab_http_status(200)
Robert Schilling committed
111 112 113
      end
    end
  end
Robert Schilling committed
114
end