2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe API::AwardEmoji do
|
2018-03-17 18:26:18 +05:30
|
|
|
set(:user) { create(:user) }
|
|
|
|
set(:project) { create(:project) }
|
|
|
|
set(:issue) { create(:issue, project: project) }
|
|
|
|
set(:award_emoji) { create(:award_emoji, awardable: issue, user: user) }
|
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
|
|
|
|
let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request, user: user) }
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
set(:note) { create(:note, project: project, noteable: issue) }
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
describe "GET /projects/:id/awardable/:awardable_id/award_emoji" do
|
|
|
|
context 'on an issue' do
|
|
|
|
it "returns an array of award_emoji" do
|
2017-08-17 22:00:37 +05:30
|
|
|
get api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-06-22 15:30:34 +05:30
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.first['name']).to eq(award_emoji.name)
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "returns a 404 error when issue id not found" do
|
2016-06-22 15:30:34 +05:30
|
|
|
get api("/projects/#{project.id}/issues/12345/award_emoji", user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a merge request' do
|
|
|
|
it "returns an array of award_emoji" do
|
2017-08-17 22:00:37 +05:30
|
|
|
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(response).to include_pagination_headers
|
2016-06-22 15:30:34 +05:30
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.first['name']).to eq(downvote.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
context 'on a snippet' do
|
|
|
|
let(:snippet) { create(:project_snippet, :public, project: project) }
|
|
|
|
let!(:award) { create(:award_emoji, awardable: snippet) }
|
|
|
|
|
|
|
|
it 'returns the awarded emoji' do
|
|
|
|
get api("/projects/#{project.id}/snippets/#{snippet.id}/award_emoji", user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.first['name']).to eq(award.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
context 'when the user has no access' do
|
|
|
|
it 'returns a status code 404' do
|
|
|
|
user1 = create(:user)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji", user1)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/awardable/:awardable_id/notes/:note_id/award_emoji' do
|
|
|
|
let!(:rocket) { create(:award_emoji, awardable: note, name: 'rocket') }
|
|
|
|
|
|
|
|
it 'returns an array of award emoji' do
|
2017-08-17 22:00:37 +05:30
|
|
|
get api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-06-22 15:30:34 +05:30
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.first['name']).to eq(rocket.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/awardable/:awardable_id/award_emoji/:award_id" do
|
|
|
|
context 'on an issue' do
|
|
|
|
it "returns the award emoji" do
|
2017-08-17 22:00:37 +05:30
|
|
|
get api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji/#{award_emoji.id}", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-06-22 15:30:34 +05:30
|
|
|
expect(json_response['name']).to eq(award_emoji.name)
|
|
|
|
expect(json_response['awardable_id']).to eq(issue.id)
|
|
|
|
expect(json_response['awardable_type']).to eq("Issue")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a 404 error if the award is not found" do
|
2017-08-17 22:00:37 +05:30
|
|
|
get api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji/12345", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a merge request' do
|
|
|
|
it 'returns the award emoji' do
|
2017-08-17 22:00:37 +05:30
|
|
|
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji/#{downvote.id}", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-06-22 15:30:34 +05:30
|
|
|
expect(json_response['name']).to eq(downvote.name)
|
|
|
|
expect(json_response['awardable_id']).to eq(merge_request.id)
|
|
|
|
expect(json_response['awardable_type']).to eq("MergeRequest")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
context 'on a snippet' do
|
|
|
|
let(:snippet) { create(:project_snippet, :public, project: project) }
|
|
|
|
let!(:award) { create(:award_emoji, awardable: snippet) }
|
|
|
|
|
|
|
|
it 'returns the awarded emoji' do
|
|
|
|
get api("/projects/#{project.id}/snippets/#{snippet.id}/award_emoji/#{award.id}", user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(json_response['name']).to eq(award.name)
|
|
|
|
expect(json_response['awardable_id']).to eq(snippet.id)
|
|
|
|
expect(json_response['awardable_type']).to eq("Snippet")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
context 'when the user has no access' do
|
|
|
|
it 'returns a status code 404' do
|
|
|
|
user1 = create(:user)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji/#{downvote.id}", user1)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/awardable/:awardable_id/notes/:note_id/award_emoji/:award_id' do
|
|
|
|
let!(:rocket) { create(:award_emoji, awardable: note, name: 'rocket') }
|
|
|
|
|
|
|
|
it 'returns an award emoji' do
|
2017-08-17 22:00:37 +05:30
|
|
|
get api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji/#{rocket.id}", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-06-22 15:30:34 +05:30
|
|
|
expect(json_response).not_to be_an Array
|
|
|
|
expect(json_response['name']).to eq(rocket.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /projects/:id/awardable/:awardable_id/award_emoji" do
|
2019-03-02 22:35:43 +05:30
|
|
|
let(:issue2) { create(:issue, project: project, author: user) }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
context "on an issue" do
|
|
|
|
it "creates a new award emoji" do
|
2019-02-15 15:39:39 +05:30
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: { name: 'blowfish' }
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(201)
|
2016-06-22 15:30:34 +05:30
|
|
|
expect(json_response['name']).to eq('blowfish')
|
|
|
|
expect(json_response['user']['username']).to eq(user.username)
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'marks Todos on the Issue as done' do
|
|
|
|
todo = create(:todo, target: issue, project: project, user: user)
|
|
|
|
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: { name: '8ball' }
|
|
|
|
|
|
|
|
expect(todo.reload).to be_done
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "returns a 400 bad request error if the name is not given" do
|
2017-08-17 22:00:37 +05:30
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(400)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "returns a 401 unauthorized error if the user is not authenticated" do
|
2019-02-15 15:39:39 +05:30
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji"), params: { name: 'thumbsup' }
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(401)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "normalizes +1 as thumbsup award" do
|
2019-02-15 15:39:39 +05:30
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: { name: '+1' }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
expect(issue.award_emoji.last.name).to eq("thumbsup")
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the emoji already has been awarded' do
|
|
|
|
it 'returns a 404 status code' do
|
2019-02-15 15:39:39 +05:30
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: { name: 'thumbsup' }
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: { name: 'thumbsup' }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-24 12:49:21 +05:30
|
|
|
expect(json_response["message"]).to match("has already been taken")
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
context 'on a snippet' do
|
|
|
|
it 'creates a new award emoji' do
|
|
|
|
snippet = create(:project_snippet, :public, project: project)
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
post api("/projects/#{project.id}/snippets/#{snippet.id}/award_emoji", user), params: { name: 'blowfish' }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(201)
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(json_response['name']).to eq('blowfish')
|
|
|
|
expect(json_response['user']['username']).to eq(user.username)
|
|
|
|
end
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /projects/:id/awardable/:awardable_id/notes/:note_id/award_emoji" do
|
2016-09-29 09:46:39 +05:30
|
|
|
let(:note2) { create(:note, project: project, noteable: issue, author: user) }
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
it 'creates a new award emoji' do
|
|
|
|
expect do
|
2019-02-15 15:39:39 +05:30
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: 'rocket' }
|
2016-06-22 15:30:34 +05:30
|
|
|
end.to change { note.award_emoji.count }.from(0).to(1)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(201)
|
2016-06-22 15:30:34 +05:30
|
|
|
expect(json_response['user']['username']).to eq(user.username)
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'marks Todos on the Noteable as done' do
|
|
|
|
todo = create(:todo, target: note2.noteable, project: project, user: user)
|
|
|
|
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: 'rocket' }
|
|
|
|
|
|
|
|
expect(todo.reload).to be_done
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
it "normalizes +1 as thumbsup award" do
|
2019-02-15 15:39:39 +05:30
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: '+1' }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
expect(note.award_emoji.last.name).to eq("thumbsup")
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the emoji already has been awarded' do
|
|
|
|
it 'returns a 404 status code' do
|
2019-02-15 15:39:39 +05:30
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: 'rocket' }
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: 'rocket' }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-24 12:49:21 +05:30
|
|
|
expect(json_response["message"]).to match("has already been taken")
|
|
|
|
end
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE /projects/:id/awardable/:awardable_id/award_emoji/:award_id' do
|
|
|
|
context 'when the awardable is an Issue' do
|
|
|
|
it 'deletes the award' do
|
|
|
|
expect do
|
2017-08-17 22:00:37 +05:30
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji/#{award_emoji.id}", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(204)
|
2017-08-17 22:00:37 +05:30
|
|
|
end.to change { issue.award_emoji.count }.from(1).to(0)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404 error when the award emoji can not be found' do
|
2017-08-17 22:00:37 +05:30
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji/12345", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like '412 response' do
|
|
|
|
let(:request) { api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji/#{award_emoji.id}", user) }
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the awardable is a Merge Request' do
|
|
|
|
it 'deletes the award' do
|
|
|
|
expect do
|
2017-08-17 22:00:37 +05:30
|
|
|
delete api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji/#{downvote.id}", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(204)
|
2017-08-17 22:00:37 +05:30
|
|
|
end.to change { merge_request.award_emoji.count }.from(1).to(0)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404 error when note id not found' do
|
2017-08-17 22:00:37 +05:30
|
|
|
delete api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes/12345", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like '412 response' do
|
|
|
|
let(:request) { api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/award_emoji/#{downvote.id}", user) }
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
context 'when the awardable is a Snippet' do
|
|
|
|
let(:snippet) { create(:project_snippet, :public, project: project) }
|
|
|
|
let!(:award) { create(:award_emoji, awardable: snippet, user: user) }
|
|
|
|
|
|
|
|
it 'deletes the award' do
|
|
|
|
expect do
|
|
|
|
delete api("/projects/#{project.id}/snippets/#{snippet.id}/award_emoji/#{award.id}", user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(204)
|
2017-08-17 22:00:37 +05:30
|
|
|
end.to change { snippet.award_emoji.count }.from(1).to(0)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it_behaves_like '412 response' do
|
|
|
|
let(:request) { api("/projects/#{project.id}/snippets/#{snippet.id}/award_emoji/#{award.id}", user) }
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE /projects/:id/awardable/:awardable_id/award_emoji/:award_emoji_id' do
|
|
|
|
let!(:rocket) { create(:award_emoji, awardable: note, name: 'rocket', user: user) }
|
|
|
|
|
|
|
|
it 'deletes the award' do
|
|
|
|
expect do
|
2017-08-17 22:00:37 +05:30
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji/#{rocket.id}", user)
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(204)
|
2017-08-17 22:00:37 +05:30
|
|
|
end.to change { note.award_emoji.count }.from(1).to(0)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it_behaves_like '412 response' do
|
|
|
|
let(:request) { api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji/#{rocket.id}", user) }
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|