summaryrefslogtreecommitdiff
path: root/spec/requests/api/deployments_spec.rb
blob: e55575ffbda766faca0dd29c93c1df56bb757f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'spec_helper'

describe API::Deployments, api: true  do
  include ApiHelpers

  let(:user)        { create(:user) }
  let(:non_member)  { create(:user) }
  let(:project)     { deployment.environment.project }
  let!(:deployment) { create(:deployment) }

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

  describe 'GET /projects/:id/deployments' do
    context 'as member of the project' do
      it 'returns projects deployments' do
        get api("/projects/#{project.id}/deployments", user)

        expect(response).to have_http_status(200)
        expect(response).to include_pagination_headers
        expect(json_response).to be_an Array
        expect(json_response.size).to eq(1)
        expect(json_response.first['iid']).to eq(deployment.iid)
        expect(json_response.first['sha']).to match /\A\h{40}\z/
      end
    end

    context 'as non member' do
      it 'returns a 404 status code' do
        get api("/projects/#{project.id}/deployments", non_member)

        expect(response).to have_http_status(404)
      end
    end
  end

  describe 'GET /projects/:id/deployments/:deployment_id' do
    context 'as a member of the project' do
      it 'returns the projects deployment' do
        get api("/projects/#{project.id}/deployments/#{deployment.id}", user)

        expect(response).to have_http_status(200)
        expect(json_response['sha']).to match /\A\h{40}\z/
        expect(json_response['id']).to eq(deployment.id)
      end
    end

    context 'as non member' do
      it 'returns a 404 status code' do
        get api("/projects/#{project.id}/deployments/#{deployment.id}", non_member)

        expect(response).to have_http_status(404)
      end
    end
  end
end