2012-11-27 20:43:39 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::API do
|
|
|
|
include ApiHelpers
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
2013-01-02 18:32:34 +01:00
|
|
|
let!(:project) { create(:project, namespace: user.namespace ) }
|
2012-11-27 20:43:39 +01:00
|
|
|
let!(:issue) { create(:issue, project: project, author: user) }
|
|
|
|
let!(:snippet) { create(:snippet, project: project, author: user) }
|
|
|
|
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
|
|
|
|
let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) }
|
|
|
|
let!(:wall_note) { create(:note, project: project, author: user) }
|
|
|
|
before { project.add_access(user, :read) }
|
|
|
|
|
|
|
|
describe "GET /projects/:id/notes" do
|
|
|
|
context "when unauthenticated" do
|
|
|
|
it "should return authentication error" do
|
|
|
|
get api("/projects/#{project.id}/notes")
|
|
|
|
response.status.should == 401
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when authenticated" do
|
|
|
|
it "should return project wall notes" do
|
|
|
|
get api("/projects/#{project.id}/notes", user)
|
|
|
|
response.status.should == 200
|
|
|
|
json_response.should be_an Array
|
|
|
|
json_response.first['body'].should == wall_note.note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-01 11:20:45 +01:00
|
|
|
describe "GET /projects/:id/notes/:note_id" do
|
|
|
|
it "should return a wall note by id" do
|
|
|
|
get api("/projects/#{project.id}/notes/#{wall_note.id}", user)
|
|
|
|
response.status.should == 200
|
|
|
|
json_response['body'].should == wall_note.note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-30 00:52:56 +01:00
|
|
|
describe "POST /projects/:id/notes" do
|
|
|
|
it "should create a new wall note" do
|
|
|
|
post api("/projects/#{project.id}/notes", user), body: 'hi!'
|
|
|
|
response.status.should == 201
|
|
|
|
json_response['body'].should == 'hi!'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-27 20:43:39 +01:00
|
|
|
describe "GET /projects/:id/noteable/:noteable_id/notes" do
|
|
|
|
context "when noteable is an Issue" do
|
2012-11-29 20:33:41 +01:00
|
|
|
it "should return an array of issue notes" do
|
2012-11-27 20:43:39 +01:00
|
|
|
get api("/projects/#{project.id}/issues/#{issue.id}/notes", user)
|
|
|
|
response.status.should == 200
|
|
|
|
json_response.should be_an Array
|
|
|
|
json_response.first['body'].should == issue_note.note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when noteable is a Snippet" do
|
2012-11-29 20:33:41 +01:00
|
|
|
it "should return an array of snippet notes" do
|
2012-11-27 20:43:39 +01:00
|
|
|
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
|
|
|
|
response.status.should == 200
|
|
|
|
json_response.should be_an Array
|
|
|
|
json_response.first['body'].should == snippet_note.note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-11-29 20:33:41 +01:00
|
|
|
|
|
|
|
describe "GET /projects/:id/noteable/:noteable_id/notes/:note_id" do
|
|
|
|
context "when noteable is an Issue" do
|
|
|
|
it "should return an issue note by id" do
|
|
|
|
get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", user)
|
|
|
|
response.status.should == 200
|
|
|
|
json_response['body'].should == issue_note.note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when noteable is a Snippet" do
|
|
|
|
it "should return a snippet note by id" do
|
|
|
|
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user)
|
|
|
|
response.status.should == 200
|
|
|
|
json_response['body'].should == snippet_note.note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-11-29 21:06:24 +01:00
|
|
|
|
|
|
|
describe "POST /projects/:id/noteable/:noteable_id/notes" do
|
|
|
|
context "when noteable is an Issue" do
|
|
|
|
it "should create a new issue note" do
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!'
|
|
|
|
response.status.should == 201
|
|
|
|
json_response['body'].should == 'hi!'
|
|
|
|
json_response['author']['email'].should == user.email
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when noteable is a Snippet" do
|
|
|
|
it "should create a new snippet note" do
|
|
|
|
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user), body: 'hi!'
|
|
|
|
response.status.should == 201
|
|
|
|
json_response['body'].should == 'hi!'
|
|
|
|
json_response['author']['email'].should == user.email
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-11-27 20:43:39 +01:00
|
|
|
end
|