2016-08-12 17:24:09 -04:00
|
|
|
require 'spec_helper'
|
2016-05-25 15:07:36 -04:00
|
|
|
|
|
|
|
describe Projects::NotesController do
|
|
|
|
let(:user) { create(:user) }
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:project) { create(:empty_project) }
|
2016-05-25 15:07:36 -04:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:note) { create(:note, noteable: issue, project: project) }
|
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
let(:request_params) do
|
|
|
|
{
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: note
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-11-24 09:05:15 -05:00
|
|
|
describe 'POST create' do
|
|
|
|
let(:merge_request) { create(:merge_request) }
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:project) { merge_request.source_project }
|
2016-11-24 09:05:15 -05:00
|
|
|
let(:request_params) do
|
|
|
|
{
|
|
|
|
note: { note: 'some note', noteable_id: merge_request.id, noteable_type: 'MergeRequest' },
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
merge_request_diff_head_sha: 'sha'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns status 302 for html" do
|
|
|
|
post :create, request_params
|
|
|
|
|
|
|
|
expect(response).to have_http_status(302)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns status 200 for json" do
|
|
|
|
post :create, request_params.merge(format: :json)
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when merge_request_diff_head_sha present' do
|
|
|
|
before do
|
|
|
|
service_params = {
|
|
|
|
note: 'some note',
|
|
|
|
noteable_id: merge_request.id.to_s,
|
|
|
|
noteable_type: 'MergeRequest',
|
|
|
|
merge_request_diff_head_sha: 'sha'
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(Notes::CreateService).to receive(:new).with(project, user, service_params).and_return(double(execute: true))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns status 302 for html" do
|
|
|
|
post :create, request_params
|
|
|
|
|
|
|
|
expect(response).to have_http_status(302)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-12 17:24:09 -04:00
|
|
|
describe 'POST toggle_award_emoji' do
|
2016-05-25 15:07:36 -04:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "toggles the award emoji" do
|
|
|
|
expect do
|
2016-08-15 19:45:23 -04:00
|
|
|
post(:toggle_award_emoji, request_params.merge(name: "thumbsup"))
|
2016-06-02 12:25:51 -04:00
|
|
|
end.to change { note.award_emoji.count }.by(1)
|
2016-05-25 15:07:36 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-05-25 15:07:36 -04:00
|
|
|
end
|
|
|
|
|
2016-06-02 12:25:51 -04:00
|
|
|
it "removes the already awarded emoji" do
|
2016-08-15 19:45:23 -04:00
|
|
|
post(:toggle_award_emoji, request_params.merge(name: "thumbsup"))
|
2016-05-25 15:07:36 -04:00
|
|
|
|
|
|
|
expect do
|
2016-08-15 19:45:23 -04:00
|
|
|
post(:toggle_award_emoji, request_params.merge(name: "thumbsup"))
|
2016-05-25 15:07:36 -04:00
|
|
|
end.to change { AwardEmoji.count }.by(-1)
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-05-25 15:07:36 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
describe "resolving and unresolving" do
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-08-15 19:45:23 -04:00
|
|
|
let(:merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
let(:note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project) }
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
describe 'POST resolve' do
|
2016-08-12 17:24:09 -04:00
|
|
|
before do
|
2016-08-15 19:45:23 -04:00
|
|
|
sign_in user
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
context "when the user is not authorized to resolve the note" do
|
2016-08-12 17:24:09 -04:00
|
|
|
it "returns status 404" do
|
2016-08-15 19:45:23 -04:00
|
|
|
post :resolve, request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
context "when the user is authorized to resolve the note" do
|
|
|
|
before do
|
|
|
|
project.team << [user, :developer]
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
context "when the note is not resolvable" do
|
|
|
|
before do
|
|
|
|
note.update(system: true)
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
it "returns status 404" do
|
|
|
|
post :resolve, request_params
|
|
|
|
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
context "when the note is resolvable" do
|
|
|
|
it "resolves the note" do
|
|
|
|
post :resolve, request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
expect(note.reload.resolved?).to be true
|
|
|
|
expect(note.reload.resolved_by).to eq(user)
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
it "sends notifications if all discussions are resolved" do
|
|
|
|
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(merge_request)
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
post :resolve, request_params
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
it "returns the name of the resolving user" do
|
|
|
|
post :resolve, request_params
|
|
|
|
|
|
|
|
expect(JSON.parse(response.body)["resolved_by"]).to eq(user.name)
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
it "returns status 200" do
|
|
|
|
post :resolve, request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
describe 'DELETE unresolve' do
|
2016-08-12 17:24:09 -04:00
|
|
|
before do
|
2016-08-15 19:45:23 -04:00
|
|
|
sign_in user
|
|
|
|
|
|
|
|
note.resolve!(user)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
context "when the user is not authorized to resolve the note" do
|
2016-08-12 17:24:09 -04:00
|
|
|
it "returns status 404" do
|
2016-08-15 19:45:23 -04:00
|
|
|
delete :unresolve, request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
context "when the user is authorized to resolve the note" do
|
|
|
|
before do
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the note is not resolvable" do
|
|
|
|
before do
|
|
|
|
note.update(system: true)
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
it "returns status 404" do
|
|
|
|
delete :unresolve, request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
context "when the note is resolvable" do
|
|
|
|
it "unresolves the note" do
|
|
|
|
delete :unresolve, request_params
|
|
|
|
|
|
|
|
expect(note.reload.resolved?).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns status 200" do
|
|
|
|
delete :unresolve, request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-07 12:02:02 -05:00
|
|
|
|
|
|
|
describe 'GET index' do
|
|
|
|
let(:last_fetched_at) { '1487756246' }
|
|
|
|
let(:request_params) do
|
|
|
|
{
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
target_type: 'issue',
|
|
|
|
target_id: issue.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'passes last_fetched_at from headers to NotesFinder' do
|
|
|
|
request.headers['X-Last-Fetched-At'] = last_fetched_at
|
|
|
|
|
|
|
|
expect(NotesFinder).to receive(:new)
|
|
|
|
.with(anything, anything, hash_including(last_fetched_at: last_fetched_at))
|
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
get :index, request_params
|
|
|
|
end
|
|
|
|
end
|
2016-05-25 15:07:36 -04:00
|
|
|
end
|