summaryrefslogtreecommitdiff
path: root/spec/requests/api/issues_spec.rb
blob: 4c680425d487d4c2cfdcc08763a87428c3b24a45 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require 'spec_helper'

describe Gitlab::API do
  include ApiHelpers

  let(:user) { Factory :user }
  let!(:project) { Factory :project, owner: user }
  let!(:issue) { Factory :issue, author: user, assignee: user, project: project }
  before { project.add_access(user, :read) }

  describe "GET /issues" do
    it "should return authentication error" do
      get api("/issues")
      response.status.should == 401
    end

    describe "authenticated GET /issues" do
      it "should return an array of issues" do
        get api("/issues", user)
        response.status.should == 200
        json_response.should be_an Array
        json_response.first['title'].should == issue.title
      end
    end
  end

  describe "GET /projects/:id/issues" do
    it "should return project issues" do
      get api("/projects/#{project.code}/issues", user)
      response.status.should == 200
      json_response.should be_an Array
      json_response.first['title'].should == issue.title
    end
  end

  describe "GET /projects/:id/issues/:issue_id" do
    it "should return a project issue by id" do
      get api("/projects/#{project.code}/issues/#{issue.id}", user)
      response.status.should == 200
      json_response['title'].should == issue.title
    end
  end

  describe "POST /projects/:id/issues" do
    it "should create a new project issue" do
      post api("/projects/#{project.code}/issues", user),
        title: 'new issue', labels: 'label, label2'
      response.status.should == 201
      json_response['title'].should == 'new issue'
      json_response['description'].should be_nil
      json_response['labels'].should == ['label', 'label2']
    end
  end

  describe "PUT /projects/:id/issues/:issue_id" do
    it "should update a project issue" do
      put api("/projects/#{project.code}/issues/#{issue.id}", user),
        title: 'updated title', labels: 'label2', closed: 1
      response.status.should == 200
      json_response['title'].should == 'updated title'
      json_response['labels'].should == ['label2']
      json_response['closed'].should be_true
    end
  end

  describe "DELETE /projects/:id/issues/:issue_id" do
    it "should delete a project issue" do
      delete "#{api_prefix}/projects/#{project.code}/issues/#{issue.id}?private_token=#{user.private_token}"
      response.status.should == 405
    end
  end
end