6 let(:user) { create(:user) }
7 let!(:project) { create(:project, namespace: user.namespace ) }
8 let!(:issue) { create(:issue, project: project, author: user) }
9 let!(:merge_request) { create(:merge_request, project: project, author: user) }
10 let!(:snippet) { create(:snippet, project: project, author: user) }
11 let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
12 let!(:merge_request_note) { create(:note, noteable: merge_request, project: project, author: user) }
13 let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) }
14 let!(:wall_note) { create(:note, project: project, author: user) }
15 before { project.team << [user, :reporter] }
17 describe "GET /projects/:id/notes" do
18 context "when unauthenticated" do
19 it "should return authentication error" do
20 get api("/projects/#{project.id}/notes")
21 response.status.should == 401
25 context "when authenticated" do
26 it "should return project wall notes" do
27 get api("/projects/#{project.id}/notes", user)
28 response.status.should == 200
29 json_response.should be_an Array
30 json_response.first['body'].should == wall_note.note
35 describe "GET /projects/:id/notes/:note_id" do
36 it "should return a wall note by id" do
37 get api("/projects/#{project.id}/notes/#{wall_note.id}", user)
38 response.status.should == 200
39 json_response['body'].should == wall_note.note
42 it "should return a 404 error if note not found" do
43 get api("/projects/#{project.id}/notes/123", user)
44 response.status.should == 404
48 describe "POST /projects/:id/notes" do
49 it "should create a new wall note" do
50 post api("/projects/#{project.id}/notes", user), body: 'hi!'
51 response.status.should == 201
52 json_response['body'].should == 'hi!'
55 it "should return 401 unauthorized error" do
56 post api("/projects/#{project.id}/notes")
57 response.status.should == 401
60 it "should return a 400 bad request if body is missing" do
61 post api("/projects/#{project.id}/notes", user)
62 response.status.should == 400
66 describe "GET /projects/:id/noteable/:noteable_id/notes" do
67 context "when noteable is an Issue" do
68 it "should return an array of issue notes" do
69 get api("/projects/#{project.id}/issues/#{issue.id}/notes", user)
70 response.status.should == 200
71 json_response.should be_an Array
72 json_response.first['body'].should == issue_note.note
75 it "should return a 404 error when issue id not found" do
76 get api("/projects/#{project.id}/issues/123/notes", user)
77 response.status.should == 404
81 context "when noteable is a Snippet" do
82 it "should return an array of snippet notes" do
83 get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
84 response.status.should == 200
85 json_response.should be_an Array
86 json_response.first['body'].should == snippet_note.note
89 it "should return a 404 error when snippet id not found" do
90 get api("/projects/#{project.id}/snippets/42/notes", user)
91 response.status.should == 404
95 context "when noteable is a Merge Request" do
96 it "should return an array of merge_requests notes" do
97 get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes", user)
98 response.status.should == 200
99 json_response.should be_an Array
100 json_response.first['body'].should == merge_request_note.note
103 it "should return a 404 error if merge request id not found" do
104 get api("/projects/#{project.id}/merge_requests/4444/notes", user)
105 response.status.should == 404
110 describe "GET /projects/:id/noteable/:noteable_id/notes/:note_id" do
111 context "when noteable is an Issue" do
112 it "should return an issue note by id" do
113 get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", user)
114 response.status.should == 200
115 json_response['body'].should == issue_note.note
118 it "should return a 404 error if issue note not found" do
119 get api("/projects/#{project.id}/issues/#{issue.id}/notes/123", user)
120 response.status.should == 404
124 context "when noteable is a Snippet" do
125 it "should return a snippet note by id" do
126 get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user)
127 response.status.should == 200
128 json_response['body'].should == snippet_note.note
131 it "should return a 404 error if snippet note not found" do
132 get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/123", user)
133 response.status.should == 404
138 describe "POST /projects/:id/noteable/:noteable_id/notes" do
139 context "when noteable is an Issue" do
140 it "should create a new issue note" do
141 post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!'
142 response.status.should == 201
143 json_response['body'].should == 'hi!'
144 json_response['author']['email'].should == user.email
147 it "should return a 400 bad request error if body not given" do
148 post api("/projects/#{project.id}/issues/#{issue.id}/notes", user)
149 response.status.should == 400
152 it "should return a 401 unauthorized error if user not authenticated" do
153 post api("/projects/#{project.id}/issues/#{issue.id}/notes"), body: 'hi!'
154 response.status.should == 401
158 context "when noteable is a Snippet" do
159 it "should create a new snippet note" do
160 post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user), body: 'hi!'
161 response.status.should == 201
162 json_response['body'].should == 'hi!'
163 json_response['author']['email'].should == user.email
166 it "should return a 400 bad request error if body not given" do
167 post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
168 response.status.should == 400
171 it "should return a 401 unauthorized error if user not authenticated" do
172 post api("/projects/#{project.id}/snippets/#{snippet.id}/notes"), body: 'hi!'
173 response.status.should == 401