diff options
author | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-06-17 16:44:38 +0300 |
---|---|---|
committer | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-06-17 22:02:51 +0300 |
commit | 05a4a586b5e80f7d30de51199d5bb5bcf7f61705 (patch) | |
tree | 5ac9c5821e08d25a482a9275297d2bf78cdb7a0a /spec/requests/api/award_emoji_spec.rb | |
parent | 34558315d9deb305b062b825a9a1821ee17352cc (diff) |
Add endpoints for award emoji on notes
Docs also added.
Diffstat (limited to 'spec/requests/api/award_emoji_spec.rb')
-rw-r--r-- | spec/requests/api/award_emoji_spec.rb | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/spec/requests/api/award_emoji_spec.rb b/spec/requests/api/award_emoji_spec.rb index 49964cb51de..7cf2c21dae8 100644 --- a/spec/requests/api/award_emoji_spec.rb +++ b/spec/requests/api/award_emoji_spec.rb @@ -5,9 +5,10 @@ describe API::API, api: true do let(:user) { create(:user) } let!(:project) { create(:project) } let(:issue) { create(:issue, project: project, author: user) } - let!(: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) } + let!(: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) } + let!(:note) { create(:note, project: project, noteable: issue) } before { project.team << [user, :master] } @@ -49,6 +50,19 @@ describe API::API, api: true do 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 + get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji", user) + + expect(response.status).to eq(200) + 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 @@ -73,7 +87,7 @@ describe API::API, api: true do expect(response.status).to eq(200) expect(json_response['name']).to eq(downvote.name) - expect(json_response['awardable_id']).to eq(issue.id) + expect(json_response['awardable_id']).to eq(merge_request.id) expect(json_response['awardable_type']).to eq("MergeRequest") end end @@ -89,6 +103,18 @@ describe API::API, api: true do 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 + get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji/#{rocket.id}", user) + + expect(response.status).to eq(200) + 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 context "on an issue" do it "creates a new award emoji" do @@ -113,7 +139,18 @@ describe API::API, api: true do end end - describe 'DELETE /projects/:id/awardable/:awardable_id/award_emoji/:award_emoji_id' do + describe "POST /projects/:id/awardable/:awardable_id/notes/:note_id/award_emoji" do + it 'creates a new award emoji' do + expect do + post api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji", user), name: 'rocket' + end.to change { note.award_emoji.count }.from(0).to(1) + + expect(response.status).to eq(201) + expect(json_response['user']['username']).to eq(user.username) + end + 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 @@ -146,4 +183,16 @@ describe API::API, api: true do end end 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 + delete api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji/#{rocket.id}", user) + end.to change { note.award_emoji.count }.from(1).to(0) + + expect(response.status).to eq(200) + end + end end |